use of tech.pegasys.teku.storage.server.kvstore.KvStoreAccessor.KvStoreTransaction in project teku by ConsenSys.
the class V4FinalizedKvStoreDao method ingest.
@Override
public void ingest(final KvStoreFinalizedDao finalizedDao, final int batchSize, final Consumer<String> logger) {
Preconditions.checkArgument(batchSize > 1, "Batch size must be greater than 1 element");
Preconditions.checkArgument(finalizedDao instanceof V4FinalizedKvStoreDao, "Expected instance of V4FinalizedKvStoreDao");
final V4FinalizedKvStoreDao<?> dao = (V4FinalizedKvStoreDao<?>) finalizedDao;
final Map<String, KvStoreVariable<?>> newVariables = schema.getVariableMap();
if (newVariables.size() > 0) {
final Map<String, KvStoreVariable<?>> oldVariables = dao.schema.getVariableMap();
try (final KvStoreTransaction transaction = db.startTransaction()) {
for (String key : newVariables.keySet()) {
logger.accept(String.format("Copy variable %s", key));
dao.getRawVariable(oldVariables.get(key)).ifPresent(value -> transaction.putRaw(newVariables.get(key), value));
}
transaction.commit();
}
}
final Map<String, KvStoreColumn<?, ?>> newColumns = schema.getColumnMap();
if (newColumns.size() > 0) {
final Map<String, KvStoreColumn<?, ?>> oldColumns = dao.schema.getColumnMap();
for (String key : newColumns.keySet()) {
final Optional<UInt64> maybeCount = displayCopyColumnMessage(key, oldColumns, dao, logger);
try (final Stream<ColumnEntry<Bytes, Bytes>> oldEntryStream = dao.streamRawColumn(oldColumns.get(key));
BatchWriter batchWriter = new BatchWriter(batchSize, logger, db, maybeCount)) {
oldEntryStream.forEach(entry -> batchWriter.add(newColumns.get(key), entry));
}
}
}
}
use of tech.pegasys.teku.storage.server.kvstore.KvStoreAccessor.KvStoreTransaction in project teku by ConsenSys.
the class LevelDbInstanceTest method shouldStoreAndLoadSimpleKey.
@Test
void shouldStoreAndLoadSimpleKey() {
try (final KvStoreTransaction update = instance.startTransaction()) {
update.put(column1, 0, 0);
update.put(column1, 1, 1);
update.put(column2, 1, 2);
update.put(column3, 0, 3);
update.commit();
}
assertThat(instance.get(column1, 0)).contains(0);
assertThat(instance.get(column1, 1)).contains(1);
assertThat(instance.get(column1, 2)).isEmpty();
assertThat(instance.get(column2, 0)).isEmpty();
assertThat(instance.get(column2, 1)).contains(2);
assertThat(instance.get(column3, 0)).contains(3);
assertThat(instance.get(column3, 1)).isEmpty();
}
use of tech.pegasys.teku.storage.server.kvstore.KvStoreAccessor.KvStoreTransaction in project teku by ConsenSys.
the class LevelDbInstanceTest method update.
private void update(final Consumer<KvStoreTransaction> updater) {
try (final KvStoreTransaction transaction = instance.startTransaction()) {
updater.accept(transaction);
transaction.commit();
}
}
use of tech.pegasys.teku.storage.server.kvstore.KvStoreAccessor.KvStoreTransaction in project teku by ConsenSys.
the class KvStoreTreeNodeSourceTest method storeBranch.
private CompressedBranchInfo storeBranch(final Bytes32 root, final int depth, final Bytes32... children) {
try (final KvStoreTransaction transaction = accessor.startTransaction()) {
final CompressedBranchInfo value = new CompressedBranchInfo(depth, children);
transaction.put(schema.getColumnFinalizedStateMerkleTreeBranches(), root, value);
transaction.commit();
return value;
}
}
use of tech.pegasys.teku.storage.server.kvstore.KvStoreAccessor.KvStoreTransaction in project teku by ConsenSys.
the class KvStoreTreeNodeSourceTest method storeLeaf.
private void storeLeaf(final Bytes32 root, final Bytes value) {
try (final KvStoreTransaction transaction = accessor.startTransaction()) {
transaction.put(schema.getColumnFinalizedStateMerkleTreeLeaves(), root, value);
transaction.commit();
}
}
Aggregations