if (log.isDebugEnabled()) { log.debug("Replica {} finished:\n{}", //$NON-NLS-1$ replica.describeForLog(), snapshot()); Long.valueOf(term)); nextRound(); commitAsync(replica); notifySuccess(runningRound); if (log.isDebugEnabled()) { log.debug("Leader state:\n{}", snapshot()); //$NON-NLS-1$
Collection<Integer> validVoters = validVoterCounts(); if (!validVoters.contains(Integer.valueOf(v.size()))) { throw new IllegalArgumentException(MessageFormat.format( LocalReplica me = findLocal(v); if (me == null) { throw new IllegalArgumentException(
LogIndex committed = leader.getCommitted(); if (!equals(txnCommitted, committed) && shouldPushUnbatchedCommit(committed, leader.isIdle())) { pushCommitAsync(committed);
round = newProposalRound(); break; lock.lock(); try { nextRound(); } finally { lock.unlock();
KetchSystem getSystem() { return leader.getSystem(); }
initialize(); for (Proposal p : queued) { refTree.apply(p.getCommands()); scheduleLeader();
error = err.toString(); retryLater(req); leader.onReplicaUpdate(this); return; state = hasAccepted(leader.getHead()) ? CURRENT : LAGGING; if (stages != null) { staged.put(acceptCmd.getNewId(), stages); leader.onReplicaUpdate(this); runNextPushRequest(); } finally {
.setAuthor(rp.getRefLogIdent()) .setMessage("push"); //$NON-NLS-1$ leader.queueProposal(proposal); if (proposal.isDone()) {
/** * Snapshot this leader * * @return snapshot of this leader */ public LeaderSnapshot snapshot() { lock.lock(); try { LeaderSnapshot s = new LeaderSnapshot(); s.state = state; s.term = term; s.headIndex = headIndex; s.committedIndex = committedIndex; s.idle = isIdle(); for (KetchReplica r : voters) { s.replicas.add(r.snapshot()); } for (KetchReplica r : followers) { s.replicas.add(r.snapshot()); } return s; } finally { lock.unlock(); } }
private String message(Proposal p) { StringBuilder m = new StringBuilder(); String msg = p.getMessage(); if (msg != null && !msg.isEmpty()) { m.append(msg); while (m.length() < 2 || m.charAt(m.length() - 2) != '\n' || m.charAt(m.length() - 1) != '\n') { m.append('\n'); } } m.append(KetchConstants.TERM.getName()) .append(": ") //$NON-NLS-1$ .append(leader.getTerm()); return m.toString(); }
/** * Schedule a proposal round with the replica. * <p> * Called with {@link KetchLeader#lock} held by caller. * * @param round * current round being run by the leader. */ void pushTxnAcceptedAsync(Round round) { List<ReceiveCommand> cmds = new ArrayList<>(); if (commitSpeed == BATCHED) { LogIndex committedIndex = leader.getCommitted(); if (equals(txnAccepted, committedIndex) && !equals(txnCommitted, committedIndex)) { prepareTxnCommitted(cmds, committedIndex); } } // TODO(sop) Lagging replicas should build accept on the fly. if (round.stageCommands != null) { for (ReceiveCommand cmd : round.stageCommands) { // TODO(sop): Do not send certain object graphs to replica. cmds.add(copy(cmd)); } } cmds.add(new ReceiveCommand( round.acceptedOldIndex, round.acceptedNewIndex, getSystem().getTxnAccepted())); pushAsync(new ReplicaPushRequest(this, cmds)); }
/** * Get system configuration. * * @return system configuration. */ public KetchSystem getSystem() { return getLeader().getSystem(); }
round = newProposalRound(); break; lock.lock(); try { nextRound(); } finally { lock.unlock();
initialize(); for (Proposal p : queued) { refTree.apply(p.getCommands()); scheduleLeader();
error = err.toString(); retryLater(req); leader.onReplicaUpdate(this); return; state = hasAccepted(leader.getHead()) ? CURRENT : LAGGING; if (stages != null) { staged.put(acceptCmd.getNewId(), stages); leader.onReplicaUpdate(this); runNextPushRequest(); } finally {
private void proposeKetch(final List<Command> n, final RevCommit _commit) throws IOException, InterruptedException { final Proposal proposal = new Proposal(n) .setAuthor(_commit.getAuthorIdent()) .setMessage("push"); git.getKetchLeader().queueProposal(proposal); if (proposal.isDone()) { // This failed fast, e.g. conflict or bad precondition. throw new GitException("Error"); } if (proposal.getState() == QUEUED) { waitForQueue(proposal); } if (!proposal.isDone()) { waitForPropose(proposal); } }
private void commitAsync(KetchReplica caller) { for (KetchReplica r : voters) { if (r == caller) { continue; } if (r.shouldPushUnbatchedCommit(committedIndex, isIdle())) { r.pushCommitAsync(committedIndex); } } for (KetchReplica r : followers) { if (r == caller) { continue; } if (r.shouldPushUnbatchedCommit(committedIndex, isIdle())) { r.pushCommitAsync(committedIndex); } } }
private String message(Proposal p) { StringBuilder m = new StringBuilder(); String msg = p.getMessage(); if (msg != null && !msg.isEmpty()) { m.append(msg); while (m.length() < 2 || m.charAt(m.length() - 2) != '\n' || m.charAt(m.length() - 1) != '\n') { m.append('\n'); } } m.append(KetchConstants.TERM.getName()) .append(": ") //$NON-NLS-1$ .append(leader.getTerm()); return m.toString(); }
/** * Schedule a proposal round with the replica. * <p> * Called with {@link KetchLeader#lock} held by caller. * * @param round * current round being run by the leader. */ void pushTxnAcceptedAsync(Round round) { List<ReceiveCommand> cmds = new ArrayList<>(); if (commitSpeed == BATCHED) { LogIndex committedIndex = leader.getCommitted(); if (equals(txnAccepted, committedIndex) && !equals(txnCommitted, committedIndex)) { prepareTxnCommitted(cmds, committedIndex); } } // TODO(sop) Lagging replicas should build accept on the fly. if (round.stageCommands != null) { for (ReceiveCommand cmd : round.stageCommands) { // TODO(sop): Do not send certain object graphs to replica. cmds.add(copy(cmd)); } } cmds.add(new ReceiveCommand( round.acceptedOldIndex, round.acceptedNewIndex, getSystem().getTxnAccepted())); pushAsync(new ReplicaPushRequest(this, cmds)); }
if (log.isDebugEnabled()) { log.debug("Replica {} finished:\n{}", //$NON-NLS-1$ replica.describeForLog(), snapshot()); Long.valueOf(term)); nextRound(); commitAsync(replica); notifySuccess(runningRound); if (log.isDebugEnabled()) { log.debug("Leader state:\n{}", snapshot()); //$NON-NLS-1$