Search in sources :

Example 1 with ReplicatedIdAllocationRequest

use of org.neo4j.causalclustering.core.state.machines.id.ReplicatedIdAllocationRequest in project neo4j by neo4j.

the class SegmentedRaftLogPartialEntryRecoveryTest method incompleteEntriesAtTheEndShouldNotCauseFailures.

@Test
public void incompleteEntriesAtTheEndShouldNotCauseFailures() throws Throwable {
    // Given
    // we use a RaftLog to create a raft log file and then we will start chopping bits off from the end
    SegmentedRaftLog raftLog = createRaftLog(100_000);
    raftLog.start();
    // Add a bunch of entries, preferably one of each available kind.
    raftLog.append(new RaftLogEntry(4, new NewLeaderBarrier()));
    raftLog.append(new RaftLogEntry(4, new ReplicatedIdAllocationRequest(new MemberId(UUID.randomUUID()), IdType.RELATIONSHIP, 1, 1024)));
    raftLog.append(new RaftLogEntry(4, new ReplicatedIdAllocationRequest(new MemberId(UUID.randomUUID()), IdType.RELATIONSHIP, 1025, 1024)));
    raftLog.append(new RaftLogEntry(4, new ReplicatedLockTokenRequest(new MemberId(UUID.randomUUID()), 1)));
    raftLog.append(new RaftLogEntry(4, new NewLeaderBarrier()));
    raftLog.append(new RaftLogEntry(5, new ReplicatedTokenRequest(TokenType.LABEL, "labelToken", new byte[] { 1, 2, 3 })));
    raftLog.append(new RaftLogEntry(5, new ReplicatedTransaction(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 })));
    raftLog.stop();
    // We use a temporary RecoveryProtocol to get the file to chop
    RecoveryProtocol recovery = createRecoveryProtocol();
    State recoveryState = recovery.run();
    String logFilename = recoveryState.segments.last().getFilename();
    File logFile = new File(logDirectory, logFilename);
    // When
    // We remove any number of bytes from the end (up to but not including the header) and try to recover
    // Then
    // No exceptions should be thrown
    truncateAndRecover(logFile, SegmentHeader.SIZE);
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) ReplicatedLockTokenRequest(org.neo4j.causalclustering.core.state.machines.locks.ReplicatedLockTokenRequest) ReplicatedTokenRequest(org.neo4j.causalclustering.core.state.machines.token.ReplicatedTokenRequest) ReplicatedIdAllocationRequest(org.neo4j.causalclustering.core.state.machines.id.ReplicatedIdAllocationRequest) ReplicatedTransaction(org.neo4j.causalclustering.core.state.machines.tx.ReplicatedTransaction) NewLeaderBarrier(org.neo4j.causalclustering.core.consensus.NewLeaderBarrier) File(java.io.File) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry) Test(org.junit.Test)

Example 2 with ReplicatedIdAllocationRequest

use of org.neo4j.causalclustering.core.state.machines.id.ReplicatedIdAllocationRequest in project neo4j by neo4j.

the class RaftContentByteBufferMarshalTest method shouldSerializeIdRangeRequest.

@Test
public void shouldSerializeIdRangeRequest() throws Exception {
    // given
    CoreReplicatedContentMarshal serializer = new CoreReplicatedContentMarshal();
    ReplicatedContent in = new ReplicatedIdAllocationRequest(memberId, IdType.NODE, 100, 200);
    // when
    ByteBuf buf = Unpooled.buffer();
    assertMarshalingEquality(serializer, buf, in);
}
Also used : CoreReplicatedContentMarshal(org.neo4j.causalclustering.messaging.CoreReplicatedContentMarshal) ReplicatedIdAllocationRequest(org.neo4j.causalclustering.core.state.machines.id.ReplicatedIdAllocationRequest) ReplicatedContent(org.neo4j.causalclustering.core.replication.ReplicatedContent) ByteBuf(io.netty.buffer.ByteBuf) NetworkFlushableByteBuf(org.neo4j.causalclustering.messaging.NetworkFlushableByteBuf) Test(org.junit.Test)

Example 3 with ReplicatedIdAllocationRequest

use of org.neo4j.causalclustering.core.state.machines.id.ReplicatedIdAllocationRequest in project neo4j by neo4j.

the class CoreReplicatedContentMarshalTest method shouldMarshalIdRangeRequest.

@Test
public void shouldMarshalIdRangeRequest() throws Exception {
    ByteBuf buffer = Unpooled.buffer();
    ReplicatedContent message = new ReplicatedIdAllocationRequest(new MemberId(UUID.randomUUID()), IdType.PROPERTY, 100, 200);
    assertMarshalingEquality(buffer, message);
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) ReplicatedIdAllocationRequest(org.neo4j.causalclustering.core.state.machines.id.ReplicatedIdAllocationRequest) ByteBuf(io.netty.buffer.ByteBuf) NetworkFlushableByteBuf(org.neo4j.causalclustering.messaging.NetworkFlushableByteBuf) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 ReplicatedIdAllocationRequest (org.neo4j.causalclustering.core.state.machines.id.ReplicatedIdAllocationRequest)3 ByteBuf (io.netty.buffer.ByteBuf)2 MemberId (org.neo4j.causalclustering.identity.MemberId)2 NetworkFlushableByteBuf (org.neo4j.causalclustering.messaging.NetworkFlushableByteBuf)2 File (java.io.File)1 NewLeaderBarrier (org.neo4j.causalclustering.core.consensus.NewLeaderBarrier)1 RaftLogEntry (org.neo4j.causalclustering.core.consensus.log.RaftLogEntry)1 ReplicatedContent (org.neo4j.causalclustering.core.replication.ReplicatedContent)1 ReplicatedLockTokenRequest (org.neo4j.causalclustering.core.state.machines.locks.ReplicatedLockTokenRequest)1 ReplicatedTokenRequest (org.neo4j.causalclustering.core.state.machines.token.ReplicatedTokenRequest)1 ReplicatedTransaction (org.neo4j.causalclustering.core.state.machines.tx.ReplicatedTransaction)1 CoreReplicatedContentMarshal (org.neo4j.causalclustering.messaging.CoreReplicatedContentMarshal)1