LuciferYang commented on code in PR #43502: URL: https://github.com/apache/spark/pull/43502#discussion_r1382327696
########## common/kvstore/src/main/java/org/apache/spark/util/kvstore/RocksDBIterator.java: ########## @@ -176,22 +183,30 @@ public boolean skip(long n) { @Override public synchronized void close() throws IOException { - db.notifyIteratorClosed(this); + db.notifyIteratorClosed(it); if (!closed) { - it.close(); - closed = true; - next = null; + try { + it.close(); + closed = true; + next = null; + } finally { + cancelResourceClean(); + } } } - /** - * Because it's tricky to expose closeable iterators through many internal APIs, especially - * when Scala wrappers are used, this makes sure that, hopefully, the JNI resources held by - * the iterator will eventually be released. - */ - @Override - protected void finalize() throws Throwable { - db.closeIterator(this); + private void cancelResourceClean() { + this.resourceCleaner.statusToFalse(); + this.cleanable.clean(); + } + + @VisibleForTesting + ResourceCleaner getResourceCleaner() { + return resourceCleaner; + } + + public RocksIterator getRocksIterator() { Review Comment: can we remove the `public`? and I like `internalIterator` -- 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-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org