change delete to not guarantee deletion

Signed-off-by: Ratan Rai Sur <ratan.r.sur@gmail.com>
pull/760/head
Ratan Rai Sur 5 years ago
parent 1356f40303
commit 2289bb34cf
  1. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/WorldStateKeyValueStorage.java
  2. 5
      plugin-api/src/main/java/org/hyperledger/besu/plugin/services/storage/KeyValueStorage.java
  3. 9
      plugins/rocksdb/src/main/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/RocksDBColumnarKeyValueStorage.java
  4. 9
      plugins/rocksdb/src/main/java/org/hyperledger/besu/plugin/services/storage/rocksdb/unsegmented/RocksDBKeyValueStorage.java
  5. 3
      services/kvstore/src/main/java/org/hyperledger/besu/services/kvstore/InMemoryKeyValueStorage.java
  6. 3
      services/kvstore/src/main/java/org/hyperledger/besu/services/kvstore/LimitedInMemoryKeyValueStorage.java
  7. 7
      services/kvstore/src/main/java/org/hyperledger/besu/services/kvstore/SegmentedKeyValueStorage.java
  8. 4
      services/kvstore/src/main/java/org/hyperledger/besu/services/kvstore/SegmentedKeyValueStorageAdapter.java

@ -100,7 +100,7 @@ public class WorldStateKeyValueStorage implements WorldStateStorage {
lock.lock();
try {
if (!inUseCheck.test(key)) {
keyValueStorage.delete(key);
keyValueStorage.tryDelete(key);
prunedKeys.incrementAndGet();
}
} finally {

@ -69,11 +69,12 @@ public interface KeyValueStorage extends Closeable {
Stream<byte[]> streamKeys();
/**
* Delete the value corresponding to the given key.
* Attempts to delete the entry with the given key. This can fail if an attempt to get a lock for
* the underlying storage times out, for example.
*
* @param key The key to delete.
*/
void delete(byte[] key);
boolean tryDelete(byte[] key);
/**
* Performs an evaluation against each key in the store, returning the set of entries that pass.

@ -54,6 +54,7 @@ import org.rocksdb.LRUCache;
import org.rocksdb.RocksDBException;
import org.rocksdb.RocksIterator;
import org.rocksdb.Statistics;
import org.rocksdb.Status;
import org.rocksdb.TransactionDB;
import org.rocksdb.TransactionDBOptions;
import org.rocksdb.WriteOptions;
@ -172,11 +173,13 @@ public class RocksDBColumnarKeyValueStorage
}
@Override
public void delete(final ColumnFamilyHandle segmentHandle, final byte[] key) {
public boolean tryDelete(final ColumnFamilyHandle segmentHandle, final byte[] key) {
try {
db.delete(segmentHandle, key);
} catch (RocksDBException e) {
throw new StorageException(e);
return true;
} catch (final RocksDBException rdbe) {
if (rdbe.getStatus().getCode() == Status.Code.TimedOut) return false;
throw new StorageException(rdbe);
}
}

@ -42,6 +42,7 @@ import org.rocksdb.Options;
import org.rocksdb.RocksDBException;
import org.rocksdb.RocksIterator;
import org.rocksdb.Statistics;
import org.rocksdb.Status;
import org.rocksdb.TransactionDB;
import org.rocksdb.TransactionDBOptions;
import org.rocksdb.WriteOptions;
@ -132,11 +133,13 @@ public class RocksDBKeyValueStorage implements KeyValueStorage {
}
@Override
public void delete(final byte[] key) {
public boolean tryDelete(final byte[] key) {
try {
db.delete(key);
} catch (RocksDBException e) {
throw new StorageException(e);
return true;
} catch (final RocksDBException rdbe) {
if (rdbe.getStatus().getCode() == Status.Code.TimedOut) return false;
throw new StorageException(rdbe);
}
}

@ -91,11 +91,12 @@ public class InMemoryKeyValueStorage implements KeyValueStorage {
}
@Override
public void delete(final byte[] key) {
public boolean tryDelete(final byte[] key) {
final Lock lock = rwLock.writeLock();
lock.lock();
try {
hashValueStore.remove(Bytes.wrap(key));
return true;
} finally {
lock.unlock();
}

@ -102,11 +102,12 @@ public class LimitedInMemoryKeyValueStorage implements KeyValueStorage {
}
@Override
public void delete(final byte[] key) {
public boolean tryDelete(final byte[] key) {
final Lock lock = rwLock.writeLock();
lock.lock();
try {
storage.invalidate(Bytes.wrap(key));
return true;
} finally {
lock.unlock();
}

@ -59,12 +59,13 @@ public interface SegmentedKeyValueStorage<S> extends Closeable {
Stream<byte[]> streamKeys(final S segmentHandle);
/**
* Deletes the entry with the given key in the given segment.
* Attempts to delete the entry with the given key in the given segment. This can fail if an
* attempt to get a lock for the underlying storage times out, for example.
*
* @param segmentHandle The segment from which we want to delete
* @param key The key we want to delete.
* @param key The key to delete.
*/
void delete(final S segmentHandle, final byte[] key);
boolean tryDelete(final S segmentHandle, byte[] key);
Set<byte[]> getAllKeysThat(S segmentHandle, Predicate<byte[]> returnCondition);

@ -61,8 +61,8 @@ public class SegmentedKeyValueStorageAdapter<S> implements KeyValueStorage {
}
@Override
public void delete(final byte[] key) {
storage.delete(segmentHandle, key);
public boolean tryDelete(final byte[] key) {
return storage.tryDelete(segmentHandle, key);
}
@Override

Loading…
Cancel
Save