Search in sources :

Example 81 with Transaction

use of com.apple.foundationdb.Transaction in project fdb-record-layer by FoundationDB.

the class FDBRecordStoreStateCacheEntry method handleCachedState.

@Nonnull
CompletableFuture<Void> handleCachedState(@Nonnull FDBRecordContext context, @Nonnull FDBRecordStoreBase.StoreExistenceCheck existenceCheck) {
    final Transaction tr = context.ensureActive();
    tr.addReadConflictKey(subspace.pack(FDBRecordStoreKeyspace.STORE_INFO.key()));
    return FDBRecordStore.checkStoreHeader(recordStoreState.getStoreHeader(), context, subspaceProvider, subspace, existenceCheck);
}
Also used : Transaction(com.apple.foundationdb.Transaction) Nonnull(javax.annotation.Nonnull)

Example 82 with Transaction

use of com.apple.foundationdb.Transaction in project lionrock by panghy.

the class TestFDBVersionstamp method testActualFDBGetVersionstamp.

/**
 * Check that actual FDB client also hangs when using runAsync with getVersionstamp.
 */
@Test
public void testActualFDBGetVersionstamp() {
    Database fdb = FDB.selectAPIVersion(630).open();
    CompletableFuture<byte[]> cf = fdb.runAsync(Transaction::getVersionstamp);
    assertFalse(cf.isDone());
}
Also used : Transaction(com.apple.foundationdb.Transaction) Database(com.apple.foundationdb.Database) Test(org.junit.jupiter.api.Test)

Example 83 with Transaction

use of com.apple.foundationdb.Transaction in project lionrock by panghy.

the class RemoteDatabase method runAsync.

@Override
public <T> CompletableFuture<T> runAsync(String name, Function<? super Transaction, ? extends CompletableFuture<T>> retryable, Executor e) {
    final AtomicReference<Transaction> trRef = new AtomicReference<>(createTransaction(name, e));
    final AtomicReference<T> returnValue = new AtomicReference<>();
    return whileTrue(() -> composeHandleAsync(applySafely(retryable, trRef.get()).thenComposeAsync(returnVal -> trRef.get().commit().thenApply(o -> {
        returnValue.set(returnVal);
        return false;
    }), e), (value, t) -> {
        if (t == null) {
            return CompletableFuture.completedFuture(value);
        }
        if (!(t instanceof RuntimeException)) {
            throw new CompletionException(t);
        }
        return trRef.get().onError(t).thenApply(newTr -> {
            trRef.set(newTr);
            return true;
        });
    }, e), e).thenApply(o -> returnValue.get()).whenComplete((v, t) -> trRef.get().close());
}
Also used : DatabaseMixin(io.github.panghy.lionrock.client.foundationdb.mixins.DatabaseMixin) EventKeeper(com.apple.foundationdb.EventKeeper) Executor(java.util.concurrent.Executor) CompletableFuture(java.util.concurrent.CompletableFuture) CompletionException(java.util.concurrent.CompletionException) Database(com.apple.foundationdb.Database) AsyncUtil(com.apple.foundationdb.async.AsyncUtil) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) TransactionalKeyValueStoreGrpc(io.github.panghy.lionrock.proto.TransactionalKeyValueStoreGrpc) Transaction(com.apple.foundationdb.Transaction) AtomicLong(java.util.concurrent.atomic.AtomicLong) DatabaseOptions(com.apple.foundationdb.DatabaseOptions) Transaction(com.apple.foundationdb.Transaction) CompletionException(java.util.concurrent.CompletionException) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 84 with Transaction

use of com.apple.foundationdb.Transaction in project bsv-components-library by bitcoin-sv.

the class BlockChainStoreFDB method start.

@Override
public void start() {
    super.start();
    // If the DB is empty, we initialize it with the Genesis block:
    if (getNumBlocks() == 0) {
        Transaction tr = createTransaction();
        executeInTransaction(tr, () -> _initGenesisBlock(tr, config.getGenesisBlock()));
    }
    // If enabled, we start the job to publish the DB State:
    if (statePublishFrequency != null)
        this.scheduledExecutorService.scheduleAtFixedRate(this::_publishState, statePublishFrequency.toMillis(), statePublishFrequency.toMillis(), TimeUnit.MILLISECONDS);
    // If enabled, we start the job to do the automatic Prunning:
    if (enableAutomaticForkPrunning)
        this.scheduledExecutorService.scheduleAtFixedRate(this::_automaticForkPrunning, forkPrunningFrequency.toMillis(), forkPrunningFrequency.toMillis(), TimeUnit.MILLISECONDS);
    // If enabled, we start the job to do the automatic ORPHAN Prunning:
    if (enableAutomaticOrphanPrunning)
        this.scheduledExecutorService.scheduleAtFixedRate(this::_automaticOrphanPrunning, orphanPrunningFrequency.toMillis(), orphanPrunningFrequency.toMillis(), TimeUnit.MILLISECONDS);
}
Also used : Transaction(com.apple.foundationdb.Transaction)

Aggregations

Transaction (com.apple.foundationdb.Transaction)84 ReadTransaction (com.apple.foundationdb.ReadTransaction)34 Tuple (com.apple.foundationdb.tuple.Tuple)34 Test (org.junit.jupiter.api.Test)33 Nonnull (javax.annotation.Nonnull)28 ArrayList (java.util.ArrayList)26 List (java.util.List)26 CompletableFuture (java.util.concurrent.CompletableFuture)26 AsyncUtil (com.apple.foundationdb.async.AsyncUtil)22 Subspace (com.apple.foundationdb.subspace.Subspace)21 Collectors (java.util.stream.Collectors)19 Nullable (javax.annotation.Nullable)19 KeyValue (com.apple.foundationdb.KeyValue)18 Map (java.util.Map)18 KeyValueLogMessage (com.apple.foundationdb.record.logging.KeyValueLogMessage)17 Range (com.apple.foundationdb.Range)16 RecordCoreException (com.apple.foundationdb.record.RecordCoreException)16 AtomicReference (java.util.concurrent.atomic.AtomicReference)16 Collections (java.util.Collections)15 RecordCursor (com.apple.foundationdb.record.RecordCursor)14