Search in sources :

Example 1 with KvStoreTransaction

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));
            }
        }
    }
}
Also used : KvStoreVariable(tech.pegasys.teku.storage.server.kvstore.schema.KvStoreVariable) ColumnEntry(tech.pegasys.teku.storage.server.kvstore.ColumnEntry) KvStoreTransaction(tech.pegasys.teku.storage.server.kvstore.KvStoreAccessor.KvStoreTransaction) KvStoreColumn(tech.pegasys.teku.storage.server.kvstore.schema.KvStoreColumn) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64)

Example 2 with KvStoreTransaction

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();
}
Also used : KvStoreTransaction(tech.pegasys.teku.storage.server.kvstore.KvStoreAccessor.KvStoreTransaction) Test(org.junit.jupiter.api.Test)

Example 3 with KvStoreTransaction

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();
    }
}
Also used : KvStoreTransaction(tech.pegasys.teku.storage.server.kvstore.KvStoreAccessor.KvStoreTransaction)

Example 4 with KvStoreTransaction

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;
    }
}
Also used : KvStoreTransaction(tech.pegasys.teku.storage.server.kvstore.KvStoreAccessor.KvStoreTransaction) CompressedBranchInfo(tech.pegasys.teku.infrastructure.ssz.tree.TreeNodeSource.CompressedBranchInfo)

Example 5 with KvStoreTransaction

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();
    }
}
Also used : KvStoreTransaction(tech.pegasys.teku.storage.server.kvstore.KvStoreAccessor.KvStoreTransaction)

Aggregations

KvStoreTransaction (tech.pegasys.teku.storage.server.kvstore.KvStoreAccessor.KvStoreTransaction)9 Test (org.junit.jupiter.api.Test)3 ColumnEntry (tech.pegasys.teku.storage.server.kvstore.ColumnEntry)2 KvStoreColumn (tech.pegasys.teku.storage.server.kvstore.schema.KvStoreColumn)2 KvStoreVariable (tech.pegasys.teku.storage.server.kvstore.schema.KvStoreVariable)2 CompressedBranchInfo (tech.pegasys.teku.infrastructure.ssz.tree.TreeNodeSource.CompressedBranchInfo)1 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)1 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)1 SchemaFinalizedTreeState (tech.pegasys.teku.storage.server.kvstore.schema.SchemaFinalizedTreeState)1