You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "zhaomin1423 (via GitHub)" <gi...@apache.org> on 2023/11/01 15:20:23 UTC

Re: [PR] [SPARK-45533][CORE] Use j.l.r.Cleaner instead of finalize for RocksDBIterator/LevelDBIterator [spark]

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


##########
common/kvstore/src/main/java/org/apache/spark/util/kvstore/RocksDBIterator.java:
##########
@@ -270,20 +280,30 @@ static int compare(byte[] a, byte[] b) {
     return a.length - b.length;
   }
 
-  private record ResourceCleaner(RocksIterator rocksIterator, RocksDB rocksDB) implements Runnable {
+  private static class ResourceCleaner implements Runnable {
+
+    private final RocksIterator rocksIterator;
+    private final RocksDB rocksDB;
+    private final AtomicBoolean status = new AtomicBoolean(true);
+
+    public ResourceCleaner(RocksIterator rocksIterator, RocksDB rocksDB) {
+      this.rocksIterator = rocksIterator;
+      this.rocksDB = rocksDB;
+    }
 
     @Override
     public void run() {
-      rocksDB.getIteratorTracker().removeIf(ref -> {
-        RocksDBIterator<?> rocksDBIterator = ref.get();
-        return rocksDBIterator != null && rocksIterator.equals(rocksDBIterator.it);
-      });
-      synchronized (rocksDB.getRocksDB()) {
-        org.rocksdb.RocksDB _db = rocksDB.getRocksDB().get();
-        if (_db != null) {
-          rocksIterator.close();
-        }
+      if (status.compareAndSet(true, false)) {
+        rocksDB.getIteratorTracker().removeIf(ref -> {

Review Comment:
   Thanks, updated, levels will update after rocksdb complete



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org