-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added DocumentCollection.ref(name) - Added optional Id key validation - Lots of improvements to OperationsQueue support - Addition of ProcessQueue for more powerful batch processing - Improvements to Searchable support
- Loading branch information
1 parent
41a9a95
commit dc56373
Showing
10 changed files
with
112 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
driver/src/main/scala/com/outr/arango/queue/ProcessQueue.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.outr.arango.queue | ||
|
||
import cats.effect.IO | ||
|
||
import java.util.concurrent.ConcurrentLinkedQueue | ||
import java.util.concurrent.atomic.AtomicInteger | ||
|
||
/** | ||
* ProcessQueue provides a convenience capability to batch process in chunks. | ||
* | ||
* @param process the function to process a chunk of the queue | ||
* @param flushSize the number of records before a flush occurs | ||
* @param chunkSize the max number of records per chunk sent to the process function | ||
*/ | ||
case class ProcessQueue[T](process: List[T] => IO[Unit], flushSize: Int, chunkSize: Int) { | ||
private lazy val queue = new ConcurrentLinkedQueue[T] | ||
private lazy val counter = new AtomicInteger(0) | ||
|
||
private lazy val _processed = new AtomicInteger(0) | ||
|
||
def processed: Int = _processed.get() | ||
|
||
private def take(n: Int): List[T] = if (n == 0) { | ||
Nil | ||
} else { | ||
val d = queue.poll() | ||
if (d == null) { | ||
Nil | ||
} else { | ||
counter.decrementAndGet() | ||
d :: take(n - 1) | ||
} | ||
} | ||
|
||
/** | ||
* Queue operations for the supplied docs. If this causes the flushSize to overflow, a flush will occur before this | ||
* returns. Otherwise, this is a very fast operation. | ||
*/ | ||
def apply(docs: T*): IO[Unit] = IO { | ||
docs.foreach(queue.add) | ||
counter.addAndGet(docs.length) | ||
}.flatMap { size => | ||
if (size >= flushSize) { | ||
flush(fullFlush = false) | ||
} else { | ||
IO.unit | ||
} | ||
} | ||
|
||
/** | ||
* Flushes the queue | ||
* | ||
* @param fullFlush if true, all operations are applied. If false, flushing only occurs until the operation count | ||
* is below the flushSize threshold. | ||
*/ | ||
def flush(fullFlush: Boolean = true): IO[Unit] = IO(take(chunkSize)).flatMap { list => | ||
if (list.isEmpty) { | ||
IO.unit | ||
} else { | ||
process(list).flatMap { _ => | ||
_processed.addAndGet(list.length) | ||
if (counter.get() >= flushSize || fullFlush) { | ||
flush() | ||
} else { | ||
IO.unit | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
driver/src/main/scala/com/outr/arango/upsert/UpsertResult.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters