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();
}
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);
}
}
}
}
}
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);
}
}
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;
}
Aggregations