PendingRequests(RaftPeerId id) { this.name = id + "-" + getClass().getSimpleName(); this.pendingRequests = new RequestMap(id); }
PendingRequest add(RaftClientRequest request, TransactionContext entry) { // externally synced for now Preconditions.assertTrue(request.is(RaftClientRequestProto.TypeCase.WRITE)); final long index = entry.getLogEntry().getIndex(); LOG.debug("{}: addPendingRequest at index={}, request={}", name, index, request); final PendingRequest pending = new PendingRequest(index, request, entry); pendingRequests.put(index, pending); return pending; }
/** * The leader state is stopped. Send NotLeaderException to all the pending * requests since they have not got applied to the state machine yet. */ Collection<TransactionContext> sendNotLeaderResponses(NotLeaderException nle, Collection<CommitInfoProto> commitInfos) { LOG.info("{}: sendNotLeaderResponses", name); final Collection<TransactionContext> transactions = pendingRequests.setNotLeaderException(nle, commitInfos); if (pendingSetConf != null) { pendingSetConf.setNotLeaderException(nle, commitInfos); } return transactions; } }
/** * The leader state is stopped. Send NotLeaderException to all the pending * requests since they have not got applied to the state machine yet. */ void sendNotLeaderResponses() throws IOException { LOG.info("{} sends responses before shutting down PendingRequestsHandler", server.getId()); // notify the state machine about stepping down final NotLeaderException nle = server.generateNotLeaderException(); server.getStateMachine().notifyNotLeader(pendingRequests.setNotLeaderException(nle)); if (pendingSetConf != null) { pendingSetConf.setNotLeaderException(nle); } delayedReplies.failReplies(); }
boolean replyPendingRequest(long index, RaftClientReply reply) { final PendingRequest pending = pendingRequests.remove(index); if (pending != null) { Preconditions.assertTrue(pending.getIndex() == index); final ReplicationLevel replication = pending.getRequest().getType().getWrite().getReplication(); if (replication == ReplicationLevel.ALL) { if (delayedReplies.delay(pending, reply)) { return false; } } pending.setReply(reply); } return true; }
private PendingRequest add(long index, RaftClientRequest request, TransactionContext entry) { final PendingRequest pending = new PendingRequest(index, request, entry); pendingRequests.put(index, pending); last = pending; return pending; }
TransactionContext getTransactionContext(long index) { PendingRequest pendingRequest = pendingRequests.get(index); // it is possible that the pendingRequest is null if this peer just becomes // the new leader and commits transactions received by the previous leader return pendingRequest != null ? pendingRequest.getEntry() : null; }
TransactionContext getTransactionContext(long index) { PendingRequest pendingRequest = pendingRequests.get(index); // it is possible that the pendingRequest is null if this peer just becomes // the new leader and commits transactions received by the previous leader return pendingRequest != null ? pendingRequest.getEntry() : null; }
PendingRequests(RaftServerImpl server) { this.server = server; this.pendingRequests = new RequestMap(server.getId()); this.delayedReplies = new DelayedReplies(server.getId()); }
void replyPendingRequest(long index, RaftClientReply reply) { final PendingRequest pending = pendingRequests.remove(index); if (pending != null) { Preconditions.assertTrue(pending.getIndex() == index); pending.setReply(reply); } }