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);
}
});
}
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);
}
Aggregations