Search in sources :

Example 1 with TakeSnapshotEvent

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);
    }
}
Also used : UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) TakeSnapshotEvent(tezc.core.worker.clusterworker.TakeSnapshotEvent)

Example 2 with TakeSnapshotEvent

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);
    }
}
Also used : RaftException(tezc.base.exception.RaftException) RaftState(tezc.core.cluster.state.RaftState) State(tezc.State) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) TakeSnapshotEvent(tezc.core.worker.clusterworker.TakeSnapshotEvent)

Aggregations

IOException (java.io.IOException)2 UncheckedIOException (java.io.UncheckedIOException)2 TakeSnapshotEvent (tezc.core.worker.clusterworker.TakeSnapshotEvent)2 State (tezc.State)1 RaftException (tezc.base.exception.RaftException)1 RaftState (tezc.core.cluster.state.RaftState)1