remove removeAllKeysUnless from interfaces and its implemntation (#936)

Signed-off-by: yehia67 <yehiatarek67@gmail.com>
pull/952/head
Yehia Tarek 5 years ago committed by GitHub
parent 9d5339d73a
commit 93996e349e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      plugin-api/build.gradle
  2. 11
      plugin-api/src/main/java/org/hyperledger/besu/plugin/services/storage/KeyValueStorage.java
  3. 18
      plugins/rocksdb/src/main/java/org/hyperledger/besu/plugin/services/storage/rocksdb/segmented/RocksDBColumnarKeyValueStorage.java
  4. 17
      plugins/rocksdb/src/main/java/org/hyperledger/besu/plugin/services/storage/rocksdb/unsegmented/RocksDBKeyValueStorage.java
  5. 13
      services/kvstore/src/main/java/org/hyperledger/besu/services/kvstore/InMemoryKeyValueStorage.java
  6. 13
      services/kvstore/src/main/java/org/hyperledger/besu/services/kvstore/LimitedInMemoryKeyValueStorage.java
  7. 12
      services/kvstore/src/main/java/org/hyperledger/besu/services/kvstore/SegmentedKeyValueStorage.java
  8. 5
      services/kvstore/src/main/java/org/hyperledger/besu/services/kvstore/SegmentedKeyValueStorageAdapter.java

@ -64,7 +64,7 @@ Calculated : ${currentHash}
tasks.register('checkAPIChanges', FileStateChecker) {
description = "Checks that the API for the Plugin-API project does not change without deliberate thought"
files = sourceSets.main.allJava.files
knownHash = 'x6hLH75JBKLM8mNFz7n0ALRw4TWiDONJuum53da4jTY='
knownHash = 'd2HD6T1USSbVL9OftLuNlmJO25d1WscqrxCIimdhtgM='
}
check.dependsOn('checkAPIChanges')

@ -69,17 +69,6 @@ public interface KeyValueStorage extends Closeable {
*/
Stream<byte[]> streamKeys() throws StorageException;
/**
* Performs an evaluation against each key in the store, keeping the entries that pass, removing
* those that fail.
*
* @param retainCondition predicate to evaluate each key against, unless the result is {@code
* null}, both the key and associated value must be removed.
* @return the number of keys removed.
* @throws StorageException problem encountered during the retrieval attempt.
*/
long removeAllKeysUnless(Predicate<byte[]> retainCondition) throws StorageException;
/**
* Delete the value corresponding to the given key if a write lock can be instantly acquired on
* the underlying storage. Do nothing otherwise.

@ -173,24 +173,6 @@ public class RocksDBColumnarKeyValueStorage
return RocksDbKeyIterator.create(rocksIterator).toStream();
}
@Override
public long removeAllKeysUnless(
final ColumnFamilyHandle segmentHandle, final Predicate<byte[]> inUseCheck) {
long removedNodeCounter = 0;
try (final RocksIterator rocksIterator = db.newIterator(segmentHandle)) {
for (rocksIterator.seekToFirst(); rocksIterator.isValid(); rocksIterator.next()) {
final byte[] key = rocksIterator.key();
if (!inUseCheck.test(key)) {
removedNodeCounter++;
db.delete(segmentHandle, key);
}
}
} catch (final RocksDBException e) {
throw new StorageException(e);
}
return removedNodeCounter;
}
@Override
public boolean tryDelete(final ColumnFamilyHandle segmentHandle, final byte[] key) {
try {

@ -133,23 +133,6 @@ public class RocksDBKeyValueStorage implements KeyValueStorage {
return RocksDbKeyIterator.create(rocksIterator).toStream();
}
@Override
public long removeAllKeysUnless(final Predicate<byte[]> retainCondition) throws StorageException {
long removedNodeCounter = 0;
try (final RocksIterator rocksIterator = db.newIterator()) {
for (rocksIterator.seekToFirst(); rocksIterator.isValid(); rocksIterator.next()) {
final byte[] key = rocksIterator.key();
if (!retainCondition.test(key)) {
removedNodeCounter++;
db.delete(key);
}
}
} catch (final RocksDBException e) {
throw new StorageException(e);
}
return removedNodeCounter;
}
@Override
public boolean tryDelete(final byte[] key) {
try {

@ -90,19 +90,6 @@ public class InMemoryKeyValueStorage implements KeyValueStorage {
}
}
@Override
public long removeAllKeysUnless(final Predicate<byte[]> retainCondition) throws StorageException {
final Lock lock = rwLock.writeLock();
lock.lock();
try {
long initialSize = hashValueStore.keySet().size();
hashValueStore.keySet().removeIf(key -> !retainCondition.test(key.toArrayUnsafe()));
return initialSize - hashValueStore.keySet().size();
} finally {
lock.unlock();
}
}
@Override
public boolean tryDelete(final byte[] key) {
final Lock lock = rwLock.writeLock();

@ -95,19 +95,6 @@ public class LimitedInMemoryKeyValueStorage implements KeyValueStorage {
}
}
@Override
public long removeAllKeysUnless(final Predicate<byte[]> retainCondition) throws StorageException {
final Lock lock = rwLock.writeLock();
lock.lock();
try {
final long initialSize = storage.size();
storage.asMap().keySet().removeIf(key -> !retainCondition.test(key.toArrayUnsafe()));
return initialSize - storage.size();
} finally {
lock.unlock();
}
}
@Override
public boolean tryDelete(final byte[] key) {
final Lock lock = rwLock.writeLock();

@ -58,18 +58,6 @@ public interface SegmentedKeyValueStorage<S> extends Closeable {
*/
Stream<byte[]> streamKeys(final S segmentHandle);
/**
* Performs an evaluation against each key in the store, keeping the entries that pass, removing
* those that fail.
*
* @param segmentHandle The segment handle whose keys we want to stream.
* @param retainCondition predicate to evaluate each key against, unless the result is {@code
* null}, both the key and associated value must be removed.
* @return the number of keys removed.
*/
long removeAllKeysUnless(final S segmentHandle, Predicate<byte[]> retainCondition)
throws StorageException;
/**
* Delete the value corresponding to the given key in the given segment if a write lock can be
* instantly acquired on the underlying storage. Do nothing otherwise.

@ -60,11 +60,6 @@ public class SegmentedKeyValueStorageAdapter<S> implements KeyValueStorage {
return storage.streamKeys(segmentHandle);
}
@Override
public long removeAllKeysUnless(final Predicate<byte[]> retainCondition) throws StorageException {
return storage.removeAllKeysUnless(segmentHandle, retainCondition);
}
@Override
public boolean tryDelete(final byte[] key) {
return storage.tryDelete(segmentHandle, key);

Loading…
Cancel
Save