LuciferYang commented on code in PR #43502:
URL: https://github.com/apache/spark/pull/43502#discussion_r1371099819


##########
common/kvstore/src/main/java/org/apache/spark/util/kvstore/RocksDB.java:
##########
@@ -355,26 +355,21 @@ public void close() throws IOException {
     }
   }
 
-  /**
-   * Closes the given iterator if the DB is still open. Trying to close a JNI 
RocksDB handle
-   * with a closed DB can cause JVM crashes, so this ensures that situation 
does not happen.
-   */
-  void closeIterator(RocksDBIterator<?> it) throws IOException {
-    notifyIteratorClosed(it);
-    synchronized (this._db) {
-      org.rocksdb.RocksDB _db = this._db.get();
-      if (_db != null) {
-        it.close();
-      }
-    }
+  public AtomicReference<org.rocksdb.RocksDB> getRocksDB() {
+    return _db;
   }
 
-  /**
-   * Remove iterator from iterator tracker. `RocksDBIterator` calls it to 
notify
-   * iterator is closed.
-   */
-  void notifyIteratorClosed(RocksDBIterator<?> it) {
-    iteratorTracker.removeIf(ref -> it.equals(ref.get()));
+  public ConcurrentLinkedQueue<Reference<RocksDBIterator<?>>> 
getIteratorTracker() {
+    return iteratorTracker;
+  }
+
+  public Optional<Reference<RocksDBIterator<?>>> 
iteratorReference(RocksDBIterator<?> rocksDBIterator) {
+    for (Reference<RocksDBIterator<?>> rocksDBIteratorReference : 
iteratorTracker) {
+      if (rocksDBIterator == rocksDBIteratorReference.get()) {
+        return Optional.of(rocksDBIteratorReference);

Review Comment:
   It's not necessary to wrap it as Optional, the calling place can also check 
for non-null :)
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to