Skip to content

Commit

Permalink
Adding option to debug the potential problems with closing Transaction
Browse files Browse the repository at this point in the history
Signed-off-by: Jiri Peinlich <jiri.peinlich@gmail.com>
  • Loading branch information
gezero authored and garyschulte committed Nov 12, 2022
1 parent e2b1994 commit 7e2d372
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.hyperledger.besu.plugin.services.storage.rocksdb.RocksDBMetrics;
import org.hyperledger.besu.plugin.services.storage.rocksdb.RocksDbIterator;

import java.util.Arrays;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Stream;
Expand Down Expand Up @@ -49,6 +50,7 @@ public class RocksDBSnapshotTransaction implements KeyValueStorageTransaction, A
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);
private final StackTraceElement[] stackTrace;

RocksDBSnapshotTransaction(
final OptimisticTransactionDB db,
Expand All @@ -61,6 +63,7 @@ public class RocksDBSnapshotTransaction implements KeyValueStorageTransaction, A
this.writeOptions = new WriteOptions();
this.snapTx = db.beginTransaction(writeOptions);
this.readOptions = new ReadOptions().setSnapshot(snapshot.markAndUseSnapshot());
this.stackTrace = Thread.currentThread().getStackTrace();
}

private RocksDBSnapshotTransaction(
Expand All @@ -77,6 +80,7 @@ private RocksDBSnapshotTransaction(
this.writeOptions = new WriteOptions();
this.readOptions = readOptions;
this.snapTx = snapTx;
this.stackTrace = Thread.currentThread().getStackTrace();
}

public Optional<byte[]> get(final byte[] key) {
Expand Down Expand Up @@ -174,6 +178,9 @@ public void close() {
@Override
protected void finalize() {
if (!isClosed.get()) {
LOG.debug(
"RocksDBSnapshotTransaction was not closed. This is a memory leak. Stack trace: {}",
Arrays.toString(stackTrace));
close();
}
}
Expand Down

0 comments on commit 7e2d372

Please sign in to comment.