From: Tom Pantelis Date: Thu, 21 Jul 2016 19:57:35 +0000 (-0400) Subject: CDS Frontend client actor should delete prior snapshots X-Git-Tag: release/boron~38 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=b08cf9e64783ce7db00b6e41f2720f56b726d3b5 CDS Frontend client actor should delete prior snapshots The RecoveringClientActorBehavior increments the last generation id and saves a new snapshot. However the prior snapshots remain in akka persistence - every time the controller is restarted a new snapshot file is created. We should delete the prior snaphsots. The snapshot file names were very long with escape chars b/c FrontendIdentifier.toString is used for the frontend client actor's persistence ID. We should use a shorter, more readable ID, so I changed it to the form: member-1-frontend-datastore-config member-1-frontend-datastore-operational Change-Id: I1c77c826729ca1a36497a1236ac99f7cc77efb72 Signed-off-by: Tom Pantelis --- diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/FrontendIdentifier.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/FrontendIdentifier.java index fe85ef6e52..fc728130e6 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/FrontendIdentifier.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/FrontendIdentifier.java @@ -8,7 +8,6 @@ package org.opendaylight.controller.cluster.access.concepts; import com.google.common.annotations.Beta; -import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; import java.io.DataInput; import java.io.DataOutput; @@ -108,10 +107,13 @@ public final class FrontendIdentifier implements WritableIdentifier { return memberName.equals(other.memberName) && clientType.equals(other.clientType); } + public String toPersistentId() { + return memberName.getName() + "-frontend-" + clientType.getName(); + } + @Override public String toString() { - return MoreObjects.toStringHelper(FrontendIdentifier.class).add("member", memberName) - .add("clientType", clientType).toString(); + return toPersistentId(); } private Object writeReplace() { diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/DistributedDataStoreClientActor.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/DistributedDataStoreClientActor.java index dd40f1e589..11aeae4f92 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/DistributedDataStoreClientActor.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/DistributedDataStoreClientActor.java @@ -56,7 +56,7 @@ public final class DistributedDataStoreClientActor extends AbstractClientActor { } public static Props props(final @Nonnull MemberName memberName, @Nonnull final String storeName, final ActorContext ctx) { - final String name = "DistributedDataStore:storeName='" + storeName + "'"; + final String name = "datastore-" + storeName; final FrontendIdentifier frontendId = FrontendIdentifier.create(memberName, FrontendType.forName(name)); return Props.create(DistributedDataStoreClientActor.class, () -> new DistributedDataStoreClientActor(frontendId, ctx)); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/actors/client/AbstractClientActor.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/actors/client/AbstractClientActor.java index 5f940842fa..e8d93958e9 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/actors/client/AbstractClientActor.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/actors/client/AbstractClientActor.java @@ -27,7 +27,7 @@ public abstract class AbstractClientActor extends UntypedPersistentActor { protected AbstractClientActor(final FrontendIdentifier frontendId) { currentBehavior = new RecoveringClientActorBehavior( - new InitialClientActorContext(this, frontendId.toString()), frontendId); + new InitialClientActorContext(this, frontendId.toPersistentId()), frontendId); } @Override diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/actors/client/InitialClientActorContext.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/actors/client/InitialClientActorContext.java index 5dce1cd3f1..92b3d807dd 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/actors/client/InitialClientActorContext.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/actors/client/InitialClientActorContext.java @@ -8,6 +8,7 @@ package org.opendaylight.controller.cluster.datastore.actors.client; import akka.actor.ActorSystem; +import akka.persistence.SnapshotSelectionCriteria; import com.google.common.base.Preconditions; import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier; @@ -27,6 +28,10 @@ final class InitialClientActorContext extends AbstractClientActorContext { actor.saveSnapshot(snapshot); } + void deleteSnapshots(SnapshotSelectionCriteria criteria) { + actor.deleteSnapshots(criteria); + } + ClientActorBehavior createBehavior(final ClientIdentifier clientId) { final ActorSystem system = actor.getContext().system(); final ClientActorContext context = new ClientActorContext(self(), system.scheduler(), system.dispatcher(), diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/actors/client/SavingClientActorBehavior.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/actors/client/SavingClientActorBehavior.java index f8977344c3..fc8b005689 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/actors/client/SavingClientActorBehavior.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/actors/client/SavingClientActorBehavior.java @@ -9,6 +9,7 @@ package org.opendaylight.controller.cluster.datastore.actors.client; import akka.persistence.SaveSnapshotFailure; import akka.persistence.SaveSnapshotSuccess; +import akka.persistence.SnapshotSelectionCriteria; import com.google.common.base.Preconditions; import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier; import org.slf4j.Logger; @@ -33,6 +34,11 @@ final class SavingClientActorBehavior extends RecoveredClientActorBehavior