LuciferYang commented on code in PR #43502:
URL: https://github.com/apache/spark/pull/43502#discussion_r1369709362
##########
common/kvstore/src/main/java/org/apache/spark/util/kvstore/RocksDBIterator.java:
##########
@@ -272,4 +270,32 @@ static int compare(byte[] a, byte[] b) {
return a.length - b.length;
}
+ static class ResourceCleaner implements Runnable {
+
+ private final RocksIterator rocksIterator;
+
+ private final AtomicReference<org.rocksdb.RocksDB> _db;
+
+ private final ConcurrentLinkedQueue<Reference<RocksDBIterator<?>>>
iteratorTracker;
+
+ public ResourceCleaner(RocksIterator rocksIterator,
+ AtomicReference<org.rocksdb.RocksDB> _db,
+ ConcurrentLinkedQueue<Reference<RocksDBIterator<?>>> iteratorTracker) {
+ this.rocksIterator = rocksIterator;
+ this._db = _db;
+ this.iteratorTracker = iteratorTracker;
+ }
+
+ @Override
+ public void run() {
+ synchronized (this._db) {
+ org.rocksdb.RocksDB _db = this._db.get();
+ if (_db == null) {
+ return;
+ }
+ iteratorTracker.removeIf(ref -> ref.get() != null &&
rocksIterator.equals(ref.get().it));
Review Comment:
In addition, it would be better to assign `ref.get()` to an intermediate
variable. Even if the first `ref.get() != null` is true, the second call to
`ref.get()` could still be 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]