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); }
void updateSchemaContext(final SchemaContext schemaContext) { dataTree.setSchemaContext(schemaContext); this.schemaContext = Preconditions.checkNotNull(schemaContext); }
/** * @deprecated This method violates DataTree containment and will be removed. */ @VisibleForTesting @Deprecated public DataTreeCandidate commit(final DataTreeModification modification) throws DataValidationFailedException { modification.ready(); dataTree.validate(modification); DataTreeCandidate candidate = dataTree.prepare(modification); dataTree.commit(candidate); return candidate; }
public DataTreeSnapshot takeSnapshot() { return dataTree.takeSnapshot(); }
private void finishCommit(final SimpleShardDataTreeCohort cohort) { final TransactionIdentifier txId = cohort.getIdentifier(); final DataTreeCandidate candidate = cohort.getCandidate(); LOG.debug("{}: Resuming commit of transaction {}", logContext, txId); try { dataTree.commit(candidate); } catch (Exception e) { LOG.error("{}: Failed to commit transaction {}", logContext, txId, e); failCommit(e); return; } shard.getShardMBean().incrementCommittedTransactionCount(); shard.getShardMBean().setLastCommittedTransactionTime(System.currentTimeMillis()); // FIXME: propagate journal index pendingTransactions.poll().cohort.successfulCommit(UnsignedLong.ZERO); LOG.trace("{}: Transaction {} committed, proceeding to notify", logContext, txId); notifyListeners(candidate); processNextTransaction(); }
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); final DataTreeCandidateTip candidate; try { candidate = dataTree.prepare(cohort.getDataTreeModification()); } catch (Exception e) { failPreCommit(e); return; } try { cohort.userPreCommit(candidate); } catch (ExecutionException | TimeoutException e) { failPreCommit(e); return; } entry.lastAccess = shard.ticker().read(); cohort.successfulPreCommit(candidate); }
Exception cause; try { dataTree.validate(modification); LOG.debug("{}: Transaction {} validated", logContext, cohort.getIdentifier()); cohort.successfulCanCommit();
public Optional<NormalizedNode<?, ?>> readNode(final YangInstanceIdentifier path) { return dataTree.takeSnapshot().readNode(path); }
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); } }
public DataTreeModification newModification() { return dataTree.takeSnapshot().newModification(); }
final DataTreeModification mod = wrapper.apply(dataTree.takeSnapshot().newModification()); dataTree.validate(unwrapped); DataTreeCandidateTip candidate = dataTree.prepare(unwrapped); dataTree.commit(candidate); notifyListeners(candidate);
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(); }
/** * 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()); }
ReadOnlyShardDataTreeTransaction newReadOnlyTransaction(final TransactionIdentifier txId) { if (txId.getHistoryId().getHistoryId() == 0) { return new ReadOnlyShardDataTreeTransaction(txId, dataTree.takeSnapshot()); } return ensureTransactionChain(txId.getHistoryId()).newReadOnlyTransaction(txId); }
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); }