Skip to content

Commit 7ac38c6

Browse files
authored
close rocksdb transaction correctly with bonsai (#9467)
Signed-off-by: Karim Taam <[email protected]>
1 parent 568842c commit 7ac38c6

File tree

12 files changed

+57
-2
lines changed

12 files changed

+57
-2
lines changed

ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/pathbased/bonsai/storage/BonsaiWorldStateKeyValueStorage.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,11 +322,13 @@ public void commit() {
322322
@Override
323323
public void commitTrieLogOnly() {
324324
trieLogStorageTransaction.commit();
325+
composedWorldStateTransaction.close();
325326
}
326327

327328
@Override
328329
public void commitComposedOnly() {
329330
composedWorldStateTransaction.commit();
331+
trieLogStorageTransaction.close();
330332
}
331333

332334
@Override

ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/pathbased/common/worldview/PathBasedWorldState.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,11 @@ public void commit() throws StorageException {
318318
public void rollback() {
319319
// no-op
320320
}
321+
322+
@Override
323+
public void close() {
324+
// no-op
325+
}
321326
};
322327

323328
protected static final SegmentedKeyValueStorageTransaction noOpSegmentedTx =
@@ -343,6 +348,11 @@ public void commit() throws StorageException {
343348
public void rollback() {
344349
// no-op
345350
}
351+
352+
@Override
353+
public void close() {
354+
// no-op
355+
}
346356
};
347357

348358
public Hash blockHash() {

plugin-api/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Calculated : ${currentHash}
7171
tasks.register('checkAPIChanges', FileStateChecker) {
7272
description = "Checks that the API for the Plugin-API project does not change without deliberate thought"
7373
files = sourceSets.main.allJava.files
74-
knownHash = 'IzrtFU4/tJOlP/uzYA0e2/JA2029pinh32givR4HSbA='
74+
knownHash = 'ACVfXtQZDPbvDrHz43Rigj8ZLzph7Pnp0q8z11gzpjA='
7575
}
7676
check.dependsOn('checkAPIChanges')
7777

plugin-api/src/main/java/org/hyperledger/besu/plugin/services/storage/KeyValueStorageTransaction.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,7 @@ public interface KeyValueStorageTransaction {
4848

4949
/** Reset the transaction to a state prior to any operations being queued. */
5050
void rollback();
51+
52+
/** close the transaction */
53+
void close();
5154
}

plugin-api/src/main/java/org/hyperledger/besu/plugin/services/storage/SegmentedKeyValueStorageTransaction.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,7 @@ public interface SegmentedKeyValueStorageTransaction {
5252

5353
/** Reset the transaction to a state prior to any operations being queued. */
5454
void rollback();
55+
56+
/** close the transaction */
57+
void close();
5558
}

plugins/rocksdb/src/main/java/org/hyperledger/besu/plugin/services/storage/rocksdb/RocksDBTransaction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ public void rollback() {
114114
}
115115
}
116116

117-
private void close() {
117+
@Override
118+
public void close() {
118119
innerTx.close();
119120
options.close();
120121
}

plugins/rocksdb/src/main/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/RocksDBColumnarKeyValueSnapshot.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,5 +297,10 @@ public void commit() throws StorageException {
297297
public void rollback() {
298298
// no-op
299299
}
300+
301+
@Override
302+
public void close() {
303+
// no-op
304+
}
300305
};
301306
}

services/kvstore/src/main/java/org/hyperledger/besu/services/kvstore/KeyValueStorageTransactionValidatorDecorator.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,12 @@ public final void rollback() {
6969
active = false;
7070
transaction.rollback();
7171
}
72+
73+
@Override
74+
public void close() {
75+
checkState(active, "Cannot close a completed transaction.");
76+
checkState(!isClosed.get(), "Cannot invoke close() on a closed storage.");
77+
active = false;
78+
transaction.close();
79+
}
7280
}

services/kvstore/src/main/java/org/hyperledger/besu/services/kvstore/LimitedInMemoryKeyValueStorage.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ public void commit() throws StorageException {
195195

196196
@Override
197197
public void rollback() {
198+
close();
199+
}
200+
201+
@Override
202+
public void close() {
198203
updatedValues.clear();
199204
removedKeys.clear();
200205
}

services/kvstore/src/main/java/org/hyperledger/besu/services/kvstore/SegmentedInMemoryKeyValueStorage.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,11 @@ public void commit() throws StorageException {
388388

389389
@Override
390390
public void rollback() {
391+
close();
392+
}
393+
394+
@Override
395+
public void close() {
391396
updatedValues.clear();
392397
removedKeys.clear();
393398
}

0 commit comments

Comments
 (0)