mirror of
https://github.com/vacp2p/linea-besu.git
synced 2026-01-09 23:47:57 -05:00
refactor-privacy-storage (#7)
* refactor-privacy-storage Signed-off-by: Ivaylo Kirilov <iikirilov@gmail.com>
This commit is contained in:
committed by
MadelineMurray
parent
f84bd55f2f
commit
c09145e490
@@ -28,6 +28,7 @@ import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class InMemoryKeyValueStorage implements KeyValueStorage {
|
||||
|
||||
@@ -88,6 +89,14 @@ public class InMemoryKeyValueStorage implements KeyValueStorage {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> getAllKeysThat(final Predicate<byte[]> returnCondition) {
|
||||
return hashValueStore.keySet().stream()
|
||||
.map(BytesValue::getArrayUnsafe)
|
||||
.filter(returnCondition)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
@@ -88,6 +89,14 @@ public class LimitedInMemoryKeyValueStorage implements KeyValueStorage {
|
||||
return initialSize - storage.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> getAllKeysThat(final Predicate<byte[]> returnCondition) {
|
||||
return storage.asMap().keySet().stream()
|
||||
.map(BytesValue::getArrayUnsafe)
|
||||
.filter(returnCondition)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeyValueStorageTransaction startTransaction() throws StorageException {
|
||||
return new KeyValueStorageTransactionTransitionValidatorDecorator(new MemoryTransaction());
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.hyperledger.besu.plugin.services.storage.SegmentIdentifier;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
@@ -48,7 +49,9 @@ public interface SegmentedKeyValueStorage<S> extends Closeable {
|
||||
*/
|
||||
Transaction<S> startTransaction() throws StorageException;
|
||||
|
||||
long removeUnless(S segmentHandle, Predicate<byte[]> inUseCheck);
|
||||
long removeAllEntriesUnless(S segmentHandle, Predicate<byte[]> inUseCheck);
|
||||
|
||||
Set<byte[]> getAllKeysThat(S segmentHandle, Predicate<byte[]> returnCondition);
|
||||
|
||||
void clear(S segmentHandle);
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.hyperledger.besu.plugin.services.storage.SegmentIdentifier;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class SegmentedKeyValueStorageAdapter<S> implements KeyValueStorage {
|
||||
@@ -51,7 +52,12 @@ public class SegmentedKeyValueStorageAdapter<S> implements KeyValueStorage {
|
||||
|
||||
@Override
|
||||
public long removeAllKeysUnless(final Predicate<byte[]> retainCondition) throws StorageException {
|
||||
return storage.removeUnless(segmentHandle, retainCondition);
|
||||
return storage.removeAllEntriesUnless(segmentHandle, retainCondition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> getAllKeysThat(final Predicate<byte[]> returnCondition) {
|
||||
return storage.getAllKeysThat(segmentHandle, returnCondition);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user