X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FShardSnapshotCohort.java;h=c4ac727cb3b59fa3efa77b2ef3ccf7427c2a81a7;hp=c59085d61c57961feb915077e996262b92e2ce17;hb=daaef05cbf70e6cbec9af181258faead6d9620a6;hpb=9f1061c46af5220ad95d8d0b94411ba2fd832a50 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardSnapshotCohort.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardSnapshotCohort.java index c59085d61c..c4ac727cb3 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardSnapshotCohort.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardSnapshotCohort.java @@ -7,15 +7,13 @@ */ package org.opendaylight.controller.cluster.datastore; +import com.google.common.base.Preconditions; import akka.actor.ActorRef; import java.util.concurrent.ExecutionException; import org.opendaylight.controller.cluster.datastore.identifiers.ShardTransactionIdentifier; import org.opendaylight.controller.cluster.datastore.messages.CreateSnapshot; import org.opendaylight.controller.cluster.datastore.utils.SerializationUtils; import org.opendaylight.controller.cluster.raft.RaftActorSnapshotCohort; -import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore; -import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort; -import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.slf4j.Logger; @@ -31,14 +29,14 @@ class ShardSnapshotCohort implements RaftActorSnapshotCohort { private int createSnapshotTransactionCounter; private final ShardTransactionActorFactory transactionActorFactory; - private final InMemoryDOMDataStore store; + private final ShardDataTree store; private final Logger log; private final String logId; - ShardSnapshotCohort(ShardTransactionActorFactory transactionActorFactory, InMemoryDOMDataStore store, + ShardSnapshotCohort(ShardTransactionActorFactory transactionActorFactory, ShardDataTree store, Logger log, String logId) { this.transactionActorFactory = transactionActorFactory; - this.store = store; + this.store = Preconditions.checkNotNull(store); this.log = log; this.logId = logId; } @@ -53,7 +51,7 @@ class ShardSnapshotCohort implements RaftActorSnapshotCohort { "createSnapshot" + ++createSnapshotTransactionCounter); ActorRef createSnapshotTransaction = transactionActorFactory.newShardTransaction( - TransactionProxy.TransactionType.READ_ONLY, transactionID, "", DataStoreVersions.CURRENT_VERSION); + TransactionType.READ_ONLY, transactionID, "", DataStoreVersions.CURRENT_VERSION); createSnapshotTransaction.tell(CreateSnapshot.INSTANCE, actorRef); } @@ -67,15 +65,15 @@ class ShardSnapshotCohort implements RaftActorSnapshotCohort { log.info("{}: Applying snapshot", logId); try { - DOMStoreWriteTransaction transaction = store.newWriteOnlyTransaction(); + ReadWriteShardDataTreeTransaction transaction = store.newReadWriteTransaction("snapshot-" + logId, null); NormalizedNode node = SerializationUtils.deserializeNormalizedNode(snapshotBytes); // delete everything first - transaction.delete(DATASTORE_ROOT); + transaction.getSnapshot().delete(DATASTORE_ROOT); // Add everything from the remote node back - transaction.write(DATASTORE_ROOT, node); + transaction.getSnapshot().write(DATASTORE_ROOT, node); syncCommitTransaction(transaction); } catch (InterruptedException | ExecutionException e) { log.error("{}: An exception occurred when applying snapshot", logId, e); @@ -85,9 +83,9 @@ class ShardSnapshotCohort implements RaftActorSnapshotCohort { } - void syncCommitTransaction(final DOMStoreWriteTransaction transaction) + void syncCommitTransaction(final ReadWriteShardDataTreeTransaction transaction) throws ExecutionException, InterruptedException { - DOMStoreThreePhaseCommitCohort commitCohort = transaction.ready(); + ShardDataTreeCohort commitCohort = store.finishTransaction(transaction); commitCohort.preCommit().get(); commitCohort.commit().get(); }