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