Search in sources :

Example 21 with DataTreeModification

use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification in project controller by opendaylight.

the class ShardDataTree method finishTransaction.

@Override
ShardDataTreeCohort finishTransaction(final ReadWriteShardDataTreeTransaction transaction) {
    final DataTreeModification snapshot = transaction.getSnapshot();
    snapshot.ready();
    return createReadyCohort(transaction.getIdentifier(), snapshot);
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) PruningDataTreeModification(org.opendaylight.controller.cluster.datastore.utils.PruningDataTreeModification)

Example 22 with DataTreeModification

use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification in project controller by opendaylight.

the class ShardDataTree method applySnapshot.

private void applySnapshot(@Nonnull final ShardDataTreeSnapshot snapshot, final UnaryOperator<DataTreeModification> wrapper) throws DataValidationFailedException {
    final Stopwatch elapsed = Stopwatch.createStarted();
    if (anyPendingTransactions()) {
        LOG.warn("{}: applying state snapshot with pending transactions", logContext);
    }
    final Map<Class<? extends ShardDataTreeSnapshotMetadata<?>>, ShardDataTreeSnapshotMetadata<?>> snapshotMeta;
    if (snapshot instanceof MetadataShardDataTreeSnapshot) {
        snapshotMeta = ((MetadataShardDataTreeSnapshot) snapshot).getMetadata();
    } else {
        snapshotMeta = ImmutableMap.of();
    }
    for (ShardDataTreeMetadata<?> m : metadata) {
        final ShardDataTreeSnapshotMetadata<?> s = snapshotMeta.get(m.getSupportedType());
        if (s != null) {
            m.applySnapshot(s);
        } else {
            m.reset();
        }
    }
    final DataTreeModification mod = wrapper.apply(dataTree.takeSnapshot().newModification());
    // delete everything first
    mod.delete(YangInstanceIdentifier.EMPTY);
    final java.util.Optional<NormalizedNode<?, ?>> maybeNode = snapshot.getRootNode();
    if (maybeNode.isPresent()) {
        // Add everything from the remote node back
        mod.write(YangInstanceIdentifier.EMPTY, maybeNode.get());
    }
    mod.ready();
    final DataTreeModification unwrapped = unwrap(mod);
    dataTree.validate(unwrapped);
    DataTreeCandidateTip candidate = dataTree.prepare(unwrapped);
    dataTree.commit(candidate);
    notifyListeners(candidate);
    LOG.debug("{}: state snapshot applied in {}", logContext, elapsed);
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) PruningDataTreeModification(org.opendaylight.controller.cluster.datastore.utils.PruningDataTreeModification) MetadataShardDataTreeSnapshot(org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot) Stopwatch(com.google.common.base.Stopwatch) DataTreeCandidateTip(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) ShardDataTreeSnapshotMetadata(org.opendaylight.controller.cluster.datastore.persisted.ShardDataTreeSnapshotMetadata)

Example 23 with DataTreeModification

use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification in project controller by opendaylight.

the class ShardDataTree method processNextPendingTransaction.

@SuppressWarnings("checkstyle:IllegalCatch")
private void processNextPendingTransaction() {
    ++currentTransactionBatch;
    if (currentTransactionBatch > MAX_TRANSACTION_BATCH) {
        LOG.debug("{}: Already processed {}, scheduling continuation", logContext, currentTransactionBatch);
        shard.scheduleNextPendingTransaction();
        return;
    }
    processNextPending(pendingTransactions, State.CAN_COMMIT_PENDING, entry -> {
        final SimpleShardDataTreeCohort cohort = entry.cohort;
        final DataTreeModification modification = cohort.getDataTreeModification();
        LOG.debug("{}: Validating transaction {}", logContext, cohort.getIdentifier());
        Exception cause;
        try {
            tip.validate(modification);
            LOG.debug("{}: Transaction {} validated", logContext, cohort.getIdentifier());
            cohort.successfulCanCommit();
            entry.lastAccess = readTime();
            return;
        } catch (ConflictingModificationAppliedException e) {
            LOG.warn("{}: Store Tx {}: Conflicting modification for path {}.", logContext, cohort.getIdentifier(), e.getPath());
            cause = new OptimisticLockFailedException("Optimistic lock failed.", e);
        } catch (DataValidationFailedException e) {
            LOG.warn("{}: Store Tx {}: Data validation failed for path {}.", logContext, cohort.getIdentifier(), e.getPath(), e);
            // For debugging purposes, allow dumping of the modification. Coupled with the above
            // precondition log, it should allow us to understand what went on.
            LOG.debug("{}: Store Tx {}: modifications: {} tree: {}", cohort.getIdentifier(), modification, dataTree);
            cause = new TransactionCommitFailedException("Data did not pass validation.", e);
        } catch (Exception e) {
            LOG.warn("{}: Unexpected failure in validation phase", logContext, e);
            cause = e;
        }
        // Failure path: propagate the failure, remove the transaction from the queue and loop to the next one
        pendingTransactions.poll().cohort.failedCanCommit(cause);
    });
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) PruningDataTreeModification(org.opendaylight.controller.cluster.datastore.utils.PruningDataTreeModification) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) DataValidationFailedException(org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException) ConflictingModificationAppliedException(org.opendaylight.yangtools.yang.data.api.schema.tree.ConflictingModificationAppliedException) TimeoutException(java.util.concurrent.TimeoutException) ConflictingModificationAppliedException(org.opendaylight.yangtools.yang.data.api.schema.tree.ConflictingModificationAppliedException) IOException(java.io.IOException) DataValidationFailedException(org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) OptimisticLockFailedException(org.opendaylight.mdsal.common.api.OptimisticLockFailedException) OptimisticLockFailedException(org.opendaylight.mdsal.common.api.OptimisticLockFailedException)

