SnapshotBackedWriteTransaction(final T identifier, final boolean debug, final DataTreeSnapshot snapshot, final TransactionReadyPrototype<T> readyImpl) { super(identifier, debug); this.readyImpl = Preconditions.checkNotNull(readyImpl, "readyImpl must not be null."); mutableTree = snapshot.newModification(); LOG.debug("Write Tx: {} allocated with snapshot {}", identifier, snapshot); }
LocalProxyTransaction(final DistributedDataStoreClientBehavior client, final TransactionIdentifier identifier, final DataTreeSnapshot snapshot) { super(client); this.identifier = Preconditions.checkNotNull(identifier); this.modification = snapshot.newModification(); }
SnapshotBackedWriteTransaction(final T identifier, final boolean debug, final DataTreeSnapshot snapshot, final TransactionReadyPrototype<T> readyImpl) { super(identifier, debug); this.readyImpl = Preconditions.checkNotNull(readyImpl, "readyImpl must not be null."); mutableTree = snapshot.newModification(); LOG.debug("Write Tx: {} allocated with snapshot {}", identifier, snapshot); }
SnapshotBackedWriteTransaction(final T identifier, final boolean debug, final DataTreeSnapshot snapshot, final TransactionReadyPrototype<T> readyImpl) { super(identifier, debug); this.readyImpl = requireNonNull(readyImpl, "readyImpl must not be null."); mutableTree = snapshot.newModification(); LOG.debug("Write Tx: {} allocated with snapshot {}", identifier, snapshot); }
ConfigSnapshot() { this.snapshot = dataTree.takeSnapshot(); this.modification = snapshot.newModification(); }
public DataTreeModification newModification() { return dataTree.takeSnapshot().newModification(); }
private CursorAwareDataTreeModification begin() { return (CursorAwareDataTreeModification) datastore.takeSnapshot().newModification(); }
ReadWriteShardDataTreeTransaction newReadWriteTransaction(final TransactionIdentifier txId) { final DataTreeSnapshot snapshot = getSnapshot(); LOG.debug("Allocated read-write transaction {} snapshot {}", txId, snapshot); openTransaction = new ReadWriteShardDataTreeTransaction(this, txId, snapshot.newModification()); return openTransaction; }
private NormalizedNodeAggregator combine() throws DataValidationFailedException { final DataTreeModification mod = dataTree.takeSnapshot().newModification(); for (final Optional<NormalizedNode<?,?>> node : nodes) { if (node.isPresent()) { mod.merge(rootIdentifier, node.get()); } } mod.ready(); dataTree.validate(mod); final DataTreeCandidate candidate = dataTree.prepare(mod); dataTree.commit(candidate); return this; }
@Override public final void validate() throws ValidationFailedException { // Modification requires to be sealed before validation. // Sealed modification cannot be altered, so create copy. final CursorAwareDataTreeModification modificationCopy = (CursorAwareDataTreeModification) snapshot.newModification(); final DataTreeModificationCursor cursor = modificationCopy.createCursor(dataTree.getRootPath()); checkState(cursor != null, "DataTreeModificationCursor for root path should not be null"); modification.applyToCursor(cursor); // Then validate it. validateCandidate(prepareCandidateContext(modificationCopy)); }
private void applyRecoveryCandidate(final DataTreeCandidate candidate) throws DataValidationFailedException { final PruningDataTreeModification mod = wrapWithPruning(dataTree.takeSnapshot().newModification()); DataTreeCandidates.applyToModification(mod, candidate); mod.ready(); final DataTreeModification unwrapped = mod.delegate(); LOG.trace("{}: Applying recovery modification {}", logContext, unwrapped); try { dataTree.validate(unwrapped); dataTree.commit(dataTree.prepare(unwrapped)); } catch (Exception e) { File file = new File(System.getProperty("karaf.data", "."), "failed-recovery-payload-" + logContext + ".out"); DataTreeModificationOutput.toFile(file, unwrapped); throw new IllegalStateException(String.format( "%s: Failed to apply recovery payload. Modification data was written to file %s", logContext, file), e); } }
private void applyReplicatedCandidate(final Identifier identifier, final DataTreeCandidate foreign) throws DataValidationFailedException { LOG.debug("{}: Applying foreign transaction {}", logContext, identifier); final DataTreeModification mod = dataTree.takeSnapshot().newModification(); DataTreeCandidates.applyToModification(mod, foreign); mod.ready(); LOG.trace("{}: Applying foreign modification {}", logContext, mod); dataTree.validate(mod); final DataTreeCandidate candidate = dataTree.prepare(mod); dataTree.commit(candidate); notifyListeners(candidate); }
@Override public void ready() { try { delegate.ready(); } catch (SchemaValidationFailedException e) { DataTreeModification newModification = dataTree.takeSnapshot().newModification(); delegate.applyToCursor(new PruningDataTreeModificationCursor(newModification, this)); delegate = newModification; delegate.ready(); } }
final DataTreeModification mod = wrapper.apply(dataTree.takeSnapshot().newModification());
ReadWriteShardDataTreeTransaction newReadWriteTransaction(final TransactionIdentifier txId) { if (txId.getHistoryId().getHistoryId() == 0) { return new ReadWriteShardDataTreeTransaction(ShardDataTree.this, txId, dataTree.takeSnapshot() .newModification()); } return ensureTransactionChain(txId.getHistoryId()).newReadWriteTransaction(txId); }
@Override public DataTree create(final DataTreeConfiguration treeConfig, final SchemaContext initialSchemaContext, final NormalizedNodeContainer<?, ?, ?> initialRoot) throws DataValidationFailedException { final DataTree ret = create(treeConfig, initialSchemaContext, false); final DataTreeModification mod = ret.takeSnapshot().newModification(); mod.write(YangInstanceIdentifier.EMPTY, initialRoot); mod.ready(); ret.validate(mod); final DataTreeCandidate candidate = ret.prepare(mod); ret.commit(candidate); return ret; }
@Override public DataTree create(final DataTreeConfiguration treeConfig, final SchemaContext initialSchemaContext, final NormalizedNodeContainer<?, ?, ?> initialRoot) throws DataValidationFailedException { final DataTree ret = create(treeConfig, initialSchemaContext, false); final DataTreeModification mod = ret.takeSnapshot().newModification(); mod.write(YangInstanceIdentifier.EMPTY, initialRoot); mod.ready(); ret.validate(mod); final DataTreeCandidate candidate = ret.prepare(mod); ret.commit(candidate); return ret; }
private DataTreeCandidate applyChanges(final Collection<DataTreeCandidate> changes) { final DataTreeModification modification = dataTree.takeSnapshot().newModification(); for (final DataTreeCandidate change : changes) { DataTreeCandidates.applyToModification(modification, change); } modification.ready(); try { dataTree.validate(modification); } catch (final DataValidationFailedException e) { LOG.error("Validation failed for built modification", e); throw new RuntimeException("Notification validation failed", e); } // strip nodes we do not need since this listener doesn't have to be registered at the root of the DataTree DataTreeCandidateNode modifiedChild = dataTree.prepare(modification).getRootNode(); for (final PathArgument pathArgument : listenerPath.getPathArguments()) { modifiedChild = modifiedChild.getModifiedChild(pathArgument); } if (modifiedChild == null) { modifiedChild = DataTreeCandidateNodes.empty(listenerPath.getLastPathArgument()); } return DataTreeCandidates.newDataTreeCandidate(listenerPath, modifiedChild); } }