private int getSnapshotSyncBlockSize(){ int blockSize = this.context.getRaftParameters().getSnapshotBlockSize(); return blockSize == 0 ? DEFAULT_SNAPSHOT_SYNC_BLOCK_SIZE : blockSize; }
private int getSnapshotSyncBlockSize(){ int blockSize = this.context.getRaftParameters().getSnapshotBlockSize(); return blockSize == 0 ? DEFAULT_SNAPSHOT_SYNC_BLOCK_SIZE : blockSize; }
private int getSnapshotSyncBlockSize(){ int blockSize = this.context.getRaftParameters().getSnapshotBlockSize(); return blockSize == 0 ? DEFAULT_SNAPSHOT_SYNC_BLOCK_SIZE : blockSize; }
private void restartElectionTimer(){ // don't start the election timer while this server is still catching up the logs if(this.catchingUp){ return; } if(this.scheduledElection != null){ this.scheduledElection.cancel(false); } RaftParameters parameters = this.context.getRaftParameters(); int electionTimeout = parameters.getElectionTimeoutLowerBound() + this.random.nextInt(parameters.getElectionTimeoutUpperBound() - parameters.getElectionTimeoutLowerBound() + 1); this.scheduledElection = this.context.getScheduledExecutor().schedule(this.electionTimeoutTask, electionTimeout, TimeUnit.MILLISECONDS); }
private void restartElectionTimer(){ // don't start the election timer while this server is still catching up the logs if(this.catchingUp){ return; } if(this.scheduledElection != null){ this.scheduledElection.cancel(false); } RaftParameters parameters = this.context.getRaftParameters(); int electionTimeout = parameters.getElectionTimeoutLowerBound() + this.random.nextInt(parameters.getElectionTimeoutUpperBound() - parameters.getElectionTimeoutLowerBound() + 1); this.scheduledElection = this.context.getScheduledExecutor().schedule(this.electionTimeoutTask, electionTimeout, TimeUnit.MILLISECONDS); }
private void restartElectionTimer(){ // don't start the election timer while this server is still catching up the logs if(this.catchingUp){ return; } if(this.scheduledElection != null){ this.scheduledElection.cancel(false); } RaftParameters parameters = this.context.getRaftParameters(); int electionTimeout = parameters.getElectionTimeoutLowerBound() + this.random.nextInt(parameters.getElectionTimeoutUpperBound() - parameters.getElectionTimeoutLowerBound() + 1); this.scheduledElection = this.context.getScheduledExecutor().schedule(this.electionTimeoutTask, electionTimeout, TimeUnit.MILLISECONDS); }
public PeerServer(ClusterServer server, RaftContext context, final Consumer<PeerServer> heartbeatConsumer){ this.clusterConfig = server; this.rpcClient = context.getRpcClientFactory().createRpcClient(server.getEndpoint()); this.busyFlag = new AtomicInteger(0); this.pendingCommitFlag = new AtomicInteger(0); this.heartbeatInterval = this.currentHeartbeatInterval = context.getRaftParameters().getHeartbeatInterval(); this.maxHeartbeatInterval = context.getRaftParameters().getMaxHeartbeatInterval(); this.rpcBackoffInterval = context.getRaftParameters().getRpcFailureBackoff(); this.heartbeatTask = null; this.snapshotSyncContext = null; this.nextLogIndex = 1; this.matchedIndex = 0; this.heartbeatEnabled = false; this.executor = context.getScheduledExecutor(); PeerServer self = this; this.heartbeatTimeoutHandler = new Callable<Void>(){ @Override public Void call() throws Exception { heartbeatConsumer.accept(self); return null; }}; }
public PeerServer(ClusterServer server, RaftContext context, final Consumer<PeerServer> heartbeatConsumer){ this.clusterConfig = server; this.rpcClient = context.getRpcClientFactory().createRpcClient(server.getEndpoint()); this.busyFlag = new AtomicInteger(0); this.pendingCommitFlag = new AtomicInteger(0); this.heartbeatInterval = this.currentHeartbeatInterval = context.getRaftParameters().getHeartbeatInterval(); this.maxHeartbeatInterval = context.getRaftParameters().getMaxHeartbeatInterval(); this.rpcBackoffInterval = context.getRaftParameters().getRpcFailureBackoff(); this.heartbeatTask = null; this.snapshotSyncContext = null; this.nextLogIndex = 1; this.matchedIndex = 0; this.heartbeatEnabled = false; this.executor = context.getScheduledExecutor(); PeerServer self = this; this.heartbeatTimeoutHandler = new Callable<Void>(){ @Override public Void call() throws Exception { heartbeatConsumer.accept(self); return null; }}; }
public PeerServer(ClusterServer server, RaftContext context, final Consumer<PeerServer> heartbeatConsumer){ this.clusterConfig = server; this.rpcClient = context.getRpcClientFactory().createRpcClient(server.getEndpoint()); this.busyFlag = new AtomicInteger(0); this.pendingCommitFlag = new AtomicInteger(0); this.heartbeatInterval = this.currentHeartbeatInterval = context.getRaftParameters().getHeartbeatInterval(); this.maxHeartbeatInterval = context.getRaftParameters().getMaxHeartbeatInterval(); this.rpcBackoffInterval = context.getRaftParameters().getRpcFailureBackoff(); this.heartbeatTask = null; this.snapshotSyncContext = null; this.nextLogIndex = 1; this.matchedIndex = 0; this.heartbeatEnabled = false; this.executor = context.getScheduledExecutor(); PeerServer self = this; this.heartbeatTimeoutHandler = new Callable<Void>(){ @Override public Void call() throws Exception { heartbeatConsumer.accept(self); return null; }}; }
try{ if(this.context.getRaftParameters().getSnapshotDistance() > 0 && ((indexCommitted - this.logStore.getStartIndex()) > this.context.getRaftParameters().getSnapshotDistance()) && this.snapshotInProgress.compareAndSet(0, 1)){ snapshotInAction = true; Snapshot currentSnapshot = this.stateMachine.getLastSnapshot(); if(currentSnapshot != null && indexCommitted - currentSnapshot.getLastLogIndex() < this.context.getRaftParameters().getSnapshotDistance()){ this.logger.info("a very recent snapshot is available at index %d, will skip this one", currentSnapshot.getLastLogIndex()); this.snapshotInProgress.set(0);
try{ if(this.context.getRaftParameters().getSnapshotDistance() > 0 && ((indexCommitted - this.logStore.getStartIndex()) > this.context.getRaftParameters().getSnapshotDistance()) && this.snapshotInProgress.compareAndSet(0, 1)){ snapshotInAction = true; Snapshot currentSnapshot = this.stateMachine.getLastSnapshot(); if(currentSnapshot != null && indexCommitted - currentSnapshot.getLastLogIndex() < this.context.getRaftParameters().getSnapshotDistance()){ this.logger.info("a very recent snapshot is available at index %d, will skip this one", currentSnapshot.getLastLogIndex()); this.snapshotInProgress.set(0);
final PeerServer server = (request.getMessageType() == RaftMessageType.LeaveClusterRequest) ? this.peers.get(request.getDestination()) : this.serverToJoin; if(server != null){ if(server.getCurrentHeartbeatInterval() >= this.context.getRaftParameters().getMaxHeartbeatInterval()){ if(request.getMessageType() == RaftMessageType.LeaveClusterRequest){ this.logger.info("rpc failed again for the removing server (%d), will remove this server directly", server.getId());
final PeerServer server = (request.getMessageType() == RaftMessageType.LeaveClusterRequest) ? this.peers.get(request.getDestination()) : this.serverToJoin; if(server != null){ if(server.getCurrentHeartbeatInterval() >= this.context.getRaftParameters().getMaxHeartbeatInterval()){ if(request.getMessageType() == RaftMessageType.LeaveClusterRequest){ this.logger.info("rpc failed again for the removing server (%d), will remove this server directly", server.getId());
final PeerServer server = (request.getMessageType() == RaftMessageType.LeaveClusterRequest) ? this.peers.get(request.getDestination()) : this.serverToJoin; if(server != null){ if(server.getCurrentHeartbeatInterval() >= this.context.getRaftParameters().getMaxHeartbeatInterval()){ if(request.getMessageType() == RaftMessageType.LeaveClusterRequest){ this.logger.info("rpc failed again for the removing server (%d), will remove this server directly", server.getId());
private void syncLogsToNewComingServer(long startIndex){ if(gap < this.context.getRaftParameters().getLogSyncStopGap()){ int sizeToSync = Math.min(gap, this.context.getRaftParameters().getLogSyncBatchSize()); byte[] logPack = this.logStore.packLog(startIndex, sizeToSync); request = new RaftRequestMessage();
private void syncLogsToNewComingServer(long startIndex){ if(gap < this.context.getRaftParameters().getLogSyncStopGap()){ int sizeToSync = Math.min(gap, this.context.getRaftParameters().getLogSyncBatchSize()); byte[] logPack = this.logStore.packLog(startIndex, sizeToSync); request = new RaftRequestMessage();
private void syncLogsToNewComingServer(long startIndex){ if(gap < this.context.getRaftParameters().getLogSyncStopGap()){ int sizeToSync = Math.min(gap, this.context.getRaftParameters().getLogSyncBatchSize()); byte[] logPack = this.logStore.packLog(startIndex, sizeToSync); request = new RaftRequestMessage();
long endIndex = Math.min(currentNextIndex, lastLogIndex + 1 + context.getRaftParameters().getMaximumAppendingSize()); LogEntry[] logEntries = (lastLogIndex + 1) >= endIndex ? null : this.logStore.getLogEntries(lastLogIndex + 1, endIndex); this.logger.debug(
long endIndex = Math.min(currentNextIndex, lastLogIndex + 1 + context.getRaftParameters().getMaximumAppendingSize()); LogEntry[] logEntries = (lastLogIndex + 1) >= endIndex ? null : this.logStore.getLogEntries(lastLogIndex + 1, endIndex); this.logger.debug(
long endIndex = Math.min(currentNextIndex, lastLogIndex + 1 + context.getRaftParameters().getMaximumAppendingSize()); LogEntry[] logEntries = (lastLogIndex + 1) >= endIndex ? null : this.logStore.getLogEntries(lastLogIndex + 1, endIndex); this.logger.debug(