mirror of
https://github.com/vacp2p/linea-besu.git
synced 2026-01-09 15:37:54 -05:00
Fix rocksDB storage so that clear removes all values (#1894)
Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
This commit is contained in:
@@ -184,7 +184,9 @@ public class ColumnarRocksDbKeyValueStorage
|
||||
final byte[] firstKey = rocksIterator.key();
|
||||
rocksIterator.seekToLast();
|
||||
if (rocksIterator.isValid()) {
|
||||
db.deleteRange(segmentHandle, firstKey, rocksIterator.key());
|
||||
final byte[] lastKey = rocksIterator.key();
|
||||
db.deleteRange(segmentHandle, firstKey, lastKey);
|
||||
db.delete(segmentHandle, lastKey);
|
||||
}
|
||||
}
|
||||
} catch (final RocksDBException e) {
|
||||
|
||||
@@ -14,6 +14,7 @@ package tech.pegasys.pantheon.services.kvstore;
|
||||
|
||||
import tech.pegasys.pantheon.metrics.MetricsSystem;
|
||||
import tech.pegasys.pantheon.metrics.OperationTimer;
|
||||
import tech.pegasys.pantheon.services.kvstore.SegmentedKeyValueStorage.StorageException;
|
||||
import tech.pegasys.pantheon.services.util.RocksDbUtil;
|
||||
import tech.pegasys.pantheon.util.bytes.BytesValue;
|
||||
|
||||
@@ -76,16 +77,16 @@ public class RocksDbKeyValueStorage implements KeyValueStorage, Closeable {
|
||||
@Override
|
||||
public void clear() {
|
||||
try (final RocksIterator rocksIterator = db.newIterator()) {
|
||||
if (!rocksIterator.isValid()) {
|
||||
return;
|
||||
}
|
||||
rocksIterator.seekToFirst();
|
||||
final byte[] firstKey = rocksIterator.key();
|
||||
rocksIterator.seekToLast();
|
||||
if (!rocksIterator.isValid()) {
|
||||
return;
|
||||
if (rocksIterator.isValid()) {
|
||||
final byte[] firstKey = rocksIterator.key();
|
||||
rocksIterator.seekToLast();
|
||||
if (rocksIterator.isValid()) {
|
||||
final byte[] lastKey = rocksIterator.key();
|
||||
db.deleteRange(firstKey, lastKey);
|
||||
db.delete(lastKey);
|
||||
}
|
||||
}
|
||||
db.deleteRange(firstKey, rocksIterator.key());
|
||||
} catch (final RocksDBException e) {
|
||||
throw new StorageException(e);
|
||||
}
|
||||
|
||||
@@ -76,6 +76,22 @@ public abstract class AbstractKeyValueStorageTest {
|
||||
assertThat(store.containsKey(BytesValue.fromHexString("12"))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clearRemovesAll() throws Exception {
|
||||
final KeyValueStorage store = createStore();
|
||||
Transaction tx = store.startTransaction();
|
||||
tx.put(BytesValue.fromHexString("0F"), BytesValue.fromHexString("0ABC"));
|
||||
tx.put(BytesValue.fromHexString("10"), BytesValue.fromHexString("0ABC"));
|
||||
tx.put(BytesValue.fromHexString("11"), BytesValue.fromHexString("0ABC"));
|
||||
tx.put(BytesValue.fromHexString("12"), BytesValue.fromHexString("0ABC"));
|
||||
tx.commit();
|
||||
store.clear();
|
||||
assertThat(store.containsKey(BytesValue.fromHexString("0F"))).isFalse();
|
||||
assertThat(store.containsKey(BytesValue.fromHexString("10"))).isFalse();
|
||||
assertThat(store.containsKey(BytesValue.fromHexString("11"))).isFalse();
|
||||
assertThat(store.containsKey(BytesValue.fromHexString("12"))).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void containsKey() throws Exception {
|
||||
final KeyValueStorage store = createStore();
|
||||
|
||||
Reference in New Issue
Block a user