private void preAppendEntriesAsync(RaftPeerId leaderId, RaftGroupId leaderGroupId, long leaderTerm, TermIndex previous, long leaderCommit, boolean initializing, LogEntryProto... entries) throws IOException { CodeInjectionForTesting.execute(APPEND_ENTRIES, getId(), leaderId, leaderTerm, previous, leaderCommit, initializing, entries); final LifeCycle.State currentState = assertLifeCycleState(STARTING, RUNNING); if (currentState == STARTING) { if (role.getCurrentRole() == null) { throw new ServerNotReadyException("The role of Server " + getId() + " is not yet initialized."); } } assertGroup(leaderId, leaderGroupId); try { validateEntries(leaderTerm, previous, entries); } catch (IllegalArgumentException e) { throw new IOException(e); } }
ReinitializeRequest request) throws IOException { LOG.info("{}: reinitializeAsync {}", getId(), request); getImpl().assertGroup(request.getRequestorId(), request.getRaftGroupId()); if (!reinitializeRequest.compareAndSet(null, request)) { throw new IOException("Another reinitialize is already in progress.");
getId(), candidateId, candidateGroupId, candidateTerm, candidateLastEntry); assertLifeCycleState(RUNNING); assertGroup(candidateId, candidateGroupId);
getId(), candidateId, candidateGroupId, candidateTerm, candidateLastEntry); assertLifeCycleState(RUNNING); assertGroup(candidateId, candidateGroupId);
assertGroup(leaderId, leaderGroupId);
/** * @return null if the server is in leader state. */ private CompletableFuture<RaftClientReply> checkLeaderState( RaftClientRequest request, RetryCache.CacheEntry entry) { try { assertGroup(request.getRequestorId(), request.getRaftGroupId()); } catch (GroupMismatchException e) { return RetryCache.failWithException(e, entry); } if (!isLeader()) { NotLeaderException exception = generateNotLeaderException(); final RaftClientReply reply = new RaftClientReply(request, exception, getCommitInfos()); return RetryCache.failWithReply(reply, entry); } final LeaderState leaderState = role.getLeaderState().orElse(null); if (leaderState == null || !leaderState.isReady()) { RetryCache.CacheEntry cacheEntry = retryCache.get(request.getClientId(), request.getCallId()); if (cacheEntry != null && cacheEntry.isCompletedNormally()) { return cacheEntry.getReplyFuture(); } return RetryCache.failWithException(new LeaderNotReadyException(getId()), entry); } return null; }
LOG.debug("{}: receive setConfiguration({})", getId(), request); assertLifeCycleState(RUNNING); assertGroup(request.getRequestorId(), request.getRaftGroupId());
LOG.debug("{}: receive setConfiguration({})", getId(), request); assertLifeCycleState(RUNNING); assertGroup(request.getRequestorId(), request.getRaftGroupId());
/** * @return null if the server is in leader state. */ private CompletableFuture<RaftClientReply> checkLeaderState( RaftClientRequest request, RetryCache.CacheEntry entry) { try { assertGroup(request.getRequestorId(), request.getRaftGroupId()); } catch (GroupMismatchException e) { return RetryCache.failWithException(e, entry); } if (!isLeader()) { NotLeaderException exception = generateNotLeaderException(); final RaftClientReply reply = new RaftClientReply(request, exception, getCommitInfos()); return RetryCache.failWithReply(reply, entry); } else if (leaderState == null || !leaderState.isReady()) { RetryCache.CacheEntry cacheEntry = retryCache.get(request.getClientId(), request.getCallId()); if (cacheEntry != null && cacheEntry.isCompletedNormally()) { return cacheEntry.getReplyFuture(); } return RetryCache.failWithException(new LeaderNotReadyException(getId()), entry); } return null; }
assertGroup(leaderId, leaderGroupId);
assertGroup(leaderId, leaderGroupId);