From 9e6542fcffb2a01ebfa67e6a7b27030f4a28bbd6 Mon Sep 17 00:00:00 2001 From: Sergey Nazarov Date: Mon, 30 Sep 2024 13:01:33 +0300 Subject: [PATCH] wip --- .../database/rocksdb/DBResource.scala | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/ride-runner/src/main/scala/com/wavesplatform/database/rocksdb/DBResource.scala b/ride-runner/src/main/scala/com/wavesplatform/database/rocksdb/DBResource.scala index 6c3eca3c06..a020084d2d 100644 --- a/ride-runner/src/main/scala/com/wavesplatform/database/rocksdb/DBResource.scala +++ b/ride-runner/src/main/scala/com/wavesplatform/database/rocksdb/DBResource.scala @@ -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 @@ -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() }