Introduce RocksDbSegmentIdentifier to avoid changing the storege plug… (#3755)

* Introduce RocksDbSegmentIdentifier to avoid changing the storege plugin interface

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
This commit is contained in:
Fabio Di Fabio
2022-05-04 05:54:14 +02:00
committed by GitHub
parent fb25cdb198
commit 0fdd55d78e
5 changed files with 135 additions and 81 deletions

View File

@@ -20,18 +20,17 @@ import org.hyperledger.besu.plugin.services.storage.SegmentIdentifier;
import java.io.Closeable;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Predicate;
import java.util.stream.Stream;
/**
* Service provided by besu to facilitate persistent data storage.
* Service provided by Besu to facilitate persistent data storage.
*
* @param <S> the segment identifier type
*/
public interface SegmentedKeyValueStorage<S> extends Closeable {
AtomicReference<S> getSegmentIdentifierByName(SegmentIdentifier segment);
S getSegmentIdentifierByName(SegmentIdentifier segment);
/**
* Get the value from the associated segment and key.

View File

@@ -22,12 +22,11 @@ import org.hyperledger.besu.plugin.services.storage.SegmentIdentifier;
import java.io.IOException;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Predicate;
import java.util.stream.Stream;
public class SegmentedKeyValueStorageAdapter<S> implements KeyValueStorage {
private final AtomicReference<S> segmentHandle;
private final S segmentHandle;
private final SegmentedKeyValueStorage<S> storage;
public SegmentedKeyValueStorageAdapter(
@@ -38,32 +37,32 @@ public class SegmentedKeyValueStorageAdapter<S> implements KeyValueStorage {
@Override
public void clear() {
storage.clear(segmentHandle.get());
storage.clear(segmentHandle);
}
@Override
public boolean containsKey(final byte[] key) throws StorageException {
return storage.containsKey(segmentHandle.get(), key);
return storage.containsKey(segmentHandle, key);
}
@Override
public Optional<byte[]> get(final byte[] key) throws StorageException {
return storage.get(segmentHandle.get(), key);
return storage.get(segmentHandle, key);
}
@Override
public Set<byte[]> getAllKeysThat(final Predicate<byte[]> returnCondition) {
return storage.getAllKeysThat(segmentHandle.get(), returnCondition);
return storage.getAllKeysThat(segmentHandle, returnCondition);
}
@Override
public Stream<byte[]> streamKeys() {
return storage.streamKeys(segmentHandle.get());
return storage.streamKeys(segmentHandle);
}
@Override
public boolean tryDelete(final byte[] key) {
return storage.tryDelete(segmentHandle.get(), key);
return storage.tryDelete(segmentHandle, key);
}
@Override
@@ -78,12 +77,12 @@ public class SegmentedKeyValueStorageAdapter<S> implements KeyValueStorage {
@Override
public void put(final byte[] key, final byte[] value) {
transaction.put(segmentHandle.get(), key, value);
transaction.put(segmentHandle, key, value);
}
@Override
public void remove(final byte[] key) {
transaction.remove(segmentHandle.get(), key);
transaction.remove(segmentHandle, key);
}
@Override