use of org.opendaylight.controller.cluster.datastore.messages.BatchedModificationsReply in project controller by opendaylight.
the class ShardCommitCoordinator method handleBatchedModifications.
/**
* This method handles a BatchedModifications message for a transaction being prepared directly on the
* Shard actor instead of via a ShardTransaction actor. If there's no currently cached
* DOMStoreWriteTransaction, one is created. The batched modifications are applied to the write Tx. If
* the BatchedModifications is ready to commit then a DOMStoreThreePhaseCommitCohort is created.
*
* @param batched the BatchedModifications message to process
* @param sender the sender of the message
*/
void handleBatchedModifications(final BatchedModifications batched, final ActorRef sender, final Shard shard) {
CohortEntry cohortEntry = cohortCache.get(batched.getTransactionId());
if (cohortEntry == null) {
cohortEntry = CohortEntry.createOpen(dataTree.newReadWriteTransaction(batched.getTransactionId()), batched.getVersion());
cohortCache.put(cohortEntry.getTransactionId(), cohortEntry);
}
if (log.isDebugEnabled()) {
log.debug("{}: Applying {} batched modifications for Tx {}", name, batched.getModifications().size(), batched.getTransactionId());
}
cohortEntry.applyModifications(batched.getModifications());
if (batched.isReady()) {
if (cohortEntry.getLastBatchedModificationsException() != null) {
cohortCache.remove(cohortEntry.getTransactionId());
throw cohortEntry.getLastBatchedModificationsException();
}
if (cohortEntry.getTotalBatchedModificationsReceived() != batched.getTotalMessagesSent()) {
cohortCache.remove(cohortEntry.getTransactionId());
throw new IllegalStateException(String.format("The total number of batched messages received %d does not match the number sent %d", cohortEntry.getTotalBatchedModificationsReceived(), batched.getTotalMessagesSent()));
}
if (log.isDebugEnabled()) {
log.debug("{}: Readying Tx {}, client version {}", name, batched.getTransactionId(), batched.getVersion());
}
cohortEntry.setDoImmediateCommit(batched.isDoCommitOnReady());
cohortEntry.ready(cohortDecorator);
if (batched.isDoCommitOnReady()) {
cohortEntry.setReplySender(sender);
cohortEntry.setShard(shard);
handleCanCommit(cohortEntry);
} else {
sender.tell(readyTransactionReply(shard.self()), shard.self());
}
} else {
sender.tell(new BatchedModificationsReply(batched.getModifications().size()), shard.self());
}
}
use of org.opendaylight.controller.cluster.datastore.messages.BatchedModificationsReply in project controller by opendaylight.
the class ShardTransactionTest method testOnReceiveBatchedModifications.
@Test
public void testOnReceiveBatchedModifications() throws Exception {
new TestKit(getSystem()) {
{
ShardDataTreeTransactionParent parent = Mockito.mock(ShardDataTreeTransactionParent.class);
DataTreeModification mockModification = Mockito.mock(DataTreeModification.class);
ReadWriteShardDataTreeTransaction mockWriteTx = new ReadWriteShardDataTreeTransaction(parent, nextTransactionId(), mockModification);
final ActorRef transaction = newTransactionActor(RW, mockWriteTx, "testOnReceiveBatchedModifications");
YangInstanceIdentifier writePath = TestModel.TEST_PATH;
NormalizedNode<?, ?> writeData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();
YangInstanceIdentifier mergePath = TestModel.OUTER_LIST_PATH;
NormalizedNode<?, ?> mergeData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.OUTER_LIST_QNAME)).build();
YangInstanceIdentifier deletePath = TestModel.TEST_PATH;
BatchedModifications batched = new BatchedModifications(nextTransactionId(), DataStoreVersions.CURRENT_VERSION);
batched.addModification(new WriteModification(writePath, writeData));
batched.addModification(new MergeModification(mergePath, mergeData));
batched.addModification(new DeleteModification(deletePath));
transaction.tell(batched, getRef());
BatchedModificationsReply reply = expectMsgClass(duration("5 seconds"), BatchedModificationsReply.class);
assertEquals("getNumBatched", 3, reply.getNumBatched());
InOrder inOrder = Mockito.inOrder(mockModification);
inOrder.verify(mockModification).write(writePath, writeData);
inOrder.verify(mockModification).merge(mergePath, mergeData);
inOrder.verify(mockModification).delete(deletePath);
}
};
}
use of org.opendaylight.controller.cluster.datastore.messages.BatchedModificationsReply in project controller by opendaylight.
the class ShardTransactionTest method testOnReceiveBatchedModificationsReadyWithoutImmediateCommit.
@Test
public void testOnReceiveBatchedModificationsReadyWithoutImmediateCommit() throws Exception {
new TestKit(getSystem()) {
{
final ActorRef transaction = newTransactionActor(WO, readWriteTransaction(), "testOnReceiveBatchedModificationsReadyWithoutImmediateCommit");
TestKit watcher = new TestKit(getSystem());
watcher.watch(transaction);
YangInstanceIdentifier writePath = TestModel.TEST_PATH;
NormalizedNode<?, ?> writeData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();
final TransactionIdentifier tx1 = nextTransactionId();
BatchedModifications batched = new BatchedModifications(tx1, DataStoreVersions.CURRENT_VERSION);
batched.addModification(new WriteModification(writePath, writeData));
transaction.tell(batched, getRef());
BatchedModificationsReply reply = expectMsgClass(duration("5 seconds"), BatchedModificationsReply.class);
assertEquals("getNumBatched", 1, reply.getNumBatched());
batched = new BatchedModifications(tx1, DataStoreVersions.CURRENT_VERSION);
batched.setReady(true);
batched.setTotalMessagesSent(2);
transaction.tell(batched, getRef());
expectMsgClass(duration("5 seconds"), ReadyTransactionReply.class);
watcher.expectMsgClass(duration("5 seconds"), Terminated.class);
}
};
}
Aggregations