Search in sources :

Example 1 with LocalOperationId

use of org.neo4j.causalclustering.core.replication.session.LocalOperationId in project neo4j by neo4j.

the class DistributedOperation method deserialize.

public static DistributedOperation deserialize(ReadableChannel channel) throws IOException, EndOfStreamException {
    long mostSigBits = channel.getLong();
    long leastSigBits = channel.getLong();
    MemberId owner = new MemberId.Marshal().unmarshal(channel);
    GlobalSession globalSession = new GlobalSession(new UUID(mostSigBits, leastSigBits), owner);
    long localSessionId = channel.getLong();
    long sequenceNumber = channel.getLong();
    LocalOperationId localOperationId = new LocalOperationId(localSessionId, sequenceNumber);
    ReplicatedContent content = new CoreReplicatedContentMarshal().unmarshal(channel);
    return new DistributedOperation(content, globalSession, localOperationId);
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) CoreReplicatedContentMarshal(org.neo4j.causalclustering.messaging.CoreReplicatedContentMarshal) GlobalSession(org.neo4j.causalclustering.core.replication.session.GlobalSession) LocalOperationId(org.neo4j.causalclustering.core.replication.session.LocalOperationId) UUID(java.util.UUID)

Example 2 with LocalOperationId

use of org.neo4j.causalclustering.core.replication.session.LocalOperationId in project neo4j by neo4j.

the class ProgressTrackerImplTest method shouldIgnoreOtherSessions.

@Test
public void shouldIgnoreOtherSessions() throws Exception {
    // given
    GlobalSession sessionB = new GlobalSession(UUID.randomUUID(), null);
    DistributedOperation aliasUnderSessionB = new DistributedOperation(ReplicatedInteger.valueOf(0), sessionB, new LocalOperationId(/* same id/sequence number as operationA */
    operationA.operationId().localSessionId(), operationA.operationId().sequenceNumber()));
    Progress progressA = tracker.start(operationA);
    // when
    tracker.trackReplication(aliasUnderSessionB);
    tracker.trackResult(aliasUnderSessionB, Result.of("result"));
    // then
    assertEquals(false, progressA.isReplicated());
    assertEquals(false, progressA.futureResult().isDone());
}
Also used : GlobalSession(org.neo4j.causalclustering.core.replication.session.GlobalSession) LocalOperationId(org.neo4j.causalclustering.core.replication.session.LocalOperationId) Test(org.junit.Test)

Example 3 with LocalOperationId

use of org.neo4j.causalclustering.core.replication.session.LocalOperationId in project neo4j by neo4j.

the class CommandApplicationProcessTest method outOfOrderDuplicatesShouldBeIgnoredButStillIncreaseCommandIndex.

