LuciferYang commented on code in PR #43502:
URL: https://github.com/apache/spark/pull/43502#discussion_r1369664549
##########
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:
```
iteratorTracker.removeIf(ref -> ref.get() != null &&
rocksIterator.equals(ref.get().it));
```
Maybe this part can be placed outside of `synchronized `?
##########
common/kvstore/src/main/java/org/apache/spark/util/kvstore/RocksDBIterator.java:
##########
@@ -36,20 +41,24 @@ class RocksDBIterator<T> implements KVStoreIterator<T> {
private final byte[] indexKeyPrefix;
private final byte[] end;
private final long max;
+ private final Cleaner.Cleanable cleanable;
private boolean checkedNext;
private byte[] next;
private boolean closed;
private long count;
- RocksDBIterator(Class<T> type, RocksDB db, KVStoreView<T> params) throws
Exception {
+ RocksDBIterator(Class<T> type, RocksDB db, KVStoreView<T> params,
+ ConcurrentLinkedQueue<Reference<RocksDBIterator<?>>> iteratorTracker,
Review Comment:
I'm more inclined to add two helper methods in RocksDB to get
`iteratorTracker` and `_db`, but I'm also open to other suggestions.
--
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]