private void onSaveSnapshotSuccess (SaveSnapshotSuccess successMessage) { LOG.debug ("{} saved ShardManager snapshot successfully. Deleting the prev snapshot if available", persistenceId()); deleteSnapshots(new SnapshotSelectionCriteria(scala.Long.MaxValue(), successMessage.metadata().timestamp() - 1, 0, 0)); }
private void handleSnapshotMessage(final Object message) { if (message instanceof SaveSnapshotFailure) { LOG.error("{}: failed to persist state", persistenceId(), ((SaveSnapshotFailure) message).cause()); persisting = false; self().tell(PoisonPill.getInstance(), ActorRef.noSender()); } else if (message instanceof SaveSnapshotSuccess) { LOG.debug("{}: got command: {}", persistenceId(), message); SaveSnapshotSuccess saved = (SaveSnapshotSuccess)message; deleteSnapshots(new SnapshotSelectionCriteria(saved.metadata().sequenceNr(), saved.metadata().timestamp() - 1, 0L, 0L)); persisting = false; unstash(); } else { LOG.debug("{}: stashing command {}", persistenceId(), message); stash(); } }
@Override AbstractClientActorBehavior<?> onReceiveCommand(final Object command) { if (command instanceof SaveSnapshotFailure) { LOG.error("{}: failed to persist state", persistenceId(), ((SaveSnapshotFailure) command).cause()); return null; } else if (command instanceof SaveSnapshotSuccess) { LOG.debug("{}: got command: {}", persistenceId(), command); SaveSnapshotSuccess saved = (SaveSnapshotSuccess)command; context().deleteSnapshots(new SnapshotSelectionCriteria(saved.metadata().sequenceNr(), saved.metadata().timestamp() - 1, 0L, 0L)); return this; } else if (command instanceof DeleteSnapshotsSuccess) { LOG.debug("{}: got command: {}", persistenceId(), command); } else if (command instanceof DeleteSnapshotsFailure) { // Not treating this as a fatal error. LOG.warn("{}: failed to delete prior snapshots", persistenceId(), ((DeleteSnapshotsFailure) command).cause()); } else { LOG.debug("{}: stashing command {}", persistenceId(), command); context().stash(); return this; } context().unstash(); return context().createBehavior(myId); } }
@Override AbstractClientActorBehavior<?> onReceiveCommand(final Object command) { if (command instanceof SaveSnapshotFailure) { LOG.error("{}: failed to persist state", persistenceId(), ((SaveSnapshotFailure) command).cause()); return null; } else if (command instanceof SaveSnapshotSuccess) { LOG.debug("{}: got command: {}", persistenceId(), command); SaveSnapshotSuccess saved = (SaveSnapshotSuccess)command; context().deleteSnapshots(new SnapshotSelectionCriteria(saved.metadata().sequenceNr(), saved.metadata().timestamp() - 1, 0L, 0L)); return this; } else if (command instanceof DeleteSnapshotsSuccess) { LOG.debug("{}: got command: {}", persistenceId(), command); } else if (command instanceof DeleteSnapshotsFailure) { // Not treating this as a fatal error. LOG.warn("{}: failed to delete prior snapshots", persistenceId(), ((DeleteSnapshotsFailure) command).cause()); } else { LOG.debug("{}: stashing command {}", persistenceId(), command); context().stash(); return this; } context().unstash(); return context().createBehavior(myId); } }
@Override public void commit(final long sequenceNumber, long timeStamp) { LOG.debug("{}: Snapshot success - sequence number: {}", persistenceId(), sequenceNumber); if(applySnapshot != null) { try { Snapshot snapshot = applySnapshot.getSnapshot(); //clears the followers log, sets the snapshot index to ensure adjusted-index works context.setReplicatedLog(ReplicatedLogImpl.newInstance(snapshot, context)); context.setLastApplied(snapshot.getLastAppliedIndex()); context.setCommitIndex(snapshot.getLastAppliedIndex()); context.getTermInformation().update(snapshot.getElectionTerm(), snapshot.getElectionVotedFor()); if(snapshot.getServerConfiguration() != null) { context.updatePeerIds(snapshot.getServerConfiguration()); } if(snapshot.getState().length > 0 ) { applySnapshotProcedure.accept(snapshot.getState()); } applySnapshot.getCallback().onSuccess(); } catch (Exception e) { LOG.error("{}: Error applying snapshot", context.getId(), e); } } else { context.getReplicatedLog().snapshotCommit(); } context.getPersistenceProvider().deleteSnapshots(new SnapshotSelectionCriteria(sequenceNumber, timeStamp - 1, 0L, 0L)); context.getPersistenceProvider().deleteMessages(lastSequenceNumber); snapshotComplete(); }