Make KeyValueStorage extend Closeable (#207)

Replace explicit usages of RocksDbKeyValueStorage with the more generic but now just as capable KeyValueStorage.
Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
Adrian Sutton 6 years ago committed by GitHub
parent ab77bce927
commit 8b883a15d3
  1. 7
      ethereum/core/src/jmh/java/tech/pegasys/pantheon/ethereum/vm/operations/OperationBenchmarkHelper.java
  2. 9
      pantheon/src/main/java/tech/pegasys/pantheon/controller/CliquePantheonController.java
  3. 9
      pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftPantheonController.java
  4. 9
      pantheon/src/main/java/tech/pegasys/pantheon/controller/MainnetPantheonController.java
  5. 3
      services/kvstore/src/main/java/tech/pegasys/pantheon/services/kvstore/InMemoryKeyValueStorage.java
  6. 3
      services/kvstore/src/main/java/tech/pegasys/pantheon/services/kvstore/KeyValueStorage.java
  7. 2
      services/kvstore/src/main/java/tech/pegasys/pantheon/services/kvstore/RocksDbKeyValueStorage.java

@ -21,6 +21,7 @@ import tech.pegasys.pantheon.ethereum.core.BlockHeaderTestFixture;
import tech.pegasys.pantheon.ethereum.core.ExecutionContextTestFixture;
import tech.pegasys.pantheon.ethereum.core.MessageFrameTestFixture;
import tech.pegasys.pantheon.ethereum.vm.MessageFrame;
import tech.pegasys.pantheon.services.kvstore.KeyValueStorage;
import tech.pegasys.pantheon.services.kvstore.RocksDbKeyValueStorage;
import tech.pegasys.pantheon.util.uint.UInt256;
@ -34,12 +35,12 @@ import com.google.common.io.RecursiveDeleteOption;
public class OperationBenchmarkHelper {
private final Path storageDirectory;
private final RocksDbKeyValueStorage keyValueStorage;
private final KeyValueStorage keyValueStorage;
private final MessageFrame messageFrame;
private OperationBenchmarkHelper(
final Path storageDirectory,
final RocksDbKeyValueStorage keyValueStorage,
final KeyValueStorage keyValueStorage,
final MessageFrame messageFrame) {
this.storageDirectory = storageDirectory;
this.keyValueStorage = keyValueStorage;
@ -48,7 +49,7 @@ public class OperationBenchmarkHelper {
public static OperationBenchmarkHelper create() throws IOException {
final Path storageDirectory = Files.createTempDirectory("benchmark");
final RocksDbKeyValueStorage keyValueStorage = RocksDbKeyValueStorage.create(storageDirectory);
final KeyValueStorage keyValueStorage = RocksDbKeyValueStorage.create(storageDirectory);
final ExecutionContextTestFixture executionContext =
ExecutionContextTestFixture.builder().keyValueStorage(keyValueStorage).build();

@ -47,6 +47,7 @@ import tech.pegasys.pantheon.ethereum.mainnet.ScheduleBasedBlockHashFunction;
import tech.pegasys.pantheon.ethereum.p2p.api.ProtocolManager;
import tech.pegasys.pantheon.ethereum.p2p.config.SubProtocolConfiguration;
import tech.pegasys.pantheon.ethereum.worldstate.KeyValueStorageWorldStateStorage;
import tech.pegasys.pantheon.services.kvstore.KeyValueStorage;
import tech.pegasys.pantheon.services.kvstore.RocksDbKeyValueStorage;
import tech.pegasys.pantheon.util.time.SystemClock;
@ -108,7 +109,7 @@ public class CliquePantheonController implements PantheonController<CliqueContex
cliqueConfig.getLong("period", SECONDS_BETWEEN_BLOCKS_DEFAULT);
final EpochManager epochManger = new EpochManager(blocksPerEpoch);
final RocksDbKeyValueStorage kv =
final KeyValueStorage kv =
RocksDbKeyValueStorage.create(Files.createDirectories(home.resolve(DATABASE_PATH)));
final ProtocolSchedule<CliqueContext> protocolSchedule = genesisConfig.getProtocolSchedule();
final BlockHashFunction blockHashFunction =
@ -191,7 +192,11 @@ public class CliquePantheonController implements PantheonController<CliqueContex
} catch (final InterruptedException e) {
LOG.error("Failed to shutdown miner executor");
}
kv.close();
try {
kv.close();
} catch (final IOException e) {
LOG.error("Failed to close key value storage", e);
}
});
}

@ -53,6 +53,7 @@ import tech.pegasys.pantheon.ethereum.p2p.api.ProtocolManager;
import tech.pegasys.pantheon.ethereum.p2p.config.SubProtocolConfiguration;
import tech.pegasys.pantheon.ethereum.p2p.wire.SubProtocol;
import tech.pegasys.pantheon.ethereum.worldstate.KeyValueStorageWorldStateStorage;
import tech.pegasys.pantheon.services.kvstore.KeyValueStorage;
import tech.pegasys.pantheon.services.kvstore.RocksDbKeyValueStorage;
import java.io.IOException;
@ -114,7 +115,7 @@ public class IbftPantheonController implements PantheonController<IbftContext> {
final int networkId,
final KeyPair nodeKeys)
throws IOException {
final RocksDbKeyValueStorage kv =
final KeyValueStorage kv =
RocksDbKeyValueStorage.create(Files.createDirectories(home.resolve(DATABASE_PATH)));
final ProtocolSchedule<IbftContext> protocolSchedule = genesisConfig.getProtocolSchedule();
final BlockHashFunction blockHashFunction =
@ -186,7 +187,11 @@ public class IbftPantheonController implements PantheonController<IbftContext> {
} catch (final InterruptedException e) {
LOG.error("Failed to shutdown ibft processor executor");
}
kv.close();
try {
kv.close();
} catch (final IOException e) {
LOG.error("Failed to close key value storage", e);
}
};
final TransactionPool transactionPool =

@ -42,6 +42,7 @@ import tech.pegasys.pantheon.ethereum.mainnet.ScheduleBasedBlockHashFunction;
import tech.pegasys.pantheon.ethereum.p2p.api.ProtocolManager;
import tech.pegasys.pantheon.ethereum.p2p.config.SubProtocolConfiguration;
import tech.pegasys.pantheon.ethereum.worldstate.KeyValueStorageWorldStateStorage;
import tech.pegasys.pantheon.services.kvstore.KeyValueStorage;
import tech.pegasys.pantheon.services.kvstore.RocksDbKeyValueStorage;
import tech.pegasys.pantheon.util.time.SystemClock;
@ -106,7 +107,7 @@ public class MainnetPantheonController implements PantheonController<Void> {
final MiningParameters miningParams,
final KeyPair nodeKeys)
throws IOException {
final RocksDbKeyValueStorage kv =
final KeyValueStorage kv =
RocksDbKeyValueStorage.create(Files.createDirectories(home.resolve(DATABASE_PATH)));
final ProtocolSchedule<Void> protocolSchedule = genesisConfig.getProtocolSchedule();
final BlockHashFunction blockHashFunction =
@ -179,7 +180,11 @@ public class MainnetPantheonController implements PantheonController<Void> {
} catch (final InterruptedException e) {
LOG.error("Failed to shutdown miner executor");
}
kv.close();
try {
kv.close();
} catch (final IOException e) {
LOG.error("Failed to close key value storage", e);
}
});
}

@ -85,6 +85,9 @@ public class InMemoryKeyValueStorage implements KeyValueStorage {
}
}
@Override
public void close() {}
private class InMemoryTransaction extends AbstractTransaction {
private Map<BytesValue, BytesValue> updatedValues = new HashMap<>();

@ -16,12 +16,13 @@ import static com.google.common.base.Preconditions.checkState;
import tech.pegasys.pantheon.util.bytes.BytesValue;
import java.io.Closeable;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Stream;
/** Service provided by pantheon to facilitate persistent data storage. */
public interface KeyValueStorage {
public interface KeyValueStorage extends Closeable {
/**
* @param key Index into persistent data repository.

@ -48,7 +48,7 @@ public class RocksDbKeyValueStorage implements KeyValueStorage, Closeable {
RocksDB.loadLibrary();
}
public static RocksDbKeyValueStorage create(final Path storageDirectory) throws StorageException {
public static KeyValueStorage create(final Path storageDirectory) throws StorageException {
return new RocksDbKeyValueStorage(storageDirectory);
}

Loading…
Cancel
Save