Search in sources :

Example 6 with DataTreeCandidateTip

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

the class ShardDataTree method startPreCommit.

@SuppressWarnings("checkstyle:IllegalCatch")
void startPreCommit(final SimpleShardDataTreeCohort cohort) {
    final CommitEntry entry = pendingTransactions.peek();
    Preconditions.checkState(entry != null, "Attempted to pre-commit of %s when no transactions pending", cohort);
    final SimpleShardDataTreeCohort current = entry.cohort;
    Verify.verify(cohort.equals(current), "Attempted to pre-commit %s while %s is pending", cohort, current);
    LOG.debug("{}: Preparing transaction {}", logContext, current.getIdentifier());
    final DataTreeCandidateTip candidate;
    try {
        candidate = tip.prepare(cohort.getDataTreeModification());
    } catch (RuntimeException e) {
        failPreCommit(e);
        return;
    }
    cohort.userPreCommit(candidate, new FutureCallback<Void>() {

        @Override
        public void onSuccess(final Void noop) {
            // Set the tip of the data tree.
            tip = Verify.verifyNotNull(candidate);
            entry.lastAccess = readTime();
            pendingTransactions.remove();
            pendingCommits.add(entry);
            LOG.debug("{}: Transaction {} prepared", logContext, current.getIdentifier());
            cohort.successfulPreCommit(candidate);
            processNextPendingTransaction();
        }

        @Override
        public void onFailure(final Throwable failure) {
            failPreCommit(failure);
        }
    });
}
Also used : DataTreeCandidateTip(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip)

Example 7 with DataTreeCandidateTip

use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip 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)

Aggregations

DataTreeCandidateTip (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip)7 UnsignedLong (com.google.common.primitives.UnsignedLong)2 Test (org.junit.Test)2 DataTreeCandidateNode (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode)2 Stopwatch (com.google.common.base.Stopwatch)1 MetadataShardDataTreeSnapshot (org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot)1 ShardDataTreeSnapshotMetadata (org.opendaylight.controller.cluster.datastore.persisted.ShardDataTreeSnapshotMetadata)1 PruningDataTreeModification (org.opendaylight.controller.cluster.datastore.utils.PruningDataTreeModification)1 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)1 ConflictingModificationAppliedException (org.opendaylight.yangtools.yang.data.api.schema.tree.ConflictingModificationAppliedException)1 DataTreeCandidate (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate)1 DataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)1 DataValidationFailedException (org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException)1