Search in sources :

Example 1 with SMLogEntryProto

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;
}
Also used : SMLogEntryProto(org.apache.ratis.shaded.proto.RaftProtos.SMLogEntryProto) ByteString(org.apache.ratis.shaded.com.google.protobuf.ByteString) InvalidProtocolBufferException(org.apache.ratis.shaded.com.google.protobuf.InvalidProtocolBufferException)

Example 2 with SMLogEntryProto

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.
    }
}
Also used : SMLogEntryProto(org.apache.ratis.shaded.proto.RaftProtos.SMLogEntryProto) SMLogEntryProto(org.apache.ratis.shaded.proto.RaftProtos.SMLogEntryProto) LogEntryProto(org.apache.ratis.shaded.proto.RaftProtos.LogEntryProto) SimpleOperation(org.apache.ratis.RaftTestUtil.SimpleOperation) Test(org.junit.Test) BaseTest(org.apache.ratis.BaseTest)

Aggregations

SMLogEntryProto (org.apache.ratis.shaded.proto.RaftProtos.SMLogEntryProto)2 BaseTest (org.apache.ratis.BaseTest)1 SimpleOperation (org.apache.ratis.RaftTestUtil.SimpleOperation)1 ByteString (org.apache.ratis.shaded.com.google.protobuf.ByteString)1 InvalidProtocolBufferException (org.apache.ratis.shaded.com.google.protobuf.InvalidProtocolBufferException)1 LogEntryProto (org.apache.ratis.shaded.proto.RaftProtos.LogEntryProto)1 Test (org.junit.Test)1