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=e49aa1e4f37d484d25439fd009affdeeba3a3cd8;hp=c59085d61c57961feb915077e996262b92e2ce17;hb=8ec73bf853a9b6708b455c0321a585992e02b125;hpb=c31a6fcf9fb070d4419ca4c32d8b531fdcb5030d 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..e49aa1e4f3 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 @@ -8,14 +8,12 @@ package org.opendaylight.controller.cluster.datastore; import akka.actor.ActorRef; +import com.google.common.base.Preconditions; 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; @@ -26,19 +24,17 @@ import org.slf4j.Logger; * @author Thomas Pantelis */ class ShardSnapshotCohort implements RaftActorSnapshotCohort { - - private static final YangInstanceIdentifier DATASTORE_ROOT = YangInstanceIdentifier.builder().build(); - - private int createSnapshotTransactionCounter; private final ShardTransactionActorFactory transactionActorFactory; - private final InMemoryDOMDataStore store; - private final Logger log; + private final ShardDataTree store; private final String logId; + private final Logger log; + + private int createSnapshotTransactionCounter; - 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 +49,7 @@ class ShardSnapshotCohort implements RaftActorSnapshotCohort { "createSnapshot" + ++createSnapshotTransactionCounter); ActorRef createSnapshotTransaction = transactionActorFactory.newShardTransaction( - TransactionProxy.TransactionType.READ_ONLY, transactionID, "", DataStoreVersions.CURRENT_VERSION); + TransactionType.READ_ONLY, transactionID, ""); createSnapshotTransaction.tell(CreateSnapshot.INSTANCE, actorRef); } @@ -67,15 +63,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(YangInstanceIdentifier.EMPTY); // Add everything from the remote node back - transaction.write(DATASTORE_ROOT, node); + transaction.getSnapshot().write(YangInstanceIdentifier.EMPTY, node); syncCommitTransaction(transaction); } catch (InterruptedException | ExecutionException e) { log.error("{}: An exception occurred when applying snapshot", logId, e); @@ -85,9 +81,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(); }