use of io.aeron.cluster.client.RecordingLog in project aeron by real-logic.
the class RecordingLogTest method shouldAppendAndThenCommitLogPosition.
@Test
public void shouldAppendAndThenCommitLogPosition() {
final long leadershipTermId = 1111L;
final long termBaseLogPosition = 2222L;
final long timestamp = 3333L;
final int votedForMemberId = 1;
final RecordingLog recordingLog = new RecordingLog(TEMP_DIR);
recordingLog.appendTerm(leadershipTermId, termBaseLogPosition, timestamp, votedForMemberId);
final long newLogPosition = 7777L;
recordingLog.commitLeadershipLogPosition(leadershipTermId, newLogPosition);
final RecordingLog recordingLogTwo = new RecordingLog(TEMP_DIR);
assertThat(recordingLogTwo.entries().size(), is(1));
final RecordingLog.Entry actualEntry = recordingLogTwo.entries().get(0);
assertEquals(newLogPosition, actualEntry.termBaseLogPosition);
}
use of io.aeron.cluster.client.RecordingLog in project aeron by real-logic.
the class SequencerAgent method awaitCatchUp.
private void awaitCatchUp() {
if (null != recordingCatchUp) {
while (!recordingCatchUp.isCaughtUp()) {
idle();
}
recordingCatchUp.close();
final int streamId = ctx.replayStreamId();
final ChannelUri channelUri = ChannelUri.parse(ctx.replayChannel());
final long startPosition = recordingCatchUp.fromPosition();
final long stopPosition = recordingCatchUp.caughtUpPosition();
final long length = stopPosition - startPosition;
final int lastStepIndex = recoveryPlan.termSteps.size() - 1;
final RecordingLog.ReplayStep lastStep = recoveryPlan.termSteps.get(lastStepIndex);
final RecordingLog.Entry entry = lastStep.entry;
// TODO: fix up recordingLog entry for last step for on disk in case we recover again
termBaseLogPosition = entry.termBaseLogPosition;
leadershipTermId = entry.leadershipTermId;
final int logSessionId = lastStepIndex + 1;
channelUri.put(CommonContext.SESSION_ID_PARAM_NAME, Integer.toString(logSessionId));
final String channel = channelUri.toString();
final long recordingId = recordingCatchUp.recordingIdToExtend();
try (Counter counter = CommitPos.allocate(aeron, tempBuffer, leadershipTermId, termBaseLogPosition, length)) {
serviceAckCount = 0;
logAdapter = null;
if (length > 0) {
try (Subscription subscription = aeron.addSubscription(channel, streamId)) {
serviceControlPublisher.joinLog(leadershipTermId, counter.id(), logSessionId, streamId, channel);
awaitServiceAcks();
final int replaySessionId = (int) archive.startReplay(recordingId, startPosition, length, channel, streamId);
final Image image = awaitImage(replaySessionId, subscription);
serviceAckCount = 0;
replayTerm(image, stopPosition, counter);
final long termPosition = image.position();
if (lastStep.entry.termPosition < termPosition) {
recordingLog.commitLeadershipTermPosition(leadershipTermId, termPosition);
}
termBaseLogPosition = entry.termBaseLogPosition + termPosition;
}
}
}
recordingCatchUp = null;
}
}
use of io.aeron.cluster.client.RecordingLog in project aeron by real-logic.
the class RecordingLogTest method shouldCreateNewIndex.
@Test
public void shouldCreateNewIndex() {
final RecordingLog recordingLog = new RecordingLog(TEMP_DIR);
assertThat(recordingLog.entries().size(), is(0));
}
use of io.aeron.cluster.client.RecordingLog in project aeron by real-logic.
the class RecordingLogTest method shouldTombstoneEntry.
@Test
public void shouldTombstoneEntry() {
final RecordingLog recordingLog = new RecordingLog(TEMP_DIR);
final RecordingLog.Entry entryOne = new RecordingLog.Entry(NULL_VALUE, 3, 2, NULL_POSITION, 4, 0, ENTRY_TYPE_TERM, 0);
recordingLog.appendTerm(entryOne.leadershipTermId, entryOne.termBaseLogPosition, entryOne.timestamp, entryOne.votedForMemberId);
final RecordingLog.Entry entryTwo = new RecordingLog.Entry(NULL_VALUE, 4, 3, NULL_POSITION, 5, 0, ENTRY_TYPE_TERM, 0);
recordingLog.appendTerm(entryTwo.leadershipTermId, entryTwo.termBaseLogPosition, entryTwo.timestamp, entryTwo.votedForMemberId);
recordingLog.tombstoneEntry(entryTwo.leadershipTermId, recordingLog.nextEntryIndex() - 1);
final RecordingLog recordingLogTwo = new RecordingLog(TEMP_DIR);
assertThat(recordingLogTwo.entries().size(), is(1));
assertThat(recordingLogTwo.nextEntryIndex(), is(2));
}
use of io.aeron.cluster.client.RecordingLog in project aeron by real-logic.
the class RecordingLogTest method shouldAppendAndThenReloadLatestSnapshot.
@Test
public void shouldAppendAndThenReloadLatestSnapshot() {
final RecordingLog recordingLog = new RecordingLog(TEMP_DIR);
final RecordingLog.Entry entry = new RecordingLog.Entry(1, 3, 2, 777, 4, NULL_VALUE, ENTRY_TYPE_SNAPSHOT, 0);
recordingLog.appendSnapshot(entry.recordingId, entry.leadershipTermId, entry.termBaseLogPosition, 777, entry.timestamp);
final RecordingLog recordingLogTwo = new RecordingLog(TEMP_DIR);
assertThat(recordingLogTwo.entries().size(), is(1));
final RecordingLog.Entry snapshot = recordingLogTwo.getLatestSnapshot();
assertEquals(entry.toString(), snapshot.toString());
}
Aggregations