use of org.apache.ignite.raft.jraft.entity.LogId in project ignite-3 by apache.
the class FSMCallerImpl method doCommitted.
private void doCommitted(final long committedIndex) {
if (!this.error.getStatus().isOk()) {
return;
}
final long lastAppliedIndex = this.lastAppliedIndex.get();
// We can tolerate the disorder of committed_index
if (lastAppliedIndex >= committedIndex) {
return;
}
final long startMs = Utils.monotonicMs();
try {
final List<Closure> closures = new ArrayList<>();
final List<TaskClosure> taskClosures = new ArrayList<>();
final long firstClosureIndex = this.closureQueue.popClosureUntil(committedIndex, closures, taskClosures);
// Calls TaskClosure#onCommitted if necessary
onTaskCommitted(taskClosures);
Requires.requireTrue(firstClosureIndex >= 0, "Invalid firstClosureIndex");
final IteratorImpl iterImpl = new IteratorImpl(this.fsm, this.logManager, closures, firstClosureIndex, lastAppliedIndex, committedIndex, this.applyingIndex, this.node.getOptions());
while (iterImpl.isGood()) {
final LogEntry logEntry = iterImpl.entry();
if (logEntry.getType() != EnumOutter.EntryType.ENTRY_TYPE_DATA) {
if (logEntry.getType() == EnumOutter.EntryType.ENTRY_TYPE_CONFIGURATION) {
if (logEntry.getOldPeers() != null && !logEntry.getOldPeers().isEmpty()) {
// Joint stage is not supposed to be noticeable by end users.
this.fsm.onConfigurationCommitted(new Configuration(iterImpl.entry().getPeers()));
}
}
if (iterImpl.done() != null) {
// For other entries, we have nothing to do besides flush the
// pending tasks and run this closure to notify the caller that the
// entries before this one were successfully committed and applied.
iterImpl.done().run(Status.OK());
}
iterImpl.next();
continue;
}
// Apply data task to user state machine
doApplyTasks(iterImpl);
}
if (iterImpl.hasError()) {
setError(iterImpl.getError());
iterImpl.runTheRestClosureWithError();
}
final long lastIndex = iterImpl.getIndex() - 1;
final long lastTerm = this.logManager.getTerm(lastIndex);
final LogId lastAppliedId = new LogId(lastIndex, lastTerm);
this.lastAppliedIndex.set(lastIndex);
this.lastAppliedTerm = lastTerm;
this.logManager.setAppliedId(lastAppliedId);
notifyLastAppliedIndexUpdated(lastIndex);
} finally {
this.nodeMetrics.recordLatency("fsm-commit", Utils.monotonicMs() - startMs);
}
}
use of org.apache.ignite.raft.jraft.entity.LogId in project ignite-3 by apache.
the class BaseLogStorageTest method testLoadWithConfigManager.
@Test
public void testLoadWithConfigManager() {
assertTrue(this.confManager.getLastConfiguration().isEmpty());
final LogEntry confEntry1 = new LogEntry(EnumOutter.EntryType.ENTRY_TYPE_CONFIGURATION);
confEntry1.setId(new LogId(99, 1));
confEntry1.setPeers(JRaftUtils.getConfiguration("localhost:8081,localhost:8082").listPeers());
final LogEntry confEntry2 = new LogEntry(EnumOutter.EntryType.ENTRY_TYPE_CONFIGURATION);
confEntry2.setId(new LogId(100, 2));
confEntry2.setPeers(JRaftUtils.getConfiguration("localhost:8081,localhost:8082,localhost:8083").listPeers());
assertTrue(this.logStorage.appendEntry(confEntry1));
assertEquals(1, this.logStorage.appendEntries(Arrays.asList(confEntry2)));
// reload log storage.
if (this.logStorage instanceof RocksDBLogStorage) {
this.logStorage.shutdown();
this.logStorage = newLogStorage();
this.logStorage.init(newLogStorageOptions());
ConfigurationEntry conf = this.confManager.getLastConfiguration();
assertNotNull(conf);
assertFalse(conf.isEmpty());
assertEquals("localhost:8081,localhost:8082,localhost:8083", conf.getConf().toString());
conf = this.confManager.get(99);
assertNotNull(conf);
assertFalse(conf.isEmpty());
assertEquals("localhost:8081,localhost:8082", conf.getConf().toString());
}
}
use of org.apache.ignite.raft.jraft.entity.LogId in project ignite-3 by apache.
the class LogManagerTest method testAppendOneEntry.
@Test
public void testAppendOneEntry() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
final LogEntry entry = TestUtils.mockEntry(1, 1);
final List<LogEntry> entries = new ArrayList<>();
entries.add(entry);
this.logManager.appendEntries(entries, new LogManager.StableClosure() {
@Override
public void run(final Status status) {
assertTrue(status.isOk());
latch.countDown();
}
});
latch.await();
assertEquals(1, this.logManager.getFirstLogIndex());
assertEquals(1, this.logManager.getLastLogIndex());
assertEquals(entry, this.logManager.getEntry(1));
assertEquals(1, this.logManager.getLastLogIndex(true));
LogId lastLogId = this.logManager.getLastLogId(true);
assertEquals(1, lastLogId.getIndex());
lastLogId = this.logManager.getLastLogId(false);
assertEquals(1, lastLogId.getIndex());
assertTrue(this.logManager.checkConsistency().isOk());
}
use of org.apache.ignite.raft.jraft.entity.LogId in project ignite-3 by apache.
the class LogManagerTest method testCheckAndSetConfiguration.
@Test
public void testCheckAndSetConfiguration() throws Exception {
assertNull(this.logManager.checkAndSetConfiguration(null));
final ConfigurationEntry entry = new ConfigurationEntry();
entry.setId(new LogId(0, 1));
entry.setConf(JRaftUtils.getConfiguration("localhost:8081,localhost:8082"));
assertSame(entry, this.logManager.checkAndSetConfiguration(entry));
testGetConfiguration();
final ConfigurationEntry lastEntry = this.logManager.checkAndSetConfiguration(entry);
assertNotSame(entry, lastEntry);
assertEquals("localhost:8081,localhost:8082,localhost:8083", lastEntry.getConf().toString());
assertEquals("localhost:8081,localhost:8082", lastEntry.getOldConf().toString());
}
use of org.apache.ignite.raft.jraft.entity.LogId in project ignite-3 by apache.
the class LogManagerTest method testSetAppliedId2.
@Test
public void testSetAppliedId2() throws Exception {
final List<LogEntry> mockEntries = mockAddEntries();
for (int i = 0; i < 10; i++) {
// it's in memory
assertEquals(mockEntries.get(i), this.logManager.getEntryFromMemory(i + 1));
}
// waiting for setDiskId()
Thread.sleep(200);
this.logManager.setAppliedId(new LogId(10, 10));
for (int i = 0; i < 10; i++) {
assertNull(this.logManager.getEntryFromMemory(i + 1));
assertEquals(mockEntries.get(i), this.logManager.getEntry(i + 1));
}
}
Aggregations