CDS Frontend client actor should delete prior snapshots
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / actors / client / SavingClientActorBehavior.java
index f8977344c3ab9190397964d03f25fe4fdbaaad71..fc8b0056890e34eca5a1121cfafbdba41e25e961 100644 (file)
@@ -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<Initi
             return null;
         } else if (command instanceof SaveSnapshotSuccess) {
             context().unstash();
+
+            SaveSnapshotSuccess saved = (SaveSnapshotSuccess)command;
+            context().deleteSnapshots(new SnapshotSelectionCriteria(saved.metadata().sequenceNr(),
+                    saved.metadata().timestamp() - 1, 0L, 0L));
+
             return context().createBehavior(myId);
         } else {
             LOG.debug("{}: stashing command {}", persistenceId(), command);