use of org.apache.ignite.raft.jraft.entity.LogEntry in project ignite-3 by apache.
the class LogManagerTest method testAppendEntriesBeforeAppliedIndex.
@Test
public void testAppendEntriesBeforeAppliedIndex() throws Exception {
// Append 0-10
List<LogEntry> mockEntries = TestUtils.mockEntries(10);
for (int i = 0; i < 10; i++) {
mockEntries.get(i).getId().setTerm(1);
}
final CountDownLatch latch1 = new CountDownLatch(1);
this.logManager.appendEntries(new ArrayList<>(mockEntries), new LogManager.StableClosure() {
@Override
public void run(final Status status) {
assertTrue(status.isOk());
latch1.countDown();
}
});
latch1.await();
assertEquals(1, this.logManager.getFirstLogIndex());
assertEquals(10, this.logManager.getLastLogIndex());
// waiting for setDiskId()
Thread.sleep(200);
this.logManager.setAppliedId(new LogId(9, 1));
for (int i = 0; i < 10; i++) {
assertNull(this.logManager.getEntryFromMemory(i));
}
// append 1-10 again, already applied, returns OK.
final CountDownLatch latch2 = new CountDownLatch(1);
mockEntries = TestUtils.mockEntries(10);
mockEntries.remove(0);
this.logManager.appendEntries(new ArrayList<>(mockEntries), new LogManager.StableClosure() {
@Override
public void run(final Status status) {
assertTrue(status.isOk());
latch2.countDown();
}
});
latch2.await();
assertEquals(1, this.logManager.getFirstLogIndex());
assertEquals(10, this.logManager.getLastLogIndex());
}
use of org.apache.ignite.raft.jraft.entity.LogEntry in project ignite-3 by apache.
the class NodeImpl method readCommittedUserLog.
@Override
public UserLog readCommittedUserLog(final long index) {
if (index <= 0) {
throw new LogIndexOutOfBoundsException("Request index is invalid: " + index);
}
final long savedLastAppliedIndex = this.fsmCaller.getLastAppliedIndex();
if (index > savedLastAppliedIndex) {
throw new LogIndexOutOfBoundsException("Request index " + index + " is greater than lastAppliedIndex: " + savedLastAppliedIndex);
}
long curIndex = index;
LogEntry entry = this.logManager.getEntry(curIndex);
if (entry == null) {
throw new LogNotFoundException("User log is deleted at index: " + index);
}
do {
if (entry.getType() == EnumOutter.EntryType.ENTRY_TYPE_DATA) {
return new UserLog(curIndex, entry.getData());
} else {
curIndex++;
}
if (curIndex > savedLastAppliedIndex) {
throw new IllegalStateException("No user log between index:" + index + " and last_applied_index:" + savedLastAppliedIndex);
}
entry = this.logManager.getEntry(curIndex);
} while (entry != null);
throw new LogNotFoundException("User log is deleted at index: " + curIndex);
}
use of org.apache.ignite.raft.jraft.entity.LogEntry in project ignite-3 by apache.
the class ReplicatorTest method createEntriesRequest.
private RpcRequests.AppendEntriesRequest createEntriesRequest(final int n) {
final AppendEntriesRequestBuilder rb = raftOptions.getRaftMessagesFactory().appendEntriesRequest().groupId("test").serverId(new PeerId("localhost", 8082).toString()).peerId(this.peerId.toString()).term(1).prevLogIndex(10).prevLogTerm(1).committedIndex(0);
List<RaftOutter.EntryMeta> entries = new ArrayList<>();
for (int i = 0; i < n; i++) {
final LogEntry log = new LogEntry(EnumOutter.EntryType.ENTRY_TYPE_DATA);
log.setData(ByteBuffer.wrap(new byte[i]));
log.setId(new LogId(i + 11, 1));
Mockito.when(this.logManager.getEntry(i + 11)).thenReturn(log);
Mockito.when(this.logManager.getTerm(i + 11)).thenReturn(1L);
entries.add(raftOptions.getRaftMessagesFactory().entryMeta().dataLen(i).term(1).type(EnumOutter.EntryType.ENTRY_TYPE_DATA).build());
}
rb.entriesList(entries);
return rb.build();
}
use of org.apache.ignite.raft.jraft.entity.LogEntry in project ignite-3 by apache.
the class FSMCallerTest method testOnCommitted.
@Test
public void testOnCommitted() throws Exception {
final LogEntry log = new LogEntry(EntryType.ENTRY_TYPE_DATA);
log.getId().setIndex(11);
log.getId().setTerm(1);
Mockito.when(this.logManager.getTerm(11)).thenReturn(1L);
Mockito.when(this.logManager.getEntry(11)).thenReturn(log);
final ArgumentCaptor<Iterator> itArg = ArgumentCaptor.forClass(Iterator.class);
assertTrue(this.fsmCaller.onCommitted(11));
this.fsmCaller.flush();
assertEquals(this.fsmCaller.getLastAppliedIndex(), 11);
Mockito.verify(this.fsm).onApply(itArg.capture());
final Iterator it = itArg.getValue();
assertFalse(it.hasNext());
assertEquals(it.getIndex(), 12);
Mockito.verify(this.logManager).setAppliedId(new LogId(11, 1));
assertTrue(this.fsmCaller.getError().getStatus().isOk());
}
use of org.apache.ignite.raft.jraft.entity.LogEntry in project ignite-3 by apache.
the class IteratorImplTest method setup.
@BeforeEach
public void setup() {
this.applyingIndex = new AtomicLong(0);
this.closures = new ArrayList<>();
for (int i = 0; i < 11; i++) {
this.closures.add(new MockClosure());
final LogEntry log = new LogEntry(EnumOutter.EntryType.ENTRY_TYPE_NO_OP);
log.getId().setIndex(i);
log.getId().setTerm(1);
Mockito.when(this.logManager.getEntry(i)).thenReturn(log);
}
NodeOptions nodeOptions = new NodeOptions();
executor = JRaftUtils.createExecutor("test-executor", Utils.cpus());
nodeOptions.setCommonExecutor(executor);
this.iter = new IteratorImpl(fsm, logManager, closures, 0L, 0L, 10L, applyingIndex, nodeOptions);
}
Aggregations