Example 24 with DataTreeModification

use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification in project controller by opendaylight.

the class FrontendReadWriteTransaction method handleCommitLocalTransaction.

private void handleCommitLocalTransaction(final CommitLocalTransactionRequest request, final RequestEnvelope envelope, final long now) throws RequestException {
    final DataTreeModification sealedModification = checkSealed();
    if (!sealedModification.equals(request.getModification())) {
        LOG.warn("Expecting modification {}, commit request has {}", sealedModification, request.getModification());
        throw new UnsupportedRequestException(request);
    }
    final java.util.Optional<Exception> optFailure = request.getDelayedFailure();
    if (optFailure.isPresent()) {
        state = new Ready(history().createFailedCohort(getIdentifier(), sealedModification, optFailure.get()));
    } else {
        state = new Ready(history().createReadyCohort(getIdentifier(), sealedModification));
    }
    if (request.isCoordinated()) {
        coordinatedCommit(envelope, now);
    } else {
        directCommit(envelope, now);
    }
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) UnsupportedRequestException(org.opendaylight.controller.cluster.access.concepts.UnsupportedRequestException) RuntimeRequestException(org.opendaylight.controller.cluster.access.concepts.RuntimeRequestException) RequestException(org.opendaylight.controller.cluster.access.concepts.RequestException) UnsupportedRequestException(org.opendaylight.controller.cluster.access.concepts.UnsupportedRequestException)

Example 25 with DataTreeModification

use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification in project controller by opendaylight.

the class RemoteProxyTransaction method replayLocalCommitRequest.

private void replayLocalCommitRequest(final CommitLocalTransactionRequest request, final Consumer<Response<?, ?>> callback, final long enqueuedTicks) {
    final DataTreeModification mod = request.getModification();
    final Optional<Long> optTicks = Optional.of(Long.valueOf(enqueuedTicks));
    mod.applyToCursor(new AbstractDataTreeModificationCursor() {

        @Override
        public void write(final PathArgument child, final NormalizedNode<?, ?> data) {
            appendModification(new TransactionWrite(current().node(child), data), optTicks);
        }

        @Override
        public void merge(final PathArgument child, final NormalizedNode<?, ?> data) {
            appendModification(new TransactionMerge(current().node(child), data), optTicks);
        }

        @Override
        public void delete(final PathArgument child) {
            appendModification(new TransactionDelete(current().node(child)), optTicks);
        }
    });
    enqueueRequest(commitRequest(request.isCoordinated()), callback, enqueuedTicks);
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) AbstractDataTreeModificationCursor(org.opendaylight.controller.cluster.datastore.util.AbstractDataTreeModificationCursor) TransactionWrite(org.opendaylight.controller.cluster.access.commands.TransactionWrite) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) TransactionDelete(org.opendaylight.controller.cluster.access.commands.TransactionDelete) TransactionMerge(org.opendaylight.controller.cluster.access.commands.TransactionMerge)

Aggregations

DataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)45 Test (org.junit.Test)17 DataTree (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree)13 WriteModification (org.opendaylight.controller.cluster.datastore.modification.WriteModification)8 InMemoryDataTreeFactory (org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory)8 MergeModification (org.opendaylight.controller.cluster.datastore.modification.MergeModification)7 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)6 DataTreeCandidate (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate)6 DataTreeSnapshot (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot)6 ActorRef (akka.actor.ActorRef)5 PruningDataTreeModification (org.opendaylight.controller.cluster.datastore.utils.PruningDataTreeModification)5 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)5 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)5 BatchedModifications (org.opendaylight.controller.cluster.datastore.messages.BatchedModifications)4 ReadyLocalTransaction (org.opendaylight.controller.cluster.datastore.messages.ReadyLocalTransaction)4 MetadataShardDataTreeSnapshot (org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot)3 PathArgument (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)3 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)3 ActorSelection (akka.actor.ActorSelection)2 TestActorRef (akka.testkit.TestActorRef)2