private void commitPositionOnSingleNode() { final long commitPosition = logStream.getLogStorageAppender().getCurrentAppenderPosition() - 1; if (initialEventPosition >= 0 && commitPosition >= initialEventPosition && logStream.getCommitPosition() < commitPosition) { logStream.setCommitPosition(commitPosition); } }
private void commitPositionOnSingleNode() { final long commitPosition = logStream.getLogStorageAppender().getCurrentAppenderPosition() - 1; if (initialEventPosition >= 0 && commitPosition >= initialEventPosition && logStream.getCommitPosition() < commitPosition) { logStream.setCommitPosition(commitPosition); } }
protected void acceptAppendRequest(long position, long commitPosition, int nodeId) { final long currentCommitPosition = logStream.getCommitPosition(); final long nextCommitPosition = Math.min(position, commitPosition); if (nextCommitPosition >= 0 && nextCommitPosition > currentCommitPosition) { logStream.setCommitPosition(nextCommitPosition); } appendResponse.reset().setRaft(raft).setPreviousEventPosition(position).setSucceeded(true); raft.sendMessage(nodeId, appendResponse); }
protected void acceptAppendRequest(long position, long commitPosition, int nodeId) { final long currentCommitPosition = logStream.getCommitPosition(); final long nextCommitPosition = Math.min(position, commitPosition); if (nextCommitPosition >= 0 && nextCommitPosition > currentCommitPosition) { logStream.setCommitPosition(nextCommitPosition); } appendResponse.reset().setRaft(raft).setPreviousEventPosition(position).setSucceeded(true); raft.sendMessage(nodeId, appendResponse); }
private void commit() { final List<RaftMember> memberList = raftMembers.getMemberList(); final int memberSize = memberList.size(); final long[] positions = new long[memberSize + 1]; for (int i = 0; i < memberSize; i++) { positions[i] = memberList.get(i).getMatchPosition(); } // TODO(menski): `raft.getLogStream().getCurrentAppenderPosition()` is wrong as the current // appender // position is the next position which is written. This means in a single node cluster the log // already committed an event which will be written in the future. `- 1` is a hotfix for this. // see https://github.com/zeebe-io/zeebe/issues/501 positions[memberSize] = logStream.getLogStorageAppender().getCurrentAppenderPosition() - 1; Arrays.sort(positions); final long commitPosition = positions[memberSize + 1 - raft.requiredQuorum()]; final LogStream logStream = raft.getLogStream(); if (initialEventPosition >= 0 && commitPosition >= initialEventPosition && logStream.getCommitPosition() < commitPosition) { logStream.setCommitPosition(commitPosition); } }
@Override protected void onActorStarting() { final ActorCondition condition = actor.onCondition( "on-append", () -> logStream.setCommitPosition(Long.MAX_VALUE)); logStream.registerOnAppendCondition(condition); } })
private void commit() { final List<RaftMember> memberList = raftMembers.getMemberList(); final int memberSize = memberList.size(); final long[] positions = new long[memberSize + 1]; for (int i = 0; i < memberSize; i++) { positions[i] = memberList.get(i).getMatchPosition(); } // TODO(menski): `raft.getLogStream().getCurrentAppenderPosition()` is wrong as the current // appender // position is the next position which is written. This means in a single node cluster the log // already committed an event which will be written in the future. `- 1` is a hotfix for this. // see https://github.com/zeebe-io/zeebe/issues/501 positions[memberSize] = logStream.getLogStorageAppender().getCurrentAppenderPosition() - 1; Arrays.sort(positions); final long commitPosition = positions[memberSize + 1 - raft.requiredQuorum()]; final LogStream logStream = raft.getLogStream(); if (initialEventPosition >= 0 && commitPosition >= initialEventPosition && logStream.getCommitPosition() < commitPosition) { logStream.setCommitPosition(commitPosition); } }
@Override protected void onActorStarting() { final ActorCondition condition = actor.onCondition( "on-append", () -> logStream.setCommitPosition(Long.MAX_VALUE)); logStream.registerOnAppendCondition(condition); } })
/** * Truncates events with getPosition greater than the argument. Includes committed events. Resets * commit getPosition to the argument getPosition. * * @param position exclusive (unlike {@link LogStream#truncate(long)}!) */ public void truncate(final String stream, final long position) { final LogStream logStream = getLogStream(stream); try (final LogStreamReader reader = new BufferedLogStreamReader(logStream)) { logStream.closeAppender().get(); reader.seek(position + 1); logStream.setCommitPosition(position); if (reader.hasNext()) { logStream.truncate(reader.next().getPosition()); } logStream.setCommitPosition(Long.MAX_VALUE); logStream.openAppender().get(); } catch (final Exception e) { throw new RuntimeException("Could not truncate log stream " + stream, e); } }
/** * Truncates events with getPosition greater than the argument. Includes committed events. Resets * commit getPosition to the argument getPosition. * * @param position exclusive (unlike {@link LogStream#truncate(long)}!) */ public void truncate(final String stream, final long position) { final LogStream logStream = getLogStream(stream); try (final LogStreamReader reader = new BufferedLogStreamReader(logStream)) { logStream.closeAppender().get(); reader.seek(position + 1); logStream.setCommitPosition(position); if (reader.hasNext()) { logStream.truncate(reader.next().getPosition()); } logStream.setCommitPosition(Long.MAX_VALUE); logStream.openAppender().get(); } catch (final Exception e) { throw new RuntimeException("Could not truncate log stream " + stream, e); } }