use of org.apache.ratis.shaded.proto.RaftProtos.SMLogEntryProto in project incubator-ratis by apache.
the class FileStoreStateMachine method writeStateMachineData.
@Override
public CompletableFuture<Integer> writeStateMachineData(LogEntryProto entry) {
final SMLogEntryProto smLog = entry.getSmLogEntry();
final ByteString data = smLog.getData();
final FileStoreRequestProto proto;
try {
proto = FileStoreRequestProto.parseFrom(data);
} catch (InvalidProtocolBufferException e) {
return FileStoreCommon.completeExceptionally(entry.getIndex(), "Failed to parse data, entry=" + entry, e);
}
if (proto.getRequestCase() != FileStoreRequestProto.RequestCase.WRITEHEADER) {
return null;
}
final WriteRequestHeaderProto h = proto.getWriteHeader();
final CompletableFuture<Integer> f = files.write(entry.getIndex(), h.getPath().toStringUtf8(), h.getClose(), h.getOffset(), smLog.getStateMachineData());
// sync only if closing the file
return h.getClose() ? f : null;
}
use of org.apache.ratis.shaded.proto.RaftProtos.SMLogEntryProto in project incubator-ratis by apache.
the class TestRaftLogSegment method testAppendWithGap.
@Test
public void testAppendWithGap() throws Exception {
LogSegment segment = LogSegment.newOpenSegment(null, 1000);
SimpleOperation op = new SimpleOperation("m");
final SMLogEntryProto m = op.getLogEntryContent();
try {
LogEntryProto entry = ProtoUtils.toLogEntryProto(m, 0, 1001, clientId, callId);
segment.appendToOpenSegment(entry);
Assert.fail("should fail since the entry's index needs to be 1000");
} catch (IllegalStateException e) {
// the exception is expected.
}
LogEntryProto entry = ProtoUtils.toLogEntryProto(m, 0, 1000, clientId, callId);
segment.appendToOpenSegment(entry);
try {
entry = ProtoUtils.toLogEntryProto(m, 0, 1002, clientId, callId);
segment.appendToOpenSegment(entry);
Assert.fail("should fail since the entry's index needs to be 1001");
} catch (IllegalStateException e) {
// the exception is expected.
}
LogEntryProto[] entries = new LogEntryProto[2];
for (int i = 0; i < 2; i++) {
entries[i] = ProtoUtils.toLogEntryProto(m, 0, 1001 + i * 2, clientId, callId);
}
try {
segment.appendToOpenSegment(entries);
Assert.fail("should fail since there is gap between entries");
} catch (IllegalStateException e) {
// the exception is expected.
}
}
Aggregations