Search in sources :

Example 1 with RaftException

use of tezc.base.exception.RaftException in project tezcRaft by tezc.

the class Core method removeCluster.

/**
 * Remove cluster, if running, will be stopped first, than will be deleted,
 * this a non blocking call, it may take a while to stop working gracefully
 * @param name         cluster name
 * @throws IOException on any IO error
 */
public void removeCluster(String name) throws IOException {
    Cluster cluster = clusters.get(name);
    if (cluster == null) {
        throw new RaftException("Cannot find cluster with name : " + name);
    }
    cluster.remove();
}
Also used : RaftException(tezc.base.exception.RaftException) RaftCluster(tezc.core.cluster.RaftCluster) Cluster(tezc.core.cluster.Cluster)

Example 2 with RaftException

use of tezc.base.exception.RaftException in project tezcRaft by tezc.

the class Cluster method checkCompaction.

/**
 * Check compaction,
 *
 * If snapshot is taken till an index, if entry of that index is not on
 * the fly(being sending to followers), previous stores might be discarded
 *
 * @throws RaftException on any error (mostly IO error on file operations)
 */
private void checkCompaction() {
    long min = minOnFly();
    if (min > snapshotIndex && stores.size() != 1) {
        Iterator<MappedStore> it = stores.iterator();
        while (it.hasNext()) {
            MappedStore mappedStore = it.next();
            if (min > mappedStore.getEndIndex()) {
                try {
                    worker.logDebug("Min was ", min, " snapshotIndex was ", snapshotIndex);
                    mappedStore.delete();
                    it.remove();
                } catch (Exception e) {
                    worker.logError(e);
                    throw new RaftException(e);
                }
            }
        }
    }
}
Also used : RaftException(tezc.base.exception.RaftException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) RaftException(tezc.base.exception.RaftException)

Example 3 with RaftException

use of tezc.base.exception.RaftException 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)

Example 4 with RaftException

use of tezc.base.exception.RaftException in project tezcRaft by tezc.

the class Cluster method start.

/**
 * Start cluster
 *
 * @throws RaftException on a missing configuration
 */
public void start() {
    electionTimer = new ElectionTimer(this, true, new Random().nextInt(150) + 500, worker.timestamp() + 500);
    heartBeatTimer = new HeartBeatTimer(this, true, 2000, worker.timestamp() + 150);
    startLog();
    if (!isStarted() && nodeId == -1) {
        worker.logInfo("Cannot start cluster ", clusterRecord);
        throw new RaftException("Local record is not set :" + clusterRecord);
    }
    local = clusterRecord.getRecord(nodeId);
    for (TransportRecord record : local.transports) {
        worker.listenAt(record);
    }
    for (TransportRecord record : local.secureTransports) {
        worker.listenAt(record);
    }
    for (NodeRecord record : clusterRecord.nodes) {
        if (record.id != local.id) {
            nodes.add(new PeerNode(worker, this, null, local, record, PeerNode.Type.PEER));
        }
    }
    startElectionTimer();
    active = true;
}
Also used : TransportRecord(tezc.core.record.TransportRecord) NodeRecord(tezc.core.record.NodeRecord) RaftException(tezc.base.exception.RaftException) PeerNode(tezc.core.node.PeerNode)

Aggregations

RaftException (tezc.base.exception.RaftException)4 IOException (java.io.IOException)2 UncheckedIOException (java.io.UncheckedIOException)2 State (tezc.State)1 Cluster (tezc.core.cluster.Cluster)1 RaftCluster (tezc.core.cluster.RaftCluster)1 RaftState (tezc.core.cluster.state.RaftState)1 PeerNode (tezc.core.node.PeerNode)1 NodeRecord (tezc.core.record.NodeRecord)1 TransportRecord (tezc.core.record.TransportRecord)1 TakeSnapshotEvent (tezc.core.worker.clusterworker.TakeSnapshotEvent)1