stopgap to mitigate off-heap memory leak until refactor in #4641 (#4645)

Signed-off-by: garyschulte <garyschulte@gmail.com>
pull/4659/head
garyschulte 2 years ago committed by GitHub
parent 40230ee626
commit b181f99940
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      plugins/rocksdb/src/main/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/RocksDBSnapshot.java
  2. 12
      plugins/rocksdb/src/main/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/RocksDBSnapshotTransaction.java

@ -26,6 +26,7 @@ import org.rocksdb.Snapshot;
* use.
*/
class RocksDBSnapshot {
private final OptimisticTransactionDB db;
private final Snapshot dbSnapshot;
private final AtomicInteger usages = new AtomicInteger(0);
@ -42,8 +43,17 @@ class RocksDBSnapshot {
void unMarkSnapshot() {
if (usages.decrementAndGet() < 1) {
db.releaseSnapshot(dbSnapshot);
dbSnapshot.close();
}
}
// TODO: this is a stopgap measure, revisit with https://github.com/hyperledger/besu/issues/4641
@Override
protected void finalize() {
if (usages.decrementAndGet() > 0) {
db.releaseSnapshot(dbSnapshot);
dbSnapshot.close();
}
}
}

@ -22,6 +22,7 @@ import org.hyperledger.besu.plugin.services.storage.rocksdb.RocksDBMetrics;
import org.hyperledger.besu.plugin.services.storage.rocksdb.RocksDbIterator;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Stream;
import org.apache.commons.lang3.tuple.Pair;
@ -46,6 +47,8 @@ public class RocksDBSnapshotTransaction implements KeyValueStorageTransaction, A
private final RocksDBSnapshot snapshot;
private final WriteOptions writeOptions;
private final ReadOptions readOptions;
// TODO: this is a stopgap measure, revisit with https://github.com/hyperledger/besu/issues/4641
private final AtomicBoolean isClosed = new AtomicBoolean(false);
RocksDBSnapshotTransaction(
final OptimisticTransactionDB db,
@ -164,5 +167,14 @@ public class RocksDBSnapshotTransaction implements KeyValueStorageTransaction, A
writeOptions.close();
readOptions.close();
snapshot.unMarkSnapshot();
isClosed.set(true);
}
// TODO: this is a stopgap measure, revisit with https://github.com/hyperledger/besu/issues/4641
@Override
protected void finalize() {
if (!isClosed.get()) {
close();
}
}
}

Loading…
Cancel
Save