Adding option to debug the potential problems with closing Transaction (#4654)

* Adding option to debug the potential problems with closing Transaction

Signed-off-by: Jiri Peinlich <jiri.peinlich@gmail.com>
Co-authored-by: garyschulte <garyschulte@gmail.com>
pull/4668/head
Jiri Peinlich 2 years ago committed by GitHub
parent 6a3d4528bd
commit 2528aacde7
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/RocksDBSnapshotTransaction.java

@ -15,12 +15,15 @@
*/
package org.hyperledger.besu.plugin.services.storage.rocksdb.segmented;
import static org.hyperledger.besu.util.Slf4jLambdaHelper.debugLambda;
import org.hyperledger.besu.plugin.services.exception.StorageException;
import org.hyperledger.besu.plugin.services.metrics.OperationTimer;
import org.hyperledger.besu.plugin.services.storage.KeyValueStorageTransaction;
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;
@ -49,6 +52,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,
@ -61,6 +65,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(
@ -77,6 +82,7 @@ public class RocksDBSnapshotTransaction implements KeyValueStorageTransaction, A
this.writeOptions = new WriteOptions();
this.readOptions = readOptions;
this.snapTx = snapTx;
this.stackTrace = Thread.currentThread().getStackTrace();
}
public Optional<byte[]> get(final byte[] key) {
@ -174,6 +180,10 @@ public class RocksDBSnapshotTransaction implements KeyValueStorageTransaction, A
@Override
protected void finalize() {
if (!isClosed.get()) {
debugLambda(
LOG,
"RocksDBSnapshotTransaction was not closed. This is a memory leak. Stack trace: {}",
() -> Arrays.toString(stackTrace));
close();
}
}

Loading…
Cancel
Save