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=adf60a0c21441a2bd0e0fde37c2416d1d28c81b0;hp=8bef15bbbaea1b663ca376359f602e7839b9a562;hb=6276a65120a674b545ea787a5e1d9311bcdbf2af;hpb=b0067e0a4bfa955f15c6259e019f954687264eff 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 8bef15bbba..adf60a0c21 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 @@ -11,18 +11,14 @@ import akka.actor.ActorContext; import akka.actor.ActorRef; import com.google.common.base.Preconditions; import java.io.IOException; -import java.util.Optional; import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier; import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier; import org.opendaylight.controller.cluster.access.concepts.FrontendType; import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier; import org.opendaylight.controller.cluster.access.concepts.MemberName; -import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; import org.opendaylight.controller.cluster.datastore.actors.ShardSnapshotActor; import org.opendaylight.controller.cluster.datastore.persisted.ShardDataTreeSnapshot; import org.opendaylight.controller.cluster.raft.RaftActorSnapshotCohort; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.slf4j.Logger; /** @@ -33,17 +29,13 @@ import org.slf4j.Logger; class ShardSnapshotCohort implements RaftActorSnapshotCohort { private static final FrontendType SNAPSHOT_APPLY = FrontendType.forName("snapshot-apply"); - private final LocalHistoryIdentifier applyHistoryId; private final ActorRef snapshotActor; private final ShardDataTree store; private final String logId; private final Logger log; - private long applyCounter; - private ShardSnapshotCohort(final LocalHistoryIdentifier applyHistoryId, final ActorRef snapshotActor, final ShardDataTree store, final Logger log, final String logId) { - this.applyHistoryId = Preconditions.checkNotNull(applyHistoryId); this.snapshotActor = Preconditions.checkNotNull(snapshotActor); this.store = Preconditions.checkNotNull(store); this.log = log; @@ -66,10 +58,17 @@ class ShardSnapshotCohort implements RaftActorSnapshotCohort { @Override public void createSnapshot(final ActorRef actorRef) { // Forward the request to the snapshot actor - ShardSnapshotActor.requestSnapshot(snapshotActor, store.takeRecoverySnapshot(), actorRef); + ShardSnapshotActor.requestSnapshot(snapshotActor, store.takeStateSnapshot(), actorRef); } - private void deserializeAndApplySnapshot(final byte[] snapshotBytes) { + @Override + public void applySnapshot(final byte[] snapshotBytes) { + // Since this will be done only on Recovery or when this actor is a Follower + // we can safely commit everything in here. We not need to worry about event notifications + // as they would have already been disabled on the follower + + log.info("{}: Applying snapshot", logId); + final ShardDataTreeSnapshot snapshot; try { snapshot = ShardDataTreeSnapshot.deserialize(snapshotBytes); @@ -79,33 +78,12 @@ class ShardSnapshotCohort implements RaftActorSnapshotCohort { } try { - final ReadWriteShardDataTreeTransaction transaction = store.newReadWriteTransaction( - new TransactionIdentifier(applyHistoryId, applyCounter++)); - - // delete everything first - transaction.getSnapshot().delete(YangInstanceIdentifier.EMPTY); - - final Optional> maybeNode = snapshot.getRootNode(); - if (maybeNode.isPresent()) { - // Add everything from the remote node back - transaction.getSnapshot().write(YangInstanceIdentifier.EMPTY, maybeNode.get()); - } - - store.applyRecoveryTransaction(transaction); + store.applySnapshot(snapshot); } catch (Exception e) { - log.error("{}: An exception occurred when applying snapshot", logId, e); + log.error("{}: Failed to apply snapshot {}", logId, snapshot, e); + return; } - } - - @Override - public void applySnapshot(final byte[] snapshotBytes) { - // Since this will be done only on Recovery or when this actor is a Follower - // we can safely commit everything in here. We not need to worry about event notifications - // as they would have already been disabled on the follower - - log.info("{}: Applying snapshot", logId); - deserializeAndApplySnapshot(snapshotBytes); log.info("{}: Done applying snapshot", logId); } }