LocalProxyTransaction(final DistributedDataStoreClientBehavior client, final TransactionIdentifier identifier, final DataTreeSnapshot snapshot) { super(client); this.identifier = Preconditions.checkNotNull(identifier); this.modification = snapshot.newModification(); }
private Optional<NormalizedNode<?, ?>> getRootNode() { return dataTree.takeSnapshot().readNode(rootIdentifier); } }
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); }
public Optional<NormalizedNode<?, ?>> readNode(final YangInstanceIdentifier path) { return dataTree.takeSnapshot().readNode(path); }
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); }
private Optional<DataTreeCandidate> readCurrentData() { final Optional<NormalizedNode<?, ?>> currentState = dataTree.takeSnapshot().readNode(YangInstanceIdentifier.EMPTY); return currentState.isPresent() ? Optional.of(DataTreeCandidates.fromNormalizedNode( YangInstanceIdentifier.EMPTY, currentState.get())) : Optional.<DataTreeCandidate>absent(); }
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); }
<L extends DOMDataTreeChangeListener> ListenerRegistration<L> registerTreeChangeListener(final YangInstanceIdentifier treeId, final L listener, final DataTreeSnapshot snapshot) { final AbstractDOMDataTreeChangeListenerRegistration<L> reg = registerTreeChangeListener(treeId, listener); final Optional<NormalizedNode<?, ?>> node = snapshot.readNode(treeId); if (node.isPresent()) { final DataTreeCandidate candidate = DataTreeCandidates.fromNormalizedNode(treeId, node.get()); notificationManager.submitNotification(reg, candidate); } return reg; }
ConfigSnapshot() { this.snapshot = dataTree.takeSnapshot(); this.modification = snapshot.newModification(); }
@Override public void commit(final DataTreeCandidate dataTreeCandidate) { LOG.trace("Commit detected"); delegateDependency.commit(dataTreeCandidate); LOG.debug("Delegate commit successful. Persisting data"); // TODO(HONEYCOMB-163): doing full read and full write might not be the fastest way of persisting data here final DataTreeSnapshot dataTreeSnapshot = delegateDependency.takeSnapshot(); // TODO this can be handled in background by a dedicated thread + a limited blocking queue // TODO enable configurable granularity for persists. Maybe doing write on every modification is too much // and we could do bulk persist persister.persistCurrentData(dataTreeSnapshot.readNode(YangInstanceIdentifier.EMPTY)); }
private CursorAwareDataTreeModification begin() { return (CursorAwareDataTreeModification) datastore.takeSnapshot().newModification(); }
/** * Take a snapshot of current state for later recovery. * * @return A state snapshot */ @Nonnull ShardDataTreeSnapshot takeStateSnapshot() { final NormalizedNode<?, ?> rootNode = dataTree.takeSnapshot().readNode(YangInstanceIdentifier.EMPTY).get(); final Builder<Class<? extends ShardDataTreeSnapshotMetadata<?>>, ShardDataTreeSnapshotMetadata<?>> metaBuilder = ImmutableMap.builder(); for (ShardDataTreeMetadata<?> m : metadata) { final ShardDataTreeSnapshotMetadata<?> meta = m.toSnapshot(); if (meta != null) { metaBuilder.put(meta.getType(), meta); } } return new MetadataShardDataTreeSnapshot(rootNode, metaBuilder.build()); }
public DataTreeModification newModification() { return dataTree.takeSnapshot().newModification(); }
<L extends DOMDataTreeChangeListener> ListenerRegistration<L> registerTreeChangeListener( final YangInstanceIdentifier treeId, final L listener, final DataTreeSnapshot snapshot) { final AbstractDOMDataTreeChangeListenerRegistration<L> reg = registerTreeChangeListener(treeId, listener); final Optional<NormalizedNode<?, ?>> node = snapshot.readNode(YangInstanceIdentifier.EMPTY); if (node.isPresent()) { final DataTreeCandidate candidate = DataTreeCandidates.fromNormalizedNode( YangInstanceIdentifier.EMPTY, node.get()); InMemoryDOMStoreTreeChangePublisher publisher = new InMemoryDOMStoreTreeChangePublisher(notificationManager); publisher.registerTreeChangeListener(treeId, listener); publisher.publishChange(candidate); } return reg; }
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; }
@Override public Optional<EntityOwnershipState> getOwnershipState(final DOMEntity forEntity) { Preconditions.checkNotNull(forEntity, "forEntity cannot be null"); DataTree dataTree = getLocalEntityOwnershipShardDataTree(); if (dataTree == null) { return Optional.absent(); } Optional<NormalizedNode<?, ?>> entityNode = dataTree.takeSnapshot().readNode( entityPath(forEntity.getType(), forEntity.getIdentifier())); if (!entityNode.isPresent()) { return Optional.absent(); } // Check if there are any candidates, if there are none we do not really have ownership state final MapEntryNode entity = (MapEntryNode) entityNode.get(); final Optional<DataContainerChild<? extends PathArgument, ?>> optionalCandidates = entity.getChild(CANDIDATE_NODE_ID); final boolean hasCandidates = optionalCandidates.isPresent() && ((MapNode) optionalCandidates.get()).getValue().size() > 0; if(!hasCandidates){ return Optional.absent(); } MemberName localMemberName = context.getCurrentMemberName(); Optional<DataContainerChild<? extends PathArgument, ?>> ownerLeaf = entity.getChild(ENTITY_OWNER_NODE_ID); String owner = ownerLeaf.isPresent() ? ownerLeaf.get().getValue().toString() : null; boolean hasOwner = !Strings.isNullOrEmpty(owner); boolean isOwner = hasOwner && localMemberName.getName().equals(owner); return Optional.of(EntityOwnershipState.from(isOwner, hasOwner)); }
@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)); }
@Override public CheckedFuture<Optional<NormalizedNode<?,?>>, ReadFailedException> read(final YangInstanceIdentifier path) { LOG.debug("Tx: {} Read: {}", getIdentifier(), path); checkNotNull(path, "Path must not be null."); final DataTreeSnapshot snapshot = stableSnapshot; if (snapshot == null) { return Futures.immediateFailedCheckedFuture(new ReadFailedException("Transaction is closed")); } try { return Futures.immediateCheckedFuture(snapshot.readNode(path)); } catch (Exception e) { LOG.error("Tx: {} Failed Read of {}", getIdentifier(), path, e); return Futures.immediateFailedCheckedFuture(new ReadFailedException("Read failed",e)); } }
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; }
@SuppressWarnings("checkstyle:IllegalCatch") @Override public FluentFuture<Optional<NormalizedNode<?,?>>> read(final YangInstanceIdentifier path) { LOG.debug("Tx: {} Read: {}", getIdentifier(), path); requireNonNull(path, "Path must not be null."); final DataTreeSnapshot snapshot = stableSnapshot; if (snapshot == null) { return FluentFutures.immediateFailedFluentFuture(new ReadFailedException("Transaction is closed")); } try { return FluentFutures.immediateFluentFuture(snapshot.readNode(path)); } catch (Exception e) { LOG.error("Tx: {} Failed Read of {}", getIdentifier(), path, e); return FluentFutures.immediateFailedFluentFuture(new ReadFailedException("Read failed", e)); } }