@Test
public void outOfOrderDuplicatesShouldBeIgnoredButStillIncreaseCommandIndex() throws Exception {
    // given
    applicationProcess.start();
    // when
    raftLog.append(new RaftLogEntry(0, new DistributedOperation(tx((byte) 100), globalSession, new LocalOperationId(0, 0))));
    raftLog.append(new RaftLogEntry(0, new DistributedOperation(tx((byte) 101), globalSession, new LocalOperationId(0, 1))));
    raftLog.append(new RaftLogEntry(0, new DistributedOperation(tx((byte) 102), globalSession, new LocalOperationId(0, 2))));
    // duplicate of tx 101
    raftLog.append(new RaftLogEntry(0, new DistributedOperation(tx((byte) 101), globalSession, new LocalOperationId(0, 1))));
    // duplicate of tx 100
    raftLog.append(new RaftLogEntry(0, new DistributedOperation(tx((byte) 100), globalSession, new LocalOperationId(0, 0))));
    raftLog.append(new RaftLogEntry(0, new DistributedOperation(tx((byte) 103), globalSession, new LocalOperationId(0, 3))));
    raftLog.append(new RaftLogEntry(0, new DistributedOperation(tx((byte) 104), globalSession, new LocalOperationId(0, 4))));
    applicationProcess.notifyCommitted(6);
    applier.sync(false);
    InOrder inOrder = inOrder(coreStateMachines, commandDispatcher);
    // then
    inOrder.verify(coreStateMachines).commandDispatcher();
    inOrder.verify(commandDispatcher).dispatch(eq(tx((byte) 100)), eq(0L), anyCallback());
    inOrder.verify(commandDispatcher).dispatch(eq(tx((byte) 101)), eq(1L), anyCallback());
    inOrder.verify(commandDispatcher).dispatch(eq(tx((byte) 102)), eq(2L), anyCallback());
    // duplicate of tx 101 not dispatched, at index 3
    // duplicate of tx 100 not dispatched, at index 4
    inOrder.verify(commandDispatcher).dispatch(eq(tx((byte) 103)), eq(5L), anyCallback());
    inOrder.verify(commandDispatcher).dispatch(eq(tx((byte) 104)), eq(6L), anyCallback());
    inOrder.verify(commandDispatcher).close();
    verifyNoMoreInteractions(commandDispatcher);
}
Also used : InOrder(org.mockito.InOrder) LocalOperationId(org.neo4j.causalclustering.core.replication.session.LocalOperationId) DistributedOperation(org.neo4j.causalclustering.core.replication.DistributedOperation) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry) Test(org.junit.Test)

Example 4 with LocalOperationId

use of org.neo4j.causalclustering.core.replication.session.LocalOperationId in project neo4j by neo4j.

the class CommandApplicationProcessTest method duplicatesShouldBeIgnoredButStillIncreaseCommandIndex.

@Test
public void duplicatesShouldBeIgnoredButStillIncreaseCommandIndex() throws Exception {
    // given
    applicationProcess.start();
    // when
    raftLog.append(new RaftLogEntry(0, new NewLeaderBarrier()));
    raftLog.append(new RaftLogEntry(0, new DistributedOperation(nullTx, globalSession, new LocalOperationId(0, 0))));
    // duplicate
    raftLog.append(new RaftLogEntry(0, new DistributedOperation(nullTx, globalSession, new LocalOperationId(0, 0))));
    raftLog.append(new RaftLogEntry(0, new DistributedOperation(nullTx, globalSession, new LocalOperationId(0, 1))));
    applicationProcess.notifyCommitted(3);
    applier.sync(false);
    InOrder inOrder = inOrder(coreStateMachines, commandDispatcher);
    // then
    inOrder.verify(coreStateMachines).commandDispatcher();
    inOrder.verify(commandDispatcher).dispatch(eq(nullTx), eq(1L), anyCallback());
    // duplicate not dispatched
    inOrder.verify(commandDispatcher).dispatch(eq(nullTx), eq(3L), anyCallback());
    inOrder.verify(commandDispatcher).close();
    verifyNoMoreInteractions(commandDispatcher);
}
Also used : InOrder(org.mockito.InOrder) LocalOperationId(org.neo4j.causalclustering.core.replication.session.LocalOperationId) DistributedOperation(org.neo4j.causalclustering.core.replication.DistributedOperation) NewLeaderBarrier(org.neo4j.causalclustering.core.consensus.NewLeaderBarrier) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry) Test(org.junit.Test)

Aggregations

LocalOperationId (org.neo4j.causalclustering.core.replication.session.LocalOperationId)4 Test (org.junit.Test)3 InOrder (org.mockito.InOrder)2 RaftLogEntry (org.neo4j.causalclustering.core.consensus.log.RaftLogEntry)2 DistributedOperation (org.neo4j.causalclustering.core.replication.DistributedOperation)2 GlobalSession (org.neo4j.causalclustering.core.replication.session.GlobalSession)2 UUID (java.util.UUID)1 NewLeaderBarrier (org.neo4j.causalclustering.core.consensus.NewLeaderBarrier)1 MemberId (org.neo4j.causalclustering.identity.MemberId)1 CoreReplicatedContentMarshal (org.neo4j.causalclustering.messaging.CoreReplicatedContentMarshal)1