use of tezc.core.worker.clusterworker.TakeSnapshotEvent in project tezcRaft by tezc.
the class Cluster method checkSnapshot.
/**
* If our internal state is eligible for snapshotting, snapshot operation
* will be triggered
*
* @throws UncheckedIOException on any IO error
*/
private void checkSnapshot() {
try {
if (commit > stores.getFirst().getEndIndex()) {
if (!snapshotReader.isRemovable()) {
return;
}
if (snapshotWriter.isSnapshotInProgress()) {
return;
}
EntryRecord entry = getEntry(stores.getFirst().getEndIndex());
snapshotWriter.setIndex(stores.getFirst().getEndIndex());
snapshotWriter.setTerm(entry.getTerm());
snapshotWriter.setStates(states);
snapshotWriter.preSnapshot();
snapshotWorker.addEvent(new TakeSnapshotEvent(worker, this, snapshotWriter));
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
use of tezc.core.worker.clusterworker.TakeSnapshotEvent in project tezcRaft by tezc.
the class Cluster method handleSnapshotReady.
/**
* Snapshot ready callback
*
* @param success true if snapshotting executed successfully
* @throws UncheckedIOException on any IO error
*/
public void handleSnapshotReady(boolean success) {
try {
if (!success) {
throw new RaftException("Snapshot failed");
}
State state = snapshotWriter.getFirstPendingState();
state.clearSnapshotInProgress();
List<CommandRecord> pendings = state.getPendings();
for (CommandRecord record : pendings) {
state.commandReceived(record.index, record.term, record.clientId, record.sequence, record.buf);
}
snapshotWriter.popFirstPendingState();
state = snapshotWriter.getFirstPendingState();
if (state == null) {
snapshotWriter.postSnapshot();
snapshotIndex = snapshotWriter.getIndex();
} else {
snapshotWorker.addEvent(new TakeSnapshotEvent(worker, this, snapshotWriter));
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
Aggregations