use of org.apache.ignite.raft.jraft.entity.LogEntry in project ignite-3 by apache.
the class NodeImpl method logEntryFromMeta.
private LogEntry logEntryFromMeta(final long index, final ByteBuffer allData, final RaftOutter.EntryMeta entry) {
if (entry.type() != EnumOutter.EntryType.ENTRY_TYPE_UNKNOWN) {
final LogEntry logEntry = new LogEntry();
logEntry.setId(new LogId(index, entry.term()));
logEntry.setType(entry.type());
if (entry.hasChecksum())
// since 1.2.6
logEntry.setChecksum(entry.checksum());
final long dataLen = entry.dataLen();
if (dataLen > 0) {
final byte[] bs = new byte[(int) dataLen];
assert allData != null;
allData.get(bs, 0, bs.length);
logEntry.setData(ByteBuffer.wrap(bs));
}
if (entry.peersList() != null) {
if (entry.type() != EnumOutter.EntryType.ENTRY_TYPE_CONFIGURATION) {
throw new IllegalStateException("Invalid log entry that contains peers but is not ENTRY_TYPE_CONFIGURATION type: " + entry.type());
}
fillLogEntryPeers(entry, logEntry);
} else if (entry.type() == EnumOutter.EntryType.ENTRY_TYPE_CONFIGURATION) {
throw new IllegalStateException("Invalid log entry that contains zero peers but is ENTRY_TYPE_CONFIGURATION type");
}
return logEntry;
}
return null;
}
use of org.apache.ignite.raft.jraft.entity.LogEntry in project ignite-3 by apache.
the class BaseLogEntryCodecFactoryTest method testEncodeDecodeWithData.
@Test
public void testEncodeDecodeWithData() {
ByteBuffer buf = ByteBuffer.wrap("hello".getBytes(UTF_8));
LogEntry entry = new LogEntry(EnumOutter.EntryType.ENTRY_TYPE_NO_OP);
entry.setId(new LogId(100, 3));
entry.setChecksum(123456L);
entry.setData(buf);
entry.setPeers(Arrays.asList(new PeerId("localhost", 99, 1), new PeerId("localhost", 100, 2)));
entry.setOldPeers(Arrays.asList(new PeerId("localhost", 99, 1), new PeerId("localhost", 100, 2)));
entry.setLearners(Arrays.asList(new PeerId("localhost", 99, 1), new PeerId("localhost", 100, 2)));
entry.setOldLearners(Arrays.asList(new PeerId("localhost", 99, 1), new PeerId("localhost", 100, 2)));
assertEquals(buf, entry.getData());
byte[] content = this.encoder.encode(entry);
assertNotNull(content);
assertTrue(content.length > 0);
LogEntry nentry = this.decoder.decode(content);
assertNotNull(nentry);
assertEquals(100, nentry.getId().getIndex());
assertEquals(3, nentry.getId().getTerm());
assertEquals(123456L, nentry.getChecksum());
List<PeerId> peers = nentry.getPeers();
assertEquals(2, peers.size());
assertEquals("localhost:99:1", peers.get(0).toString());
assertEquals("localhost:100:2", peers.get(1).toString());
peers = nentry.getOldPeers();
assertEquals(2, peers.size());
assertEquals("localhost:99:1", peers.get(0).toString());
assertEquals("localhost:100:2", peers.get(1).toString());
peers = nentry.getLearners();
assertEquals(2, peers.size());
assertEquals("localhost:99:1", peers.get(0).toString());
assertEquals("localhost:100:2", peers.get(1).toString());
peers = nentry.getOldLearners();
assertEquals(2, peers.size());
assertEquals("localhost:99:1", peers.get(0).toString());
assertEquals("localhost:100:2", peers.get(1).toString());
assertEquals(buf, nentry.getData());
assertEquals(0, nentry.getData().position());
assertEquals(5, nentry.getData().remaining());
}
use of org.apache.ignite.raft.jraft.entity.LogEntry in project ignite-3 by apache.
the class BaseLogEntryCodecFactoryTest method testEncodeDecodeWithoutData.
@Test
public void testEncodeDecodeWithoutData() {
LogEntry entry = new LogEntry(EnumOutter.EntryType.ENTRY_TYPE_NO_OP);
entry.setId(new LogId(100, 3));
entry.setPeers(Arrays.asList(new PeerId("localhost", 99, 1), new PeerId("localhost", 100, 2)));
assertNull(entry.getData());
assertNull(entry.getOldPeers());
byte[] content = this.encoder.encode(entry);
assertNotNull(content);
assertTrue(content.length > 0);
LogEntry nentry = this.decoder.decode(content);
assertNotNull(nentry);
assertEquals(100, nentry.getId().getIndex());
assertEquals(3, nentry.getId().getTerm());
assertEquals(EnumOutter.EntryType.ENTRY_TYPE_NO_OP, nentry.getType());
assertEquals(2, nentry.getPeers().size());
assertEquals("localhost:99:1", nentry.getPeers().get(0).toString());
assertEquals("localhost:100:2", nentry.getPeers().get(1).toString());
assertNull(nentry.getData());
assertNull(nentry.getOldPeers());
}
use of org.apache.ignite.raft.jraft.entity.LogEntry in project ignite-3 by apache.
the class LogEntryCodecPerfTest method testEncodeDecode.
private void testEncodeDecode(final LogEntryEncoder encoder, final LogEntryDecoder decoder, final CyclicBarrier barrier) throws Exception {
ByteBuffer buf = ByteBuffer.wrap(DATA);
LogEntry entry = new LogEntry(EnumOutter.EntryType.ENTRY_TYPE_NO_OP);
entry.setData(buf);
entry.setPeers(Arrays.asList(new PeerId("localhost", 99, 1), new PeerId("localhost", 100, 2)));
if (barrier != null) {
barrier.await();
}
for (int i = 0; i < TIMES; i++) {
entry.setId(new LogId(i, i));
byte[] content = encoder.encode(entry);
assert (content.length > 0);
this.logSize.addAndGet(content.length);
LogEntry nLog = decoder.decode(content);
assertEquals(2, nLog.getPeers().size());
assertArrayEquals(DATA, nLog.getData().array());
assertEquals(i, nLog.getId().getIndex());
assertEquals(i, nLog.getId().getTerm());
}
if (barrier != null) {
barrier.await();
}
}
use of org.apache.ignite.raft.jraft.entity.LogEntry in project ignite-3 by apache.
the class LogManagerTest method testSetAppliedId.
@Test
public void testSetAppliedId() 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