use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification in project controller by opendaylight.
the class SnapshotBackedWriteTransaction method ready.
@Override
@SuppressWarnings("checkstyle:IllegalCatch")
public DOMStoreThreePhaseCommitCohort ready() {
@SuppressWarnings("unchecked") final TransactionReadyPrototype<T> wasReady = READY_UPDATER.getAndSet(this, null);
checkState(wasReady != null, "Transaction %s is no longer open", getIdentifier());
LOG.debug("Store transaction: {} : Ready", getIdentifier());
final DataTreeModification tree = mutableTree;
TREE_UPDATER.lazySet(this, null);
try {
tree.ready();
return wasReady.transactionReady(this, tree, null);
} catch (RuntimeException e) {
LOG.debug("Store transaction: {}: unexpected failure when readying", getIdentifier(), e);
return wasReady.transactionReady(this, tree, e);
}
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification in project controller by opendaylight.
the class ShardDataTreeTest method applyCandidates.
private static DataTreeCandidate applyCandidates(final ShardDataTree shardDataTree, final List<DataTreeCandidate> candidates) throws ExecutionException, InterruptedException {
final ReadWriteShardDataTreeTransaction transaction = shardDataTree.newReadWriteTransaction(nextTransactionId());
final DataTreeModification snapshot = transaction.getSnapshot();
for (final DataTreeCandidate candidateTip : candidates) {
DataTreeCandidates.applyToModification(snapshot, candidateTip);
}
final ShardDataTreeCohort cohort = shardDataTree.finishTransaction(transaction);
immediateCanCommit(cohort);
immediatePreCommit(cohort);
final DataTreeCandidate candidate = cohort.getCandidate();
immediateCommit(cohort);
return candidate;
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification in project controller by opendaylight.
the class ShardDataTreeTest method doTransaction.
private static DataTreeCandidate doTransaction(final ShardDataTree shardDataTree, final DataTreeOperation operation) throws ExecutionException, InterruptedException {
final ReadWriteShardDataTreeTransaction transaction = shardDataTree.newReadWriteTransaction(nextTransactionId());
final DataTreeModification snapshot = transaction.getSnapshot();
operation.execute(snapshot);
final ShardDataTreeCohort cohort = shardDataTree.finishTransaction(transaction);
immediateCanCommit(cohort);
immediatePreCommit(cohort);
final DataTreeCandidate candidate = cohort.getCandidate();
immediateCommit(cohort);
return candidate;
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification in project controller by opendaylight.
the class ShardRecoveryCoordinatorTest method createCar.
private DataTreeCandidate createCar() {
final DataTree dataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, carsSchemaContext);
final DataTreeSnapshot snapshot = dataTree.takeSnapshot();
final DataTreeModification modification = snapshot.newModification();
modification.merge(CarsModel.BASE_PATH, CarsModel.create());
modification.ready();
return dataTree.prepare(modification);
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification in project controller by opendaylight.
the class ShardTest method testTransactionCommitWithSubsequentExpiredCohortEntry.
@Test
public void testTransactionCommitWithSubsequentExpiredCohortEntry() throws Exception {
dataStoreContextBuilder.shardTransactionCommitTimeoutInSeconds(1);
new ShardTestKit(getSystem()) {
{
final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testTransactionCommitWithSubsequentExpiredCohortEntry");
waitUntilLeader(shard);
final FiniteDuration duration = duration("5 seconds");
final ShardDataTree dataStore = shard.underlyingActor().getDataStore();
final TransactionIdentifier transactionID1 = nextTransactionId();
shard.tell(prepareBatchedModifications(transactionID1, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME), false), getRef());
expectMsgClass(duration, ReadyTransactionReply.class);
// CanCommit the first Tx so it's the current in-progress Tx.
shard.tell(new CanCommitTransaction(transactionID1, CURRENT_VERSION).toSerializable(), getRef());
expectMsgClass(duration, CanCommitTransactionReply.class);
// Ready the second Tx.
final TransactionIdentifier transactionID2 = nextTransactionId();
shard.tell(prepareBatchedModifications(transactionID2, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME), false), getRef());
expectMsgClass(duration, ReadyTransactionReply.class);
// Ready the third Tx.
final TransactionIdentifier transactionID3 = nextTransactionId();
final DataTreeModification modification3 = dataStore.newModification();
new WriteModification(TestModel.TEST2_PATH, ImmutableNodes.containerNode(TestModel.TEST2_QNAME)).apply(modification3);
modification3.ready();
final ReadyLocalTransaction readyMessage = new ReadyLocalTransaction(transactionID3, modification3, true);
shard.tell(readyMessage, getRef());
// Commit the first Tx. After completing, the second should
// expire from the queue and the third
// Tx committed.
shard.tell(new CommitTransaction(transactionID1, CURRENT_VERSION).toSerializable(), getRef());
expectMsgClass(duration, CommitTransactionReply.class);
// Expect commit reply from the third Tx.
expectMsgClass(duration, CommitTransactionReply.class);
final NormalizedNode<?, ?> node = readStore(shard, TestModel.TEST2_PATH);
assertNotNull(TestModel.TEST2_PATH + " not found", node);
}
};
}
Aggregations