Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
phearnot committed Sep 30, 2024
1 parent 5418c0d commit 9e6542f
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,22 @@ object DBResource {
def multiGet[A](keys: ArrayBuffer[Key[A]], valBufferSize: Int): View[A] =
db.multiGet(readOptions, keys, valBufferSize)

@volatile private var prefixIteratorWasOpened = false
/**
* Finds the exact key for iter.seek(key) if key.length < 10 and becomes invalid on iter.next().
* Works as intended if prefix(key).length >= 10.
* @see RDB.newColumnFamilyOptions
*/
override lazy val prefixIterator: RocksIterator = db.newIterator(readOptions.setTotalOrderSeek(false).setPrefixSameAsStart(true))
override lazy val prefixIterator: RocksIterator = {
prefixIteratorWasOpened = true
db.newIterator(readOptions.setTotalOrderSeek(false).setPrefixSameAsStart(true))
}

override lazy val fullIterator: RocksIterator = db.newIterator(readOptions.setTotalOrderSeek(true))
@volatile private var fullIteratorWasOpened = false
override lazy val fullIterator: RocksIterator = {
fullIteratorWasOpened = true
db.newIterator(readOptions.setTotalOrderSeek(true))
}

override def withSafePrefixIterator[A](ifNotClosed: RocksIterator => A)(ifClosed: => A): A = prefixIterator.synchronized {
if (prefixIterator.isOwningHandle) ifNotClosed(prefixIterator) else ifClosed
Expand All @@ -53,8 +61,8 @@ object DBResource {
}

override def close(): Unit = {
prefixIterator.synchronized(prefixIterator.close())
fullIterator.synchronized(fullIterator.close())
if (prefixIteratorWasOpened) prefixIterator.synchronized(prefixIterator.close())
if (fullIteratorWasOpened) fullIterator.synchronized(fullIterator.close())
snapshot.close()
readOptions.close()
}
Expand Down

0 comments on commit 9e6542f

Please sign in to comment.