Search in sources :

Example 21 with DOMStoreThreePhaseCommitCohort

use of org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort in project controller by opendaylight.

the class TransactionProxyTest method testReadyWithReadWrite.

@Test
public void testReadyWithReadWrite() throws Exception {
    ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE);
    final NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
    doReturn(readDataReply(null)).when(mockActorContext).executeOperationAsync(eq(actorSelection(actorRef)), eqReadData(), any(Timeout.class));
    expectBatchedModificationsReady(actorRef, true);
    TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE);
    transactionProxy.read(TestModel.TEST_PATH);
    transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
    DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready();
    assertTrue(ready instanceof SingleCommitCohortProxy);
    verifyCohortFutures((SingleCommitCohortProxy) ready, new CommitTransactionReply().toSerializable());
    List<BatchedModifications> batchedModifications = captureBatchedModifications(actorRef);
    assertEquals("Captured BatchedModifications count", 1, batchedModifications.size());
    verifyBatchedModifications(batchedModifications.get(0), true, true, new WriteModification(TestModel.TEST_PATH, nodeToWrite));
    assertEquals("getTotalMessageCount", 1, batchedModifications.get(0).getTotalMessagesSent());
}
Also used : WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) CommitTransactionReply(org.opendaylight.controller.cluster.datastore.messages.CommitTransactionReply) ActorRef(akka.actor.ActorRef) Timeout(akka.util.Timeout) DOMStoreThreePhaseCommitCohort(org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications) NormalizedNodeAggregatorTest(org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregatorTest) Test(org.junit.Test)

Example 22 with DOMStoreThreePhaseCommitCohort

use of org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort in project controller by opendaylight.

the class ConcurrentDOMDataBroker method doCanCommit.

private void doCanCommit(final AsyncNotifyingSettableFuture clientSubmitFuture, final DOMDataTreeWriteTransaction transaction, final Collection<DOMStoreThreePhaseCommitCohort> cohorts) {
    final long startTime = System.nanoTime();
    final Iterator<DOMStoreThreePhaseCommitCohort> cohortIterator = cohorts.iterator();
    // Not using Futures.allAsList here to avoid its internal overhead.
    FutureCallback<Boolean> futureCallback = new FutureCallback<Boolean>() {

        @Override
        public void onSuccess(final Boolean result) {
            if (result == null || !result) {
                handleException(clientSubmitFuture, transaction, cohorts, CAN_COMMIT, CAN_COMMIT_ERROR_MAPPER, new TransactionCommitFailedException("Can Commit failed, no detailed cause available."));
            } else if (!cohortIterator.hasNext()) {
                // All cohorts completed successfully - we can move on to the preCommit phase
                doPreCommit(startTime, clientSubmitFuture, transaction, cohorts);
            } else {
                Futures.addCallback(cohortIterator.next().canCommit(), this, MoreExecutors.directExecutor());
            }
        }

        @Override
        public void onFailure(final Throwable failure) {
            handleException(clientSubmitFuture, transaction, cohorts, CAN_COMMIT, CAN_COMMIT_ERROR_MAPPER, failure);
        }
    };
    ListenableFuture<Boolean> canCommitFuture = cohortIterator.next().canCommit();
    Futures.addCallback(canCommitFuture, futureCallback, MoreExecutors.directExecutor());
}
Also used : TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) DOMStoreThreePhaseCommitCohort(org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort) FutureCallback(com.google.common.util.concurrent.FutureCallback)

Example 23 with DOMStoreThreePhaseCommitCohort

use of org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort in project controller by opendaylight.

the class ConcurrentDOMDataBroker method handleException.

@SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE", justification = "Pertains to the assignment of the 'clientException' var. FindBugs flags this as an " + "uncomfirmed cast but the generic type in TransactionCommitFailedExceptionMapper is " + "TransactionCommitFailedException and thus should be deemed as confirmed.")
private static void handleException(final AsyncNotifyingSettableFuture clientSubmitFuture, final DOMDataTreeWriteTransaction transaction, final Collection<DOMStoreThreePhaseCommitCohort> cohorts, final String phase, final TransactionCommitFailedExceptionMapper exMapper, final Throwable throwable) {
    if (clientSubmitFuture.isDone()) {
        // We must have had failures from multiple cohorts.
        return;
    }
    // Use debug instead of warn level here because this exception gets propagate back to the caller via the Future
    LOG.debug("Tx: {} Error during phase {}, starting Abort", transaction.getIdentifier(), phase, throwable);
    // Transaction failed - tell all cohorts to abort.
    @SuppressWarnings("unchecked") ListenableFuture<Void>[] canCommitFutures = new ListenableFuture[cohorts.size()];
    int index = 0;
    for (DOMStoreThreePhaseCommitCohort cohort : cohorts) {
        canCommitFutures[index++] = cohort.abort();
    }
    // Propagate the original exception
    final Exception e;
    if (throwable instanceof NoShardLeaderException || throwable instanceof ShardLeaderNotRespondingException) {
        e = new DataStoreUnavailableException(throwable.getMessage(), throwable);
    } else if (throwable instanceof Exception) {
        e = (Exception) throwable;
    } else {
        e = new RuntimeException("Unexpected error occurred", throwable);
    }
    clientSubmitFuture.setException(exMapper.apply(e));
    ListenableFuture<List<Void>> combinedFuture = Futures.allAsList(canCommitFutures);
    Futures.addCallback(combinedFuture, new FutureCallback<List<Void>>() {

        @Override
        public void onSuccess(final List<Void> notUsed) {
            // Propagate the original exception to the client.
            LOG.debug("Tx: {} aborted successfully", transaction.getIdentifier());
        }

        @Override
        public void onFailure(final Throwable failure) {
            LOG.error("Tx: {} Error during Abort.", transaction.getIdentifier(), failure);
        }
    }, MoreExecutors.directExecutor());
}
Also used : DataStoreUnavailableException(org.opendaylight.mdsal.common.api.DataStoreUnavailableException) DOMStoreThreePhaseCommitCohort(org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort) ShardLeaderNotRespondingException(org.opendaylight.controller.cluster.datastore.exceptions.ShardLeaderNotRespondingException) DataStoreUnavailableException(org.opendaylight.mdsal.common.api.DataStoreUnavailableException) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) NoShardLeaderException(org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException) ShardLeaderNotRespondingException(org.opendaylight.controller.cluster.datastore.exceptions.ShardLeaderNotRespondingException) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) List(java.util.List) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 24 with DOMStoreThreePhaseCommitCohort

use of org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort in project controller by opendaylight.

the class ClusterAdminRpcServiceTest method writeCarsNodeAndVerify.

private static NormalizedNode<?, ?> writeCarsNodeAndVerify(AbstractDataStore writeToStore, AbstractDataStore readFromStore) throws Exception {
    DOMStoreWriteTransaction writeTx = writeToStore.newWriteOnlyTransaction();
    NormalizedNode<?, ?> carsNode = CarsModel.create();
    writeTx.write(CarsModel.BASE_PATH, carsNode);
    DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
    Boolean canCommit = cohort.canCommit().get(7, TimeUnit.SECONDS);
    assertEquals("canCommit", TRUE, canCommit);
    cohort.preCommit().get(5, TimeUnit.SECONDS);
    cohort.commit().get(5, TimeUnit.SECONDS);
    readCarsNodeAndVerify(readFromStore, carsNode);
    return carsNode;
}
Also used : DOMStoreWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction) DOMStoreThreePhaseCommitCohort(org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort)

Example 25 with DOMStoreThreePhaseCommitCohort

use of org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort in project controller by opendaylight.

the class NormalizedNodeAggregatorTest method getRootNode.

public static NormalizedNode<?, ?> getRootNode(NormalizedNode<?, ?> moduleNode, SchemaContext schemaContext) throws ReadFailedException, ExecutionException, InterruptedException {
    try (InMemoryDOMDataStore store = new InMemoryDOMDataStore("test", Executors.newSingleThreadExecutor())) {
        store.onGlobalContextUpdated(schemaContext);
        DOMStoreWriteTransaction writeTransaction = store.newWriteOnlyTransaction();
        writeTransaction.merge(YangInstanceIdentifier.of(moduleNode.getNodeType()), moduleNode);
        DOMStoreThreePhaseCommitCohort ready = writeTransaction.ready();
        ready.canCommit().get();
        ready.preCommit().get();
        ready.commit().get();
        DOMStoreReadTransaction readTransaction = store.newReadOnlyTransaction();
        CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read = readTransaction.read(YangInstanceIdentifier.EMPTY);
        Optional<NormalizedNode<?, ?>> nodeOptional = read.checkedGet();
        return nodeOptional.get();
    }
}
Also used : ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) Optional(com.google.common.base.Optional) DOMStoreWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction) DOMStoreReadTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction) InMemoryDOMDataStore(org.opendaylight.mdsal.dom.store.inmemory.InMemoryDOMDataStore) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DOMStoreThreePhaseCommitCohort(org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort)

Aggregations

DOMStoreThreePhaseCommitCohort (org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort)40 Test (org.junit.Test)31 DOMStoreWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction)17 ActorRef (akka.actor.ActorRef)11 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)11 NormalizedNodeAggregatorTest (org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregatorTest)10 DOMStoreReadTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction)8 DOMStoreReadWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction)8 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)8 CountDownLatch (java.util.concurrent.CountDownLatch)6 ExecutionException (java.util.concurrent.ExecutionException)6 NoShardLeaderException (org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException)6 CommitTransactionReply (org.opendaylight.controller.cluster.datastore.messages.CommitTransactionReply)6 ReadFailedException (org.opendaylight.mdsal.common.api.ReadFailedException)6 AddressFromURIString (akka.actor.AddressFromURIString)5 BatchedModifications (org.opendaylight.controller.cluster.datastore.messages.BatchedModifications)5 DOMStoreTransactionChain (org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain)5 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)5 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)5 IOException (java.io.IOException)4