private ProposalRound newProposalRound() { List<Proposal> todo = new ArrayList<>(queued); queued.clear(); roundHoldsReferenceToRefTree = true; return new ProposalRound(this, headIndex, todo, refTree); }
@Override void start() throws IOException { for (Proposal p : todo) { p.notifyState(RUNNING); } try { ObjectId id; try (Repository git = leader.openRepository(); ProposedTimestamp ts = getSystem().getClock().propose()) { id = insertProposals(git, ts); blockUntil(ts); } runAsync(id); } catch (NoOp e) { for (Proposal p : todo) { p.success(); } leader.lock.lock(); try { leader.nextRound(); } finally { leader.lock.unlock(); } } catch (IOException e) { abort(); throw e; } }
private static boolean canCombine(Proposal a, Proposal b) { String aMsg = nullToEmpty(a.getMessage()); String bMsg = nullToEmpty(b.getMessage()); return aMsg.equals(bMsg) && canCombine(a.getAuthor(), b.getAuthor()); }
private ObjectId insertProposals(Repository git, ProposedTimestamp ts) throws IOException, NoOp { ObjectId id; try (ObjectInserter inserter = git.newObjectInserter()) { // TODO(sop) Process signed push certificates. if (queuedTree != null) { id = insertSingleProposal(git, ts, inserter); } else { id = insertMultiProposal(git, ts, inserter); } stageCommands = makeStageList(git, inserter); inserter.flush(); } return id; }
void start() throws IOException { for (Proposal p : todo) { p.notifyState(RUNNING); } try { ObjectId id; try (Repository git = leader.openRepository()) { id = insertProposals(git); } runAsync(id); } catch (NoOp e) { for (Proposal p : todo) { p.success(); } leader.lock.lock(); try { leader.nextRound(); } finally { leader.lock.unlock(); } } catch (IOException e) { abort(); throw e; } }
private static boolean canCombine(List<Proposal> todo) { Proposal first = todo.get(0); for (int i = 1; i < todo.size(); i++) { if (!canCombine(first, todo.get(i))) { return false; } } return true; }
private ObjectId insertSingleProposal(Repository git, ProposedTimestamp ts, ObjectInserter inserter) throws IOException, NoOp { // Fast path: tree is passed in with all proposals applied. ObjectId treeId = queuedTree.writeTree(inserter); queuedTree = null; leader.roundHoldsReferenceToRefTree = false; if (!ObjectId.zeroId().equals(acceptedOldIndex)) { try (RevWalk rw = new RevWalk(git)) { RevCommit c = rw.parseCommit(acceptedOldIndex); if (treeId.equals(c.getTree())) { throw new NoOp(); } } } Proposal p = todo.get(0); CommitBuilder b = new CommitBuilder(); b.setTreeId(treeId); if (!ObjectId.zeroId().equals(acceptedOldIndex)) { b.setParentId(acceptedOldIndex); } b.setCommitter(leader.getSystem().newCommitter(ts)); b.setAuthor(p.getAuthor() != null ? p.getAuthor() : b.getCommitter()); b.setMessage(message(p)); return inserter.insert(b); }
private ObjectId insertProposals(Repository git) throws IOException, NoOp { ObjectId id; try (ObjectInserter inserter = git.newObjectInserter()) { // TODO(sop) Process signed push certificates. if (queuedTree != null) { id = insertSingleProposal(git, inserter); } else { id = insertMultiProposal(git, inserter); } stageCommands = makeStageList(git, inserter); inserter.flush(); } return id; }
ProposalRound(KetchLeader leader, LogIndex head, List<Proposal> todo, @Nullable RefTree tree) { super(leader, head); this.todo = todo; if (tree != null && canCombine(todo)) { this.queuedTree = tree; } else { leader.roundHoldsReferenceToRefTree = false; } }
b.setMessage(message(p)); lastIndex = inserter.insert(b);
@Override void start() throws IOException { for (Proposal p : todo) { p.notifyState(RUNNING); } try { ObjectId id; try (Repository git = leader.openRepository(); ProposedTimestamp ts = getSystem().getClock().propose()) { id = insertProposals(git, ts); blockUntil(ts); } runAsync(id); } catch (NoOp e) { for (Proposal p : todo) { p.success(); } leader.lock.lock(); try { leader.nextRound(); } finally { leader.lock.unlock(); } } catch (IOException e) { abort(); throw e; } }
private ObjectId insertProposals(Repository git, ProposedTimestamp ts) throws IOException, NoOp { ObjectId id; try (ObjectInserter inserter = git.newObjectInserter()) { // TODO(sop) Process signed push certificates. if (queuedTree != null) { id = insertSingleProposal(git, ts, inserter); } else { id = insertMultiProposal(git, ts, inserter); } stageCommands = makeStageList(git, inserter); inserter.flush(); } return id; }
private static boolean canCombine(Proposal a, Proposal b) { String aMsg = nullToEmpty(a.getMessage()); String bMsg = nullToEmpty(b.getMessage()); return aMsg.equals(bMsg) && canCombine(a.getAuthor(), b.getAuthor()); }
private static boolean canCombine(List<Proposal> todo) { Proposal first = todo.get(0); for (int i = 1; i < todo.size(); i++) { if (!canCombine(first, todo.get(i))) { return false; } } return true; }
private ObjectId insertSingleProposal(Repository git, ObjectInserter inserter) throws IOException, NoOp { // Fast path: tree is passed in with all proposals applied. ObjectId treeId = queuedTree.writeTree(inserter); queuedTree = null; leader.roundHoldsReferenceToRefTree = false; if (!ObjectId.zeroId().equals(acceptedOldIndex)) { try (RevWalk rw = new RevWalk(git)) { RevCommit c = rw.parseCommit(acceptedOldIndex); if (treeId.equals(c.getTree())) { throw new NoOp(); } } } Proposal p = todo.get(0); CommitBuilder b = new CommitBuilder(); b.setTreeId(treeId); if (!ObjectId.zeroId().equals(acceptedOldIndex)) { b.setParentId(acceptedOldIndex); } b.setCommitter(leader.getSystem().newCommitter()); b.setAuthor(p.getAuthor() != null ? p.getAuthor() : b.getCommitter()); b.setMessage(message(p)); return inserter.insert(b); }
private ProposalRound newProposalRound() { List<Proposal> todo = new ArrayList<>(queued); queued.clear(); roundHoldsReferenceToRefTree = true; return new ProposalRound(this, headIndex, todo, refTree); }
private static boolean canCombine(Proposal a, Proposal b) { String aMsg = nullToEmpty(a.getMessage()); String bMsg = nullToEmpty(b.getMessage()); return aMsg.equals(bMsg) && canCombine(a.getAuthor(), b.getAuthor()); }
private static boolean canCombine(List<Proposal> todo) { Proposal first = todo.get(0); for (int i = 1; i < todo.size(); i++) { if (!canCombine(first, todo.get(i))) { return false; } } return true; }
private ObjectId insertSingleProposal(Repository git, ProposedTimestamp ts, ObjectInserter inserter) throws IOException, NoOp { // Fast path: tree is passed in with all proposals applied. ObjectId treeId = queuedTree.writeTree(inserter); queuedTree = null; leader.roundHoldsReferenceToRefTree = false; if (!ObjectId.zeroId().equals(acceptedOldIndex)) { try (RevWalk rw = new RevWalk(git)) { RevCommit c = rw.parseCommit(acceptedOldIndex); if (treeId.equals(c.getTree())) { throw new NoOp(); } } } Proposal p = todo.get(0); CommitBuilder b = new CommitBuilder(); b.setTreeId(treeId); if (!ObjectId.zeroId().equals(acceptedOldIndex)) { b.setParentId(acceptedOldIndex); } b.setCommitter(leader.getSystem().newCommitter(ts)); b.setAuthor(p.getAuthor() != null ? p.getAuthor() : b.getCommitter()); b.setMessage(message(p)); return inserter.insert(b); }
private ProposalRound newProposalRound() { List<Proposal> todo = new ArrayList<>(queued); queued.clear(); roundHoldsReferenceToRefTree = true; return new ProposalRound(this, headIndex, todo, refTree); }