Search in sources :

Example 11 with DOMStoreThreePhaseCommitCohort

use of org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort in project controller by opendaylight.

the class InMemoryDataStoreTest method testTransactionAbort.

@Test
public void testTransactionAbort() throws InterruptedException, ExecutionException {
    DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
    assertNotNull(writeTx);
    assertTestContainerWrite(writeTx);
    DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
    assertTrue(cohort.canCommit().get().booleanValue());
    cohort.preCommit().get();
    cohort.abort().get();
    Optional<NormalizedNode<?, ?>> afterCommitRead = domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH).get();
    assertFalse(afterCommitRead.isPresent());
}
Also used : DOMStoreReadWriteTransaction(org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DOMStoreThreePhaseCommitCohort(org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort) Test(org.junit.Test)

Example 12 with DOMStoreThreePhaseCommitCohort

use of org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort in project controller by opendaylight.

the class InMemoryDataStoreTest method testTransactionCommit.

@Test
public void testTransactionCommit() throws InterruptedException, ExecutionException {
    DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
    assertNotNull(writeTx);
    /*
         * Writes /test in writeTx
         */
    NormalizedNode<?, ?> testNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
    writeTx.write(TestModel.TEST_PATH, testNode);
    /*
         * Reads /test from writeTx Read should return container.
         */
    ListenableFuture<Optional<NormalizedNode<?, ?>>> writeTxContainer = writeTx.read(TestModel.TEST_PATH);
    assertEquals("read: isPresent", true, writeTxContainer.get().isPresent());
    assertEquals("read: data", testNode, writeTxContainer.get().get());
    DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
    assertThreePhaseCommit(cohort);
    Optional<NormalizedNode<?, ?>> afterCommitRead = domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH).get();
    assertEquals("After commit read: isPresent", true, afterCommitRead.isPresent());
    assertEquals("After commit read: data", testNode, afterCommitRead.get());
}
Also used : Optional(com.google.common.base.Optional) DOMStoreReadWriteTransaction(org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DOMStoreThreePhaseCommitCohort(org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort) Test(org.junit.Test)

Example 13 with DOMStoreThreePhaseCommitCohort

use of org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort in project controller by opendaylight.

the class CommitCoordinationTask method canCommitAll.

/**
 * Invokes canCommit on underlying cohorts and returns composite future
 * which will contains {@link Boolean#TRUE} only and only if
 * all cohorts returned true.
 *
 * <p>
 * Valid state transition is from SUBMITTED to CAN_COMMIT,
 * if currentPhase is not SUBMITTED throws IllegalStateException.
 *
 * @return List of all cohorts futures from can commit phase.
 */
private ListenableFuture<?>[] canCommitAll() {
    final ListenableFuture<?>[] ops = new ListenableFuture<?>[cohorts.size()];
    int index = 0;
    for (final DOMStoreThreePhaseCommitCohort cohort : cohorts) {
        ops[index++] = cohort.canCommit();
    }
    return ops;
}
Also used : ListenableFuture(com.google.common.util.concurrent.ListenableFuture) DOMStoreThreePhaseCommitCohort(org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort)

Example 14 with DOMStoreThreePhaseCommitCohort

use of org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort in project controller by opendaylight.

the class CommitCoordinationTask method abortAsyncAll.

/**
 * Invokes abort on underlying cohorts and returns future which
 * completes once all abort on cohorts are completed.
 *
 * @return Future which will complete once all cohorts completed
 *         abort.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
private ListenableFuture<Void> abortAsyncAll() {
    final ListenableFuture<?>[] ops = new ListenableFuture<?>[cohorts.size()];
    int index = 0;
    for (final DOMStoreThreePhaseCommitCohort cohort : cohorts) {
        ops[index++] = cohort.abort();
    }
    /*
         * We are returning all futures as list, not only succeeded ones in
         * order to fail composite future if any of them failed.
         * See Futures.allAsList for this description.
         */
    return (ListenableFuture) Futures.allAsList(ops);
}
Also used : ListenableFuture(com.google.common.util.concurrent.ListenableFuture) DOMStoreThreePhaseCommitCohort(org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort)

Example 15 with DOMStoreThreePhaseCommitCohort

use of org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort in project controller by opendaylight.

the class AbstractInMemoryDatastoreWriteTransactionBenchmark method write10KSingleNodeWithTenInnerItemsInOneCommitBenchmark.

@Benchmark
@Warmup(iterations = WARMUP_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = MEASUREMENT_ITERATIONS, timeUnit = TimeUnit.MILLISECONDS)
public void write10KSingleNodeWithTenInnerItemsInOneCommitBenchmark() throws Exception {
    DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
    for (int outerListKey = 0; outerListKey < OUTER_LIST_10K; ++outerListKey) {
        writeTx.write(OUTER_LIST_10K_PATHS[outerListKey], OUTER_LIST_TEN_ITEM_INNER_LIST[outerListKey]);
    }
    DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
    cohort.canCommit().get();
    cohort.preCommit().get();
    cohort.commit().get();
}
Also used : DOMStoreReadWriteTransaction(org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction) DOMStoreThreePhaseCommitCohort(org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort) Measurement(org.openjdk.jmh.annotations.Measurement) Warmup(org.openjdk.jmh.annotations.Warmup) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Aggregations

DOMStoreThreePhaseCommitCohort (org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort)19 DOMStoreReadWriteTransaction (org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction)12 Benchmark (org.openjdk.jmh.annotations.Benchmark)6 Measurement (org.openjdk.jmh.annotations.Measurement)6 Warmup (org.openjdk.jmh.annotations.Warmup)6 Test (org.junit.Test)5 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)4 DOMStoreReadTransaction (org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction)2 DOMStoreWriteTransaction (org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction)2 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)2 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)2 Optional (com.google.common.base.Optional)1 ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)1 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)1 DOMStoreTransactionChain (org.opendaylight.controller.sal.core.spi.data.DOMStoreTransactionChain)1 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)1 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)1