Search in sources :

Example 6 with DOMStoreThreePhaseCommitCohort

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

the class DOMForwardedWriteTransaction method submit.

@Override
@SuppressWarnings("checkstyle:illegalcatch")
public CheckedFuture<Void, TransactionCommitFailedException> submit() {
    final AbstractDOMForwardedTransactionFactory<?> impl = IMPL_UPDATER.getAndSet(this, null);
    checkRunning(impl);
    final Collection<T> txns = getSubtransactions();
    final Collection<DOMStoreThreePhaseCommitCohort> cohorts = new ArrayList<>(txns.size());
    CheckedFuture<Void, TransactionCommitFailedException> ret;
    try {
        for (DOMStoreWriteTransaction txn : txns) {
            cohorts.add(txn.ready());
        }
        ret = impl.submit(this, cohorts);
    } catch (RuntimeException e) {
        ret = Futures.immediateFailedCheckedFuture(TransactionCommitFailedExceptionMapper.COMMIT_ERROR_MAPPER.apply(e));
    }
    FUTURE_UPDATER.lazySet(this, ret);
    return ret;
}
Also used : TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) DOMStoreWriteTransaction(org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction) ArrayList(java.util.ArrayList) DOMStoreThreePhaseCommitCohort(org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort)

Example 7 with DOMStoreThreePhaseCommitCohort

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

the class CommitCoordinationTask method commitAll.

/**
 * Invokes commit on underlying cohorts and returns future which
 * completes
 * once all commits on cohorts are completed.
 *
 * <p>
 * Valid state transition is from PRE_COMMIT to COMMIT, if not throws
 * IllegalStateException
 *
 * @return List of all cohorts futures from can commit phase.
 */
private ListenableFuture<?>[] commitAll() {
    final ListenableFuture<?>[] ops = new ListenableFuture<?>[cohorts.size()];
    int index = 0;
    for (final DOMStoreThreePhaseCommitCohort cohort : cohorts) {
        ops[index++] = cohort.commit();
    }
    return ops;
}
Also used : ListenableFuture(com.google.common.util.concurrent.ListenableFuture) DOMStoreThreePhaseCommitCohort(org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort)

Example 8 with DOMStoreThreePhaseCommitCohort

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

the class CommitCoordinationTask method preCommitAll.

/**
 * Invokes preCommit on underlying cohorts and returns future
 * which will complete once all preCommit on cohorts completed or
 * failed.
 *
 * <p>
 * Valid state transition is from CAN_COMMIT to PRE_COMMIT, if current
 * state is not CAN_COMMIT
 * throws IllegalStateException.
 *
 * @return List of all cohorts futures from can commit phase.
 */
private ListenableFuture<?>[] preCommitAll() {
    final ListenableFuture<?>[] ops = new ListenableFuture<?>[cohorts.size()];
    int index = 0;
    for (final DOMStoreThreePhaseCommitCohort cohort : cohorts) {
        ops[index++] = cohort.preCommit();
    }
    return ops;
}
Also used : ListenableFuture(com.google.common.util.concurrent.ListenableFuture) DOMStoreThreePhaseCommitCohort(org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort)

Example 9 with DOMStoreThreePhaseCommitCohort

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

the class AbstractModificationTest method commitTransaction.

protected void commitTransaction(final DOMStoreWriteTransaction transaction) {
    DOMStoreThreePhaseCommitCohort cohort = transaction.ready();
    cohort.preCommit();
    cohort.commit();
}
Also used : DOMStoreThreePhaseCommitCohort(org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort)

Example 10 with DOMStoreThreePhaseCommitCohort

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

the class InMemoryDataStoreTest method testReadyWithMissingMandatoryData.

@Test
public void testReadyWithMissingMandatoryData() throws InterruptedException {
    DOMStoreWriteTransaction writeTx = domStore.newWriteOnlyTransaction();
    NormalizedNode<?, ?> testNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.MANDATORY_DATA_TEST_QNAME)).addChild(ImmutableNodes.leafNode(TestModel.OPTIONAL_QNAME, "data")).build();
    writeTx.write(TestModel.MANDATORY_DATA_TEST_PATH, testNode);
    DOMStoreThreePhaseCommitCohort ready = writeTx.ready();
    try {
        ready.canCommit().get();
        Assert.fail("Expected exception on canCommit");
    } catch (ExecutionException e) {
    // nop
    }
}
Also used : DOMStoreWriteTransaction(org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ExecutionException(java.util.concurrent.ExecutionException) DOMStoreThreePhaseCommitCohort(org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort) Test(org.junit.Test)

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