Bonsai snapshot worldstate (#4409)

* use optimistictransactiondb for mutable isolated snapshots
* plumbing necessary to have a snapshot specific updater.
* snapshot rolling working
* implement AutoCloseable on BonsaiSnapshotWorldState to ensure we can correctly dispose of snapshots
* add snapshot transaction cloning, change snapshot based worldstate to extend persisted worldstate rather than in-memory worldstate

Signed-off-by: garyschulte <garyschulte@gmail.com>
This commit is contained in:
garyschulte
2022-10-13 09:42:27 -07:00
committed by GitHub
parent e0b26d2ca4
commit d73ce2116c
29 changed files with 1220 additions and 69 deletions

View File

@@ -15,24 +15,40 @@
package org.hyperledger.besu.services.kvstore;
import org.hyperledger.besu.plugin.services.exception.StorageException;
import org.hyperledger.besu.plugin.services.storage.KeyValueStorage;
import org.hyperledger.besu.plugin.services.storage.KeyValueStorageTransaction;
import org.hyperledger.besu.plugin.services.storage.SegmentIdentifier;
import org.hyperledger.besu.plugin.services.storage.SnappableKeyValueStorage;
import org.hyperledger.besu.plugin.services.storage.SnappedKeyValueStorage;
import java.io.IOException;
import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Stream;
public class SegmentedKeyValueStorageAdapter<S> implements KeyValueStorage {
public class SegmentedKeyValueStorageAdapter<S> implements SnappableKeyValueStorage {
private final S segmentHandle;
private final SegmentedKeyValueStorage<S> storage;
private final Supplier<SnappedKeyValueStorage> snapshotSupplier;
public SegmentedKeyValueStorageAdapter(
final SegmentIdentifier segment, final SegmentedKeyValueStorage<S> storage) {
this(
segment,
storage,
() -> {
throw new UnsupportedOperationException("Snapshot not supported");
});
}
public SegmentedKeyValueStorageAdapter(
final SegmentIdentifier segment,
final SegmentedKeyValueStorage<S> storage,
final Supplier<SnappedKeyValueStorage> snapshotSupplier) {
segmentHandle = storage.getSegmentIdentifierByName(segment);
this.storage = storage;
this.snapshotSupplier = snapshotSupplier;
}
@Override
@@ -96,4 +112,9 @@ public class SegmentedKeyValueStorageAdapter<S> implements KeyValueStorage {
}
};
}
@Override
public SnappedKeyValueStorage takeSnapshot() {
return snapshotSupplier.get();
}
}