Search in sources :

Example 1 with IdAllocation

use of org.neo4j.kernel.ha.id.IdAllocation in project neo4j by neo4j.

the class MasterClient214 method allocateIds.

@Override
public Response<IdAllocation> allocateIds(RequestContext context, final IdType idType) {
    Serializer serializer = buffer -> buffer.writeByte(idType.ordinal());
    Deserializer<IdAllocation> deserializer = (buffer, temporaryBuffer) -> readIdAllocation(buffer);
    return sendRequest(requestTypes.type(HaRequestTypes.Type.ALLOCATE_IDS), context, serializer, deserializer);
}
Also used : VOID_DESERIALIZER(org.neo4j.com.Protocol.VOID_DESERIALIZER) StoreId(org.neo4j.kernel.impl.store.StoreId) IdAllocation(org.neo4j.kernel.ha.id.IdAllocation) RequestType(org.neo4j.com.RequestType) LockResult(org.neo4j.kernel.ha.lock.LockResult) ObjectSerializer(org.neo4j.com.ObjectSerializer) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) ResourceType(org.neo4j.storageengine.api.lock.ResourceType) Exceptions(org.neo4j.helpers.Exceptions) StoreWriter(org.neo4j.com.storecopy.StoreWriter) LogProvider(org.neo4j.logging.LogProvider) Serializer(org.neo4j.com.Serializer) HandshakeResult(org.neo4j.kernel.ha.com.master.HandshakeResult) IdRange(org.neo4j.kernel.impl.store.id.IdRange) RequestContext(org.neo4j.com.RequestContext) RequestMonitor(org.neo4j.com.monitor.RequestMonitor) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel) INTERNAL_PROTOCOL_VERSION(org.neo4j.com.ProtocolVersion.INTERNAL_PROTOCOL_VERSION) MasterClient(org.neo4j.kernel.ha.com.slave.MasterClient) ByteCounterMonitor(org.neo4j.kernel.monitoring.ByteCounterMonitor) Client(org.neo4j.com.Client) EMPTY_SERIALIZER(org.neo4j.com.Protocol.EMPTY_SERIALIZER) Response(org.neo4j.com.Response) Protocol(org.neo4j.com.Protocol) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) LogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader) IOException(java.io.IOException) Protocol214(org.neo4j.com.Protocol214) MasterServer(org.neo4j.kernel.ha.com.master.MasterServer) LockStatus(org.neo4j.kernel.ha.lock.LockStatus) String.format(java.lang.String.format) IdType(org.neo4j.kernel.impl.store.id.IdType) ResponseUnpacker(org.neo4j.com.storecopy.ResponseUnpacker) Protocol.writeString(org.neo4j.com.Protocol.writeString) ProtocolVersion(org.neo4j.com.ProtocolVersion) Protocol.readString(org.neo4j.com.Protocol.readString) Deserializer(org.neo4j.com.Deserializer) Master(org.neo4j.kernel.ha.com.master.Master) IdAllocation(org.neo4j.kernel.ha.id.IdAllocation) ObjectSerializer(org.neo4j.com.ObjectSerializer) Serializer(org.neo4j.com.Serializer)

Example 2 with IdAllocation

use of org.neo4j.kernel.ha.id.IdAllocation in project neo4j by neo4j.

the class MasterEpochTest method shouldFailSubsequentRequestsAfterAllocateIdsAfterMasterSwitch.

@Test
public void shouldFailSubsequentRequestsAfterAllocateIdsAfterMasterSwitch() throws Throwable {
    // GIVEN
    SPI spi = MasterImplTest.mockedSpi();
    IdAllocation servedIdAllocation = idAllocation(0, 999);
    when(spi.allocateIds(any(IdType.class))).thenReturn(servedIdAllocation);
    when(spi.getTransactionChecksum(anyLong())).thenReturn(10L);
    StoreId storeId = newStoreIdForCurrentVersion();
    MasterImpl master = new MasterImpl(spi, mock(ConversationManager.class), mock(MasterImpl.Monitor.class), Config.embeddedDefaults(stringMap(ClusterSettings.server_id.name(), "1")));
    HandshakeResult handshake = master.handshake(1, storeId).response();
    master.start();
    // WHEN/THEN
    IdAllocation idAllocation = master.allocateIds(context(handshake.epoch()), IdType.NODE).response();
    assertEquals(servedIdAllocation.getHighestIdInUse(), idAllocation.getHighestIdInUse());
    try {
        master.allocateIds(context(handshake.epoch() + 1), IdType.NODE);
        fail("Should fail with invalid epoch");
    } catch (InvalidEpochException e) {
    // Good
    }
}
Also used : HandshakeResult(org.neo4j.kernel.ha.com.master.HandshakeResult) MasterImpl(org.neo4j.kernel.ha.com.master.MasterImpl) StoreId(org.neo4j.kernel.impl.store.StoreId) ConversationManager(org.neo4j.kernel.ha.com.master.ConversationManager) IdAllocation(org.neo4j.kernel.ha.id.IdAllocation) InvalidEpochException(org.neo4j.kernel.ha.com.master.InvalidEpochException) SPI(org.neo4j.kernel.ha.com.master.MasterImpl.SPI) IdType(org.neo4j.kernel.impl.store.id.IdType) MasterImplTest(org.neo4j.kernel.ha.com.master.MasterImplTest) Test(org.junit.Test)

Example 3 with IdAllocation

use of org.neo4j.kernel.ha.id.IdAllocation in project neo4j by neo4j.

the class MasterImpl method allocateIds.

@Override
public Response<IdAllocation> allocateIds(RequestContext context, IdType idType) {
    assertCorrectEpoch(context);
    IdAllocation result = spi.allocateIds(idType);
    return spi.packEmptyResponse(result);
}
Also used : IdAllocation(org.neo4j.kernel.ha.id.IdAllocation)

Example 4 with IdAllocation

use of org.neo4j.kernel.ha.id.IdAllocation in project neo4j by neo4j.

the class MasterClient214 method readIdAllocation.

private static IdAllocation readIdAllocation(ChannelBuffer buffer) {
    int numberOfDefragIds = buffer.readInt();
    long[] defragIds = new long[numberOfDefragIds];
    for (int i = 0; i < numberOfDefragIds; i++) {
        defragIds[i] = buffer.readLong();
    }
    long rangeStart = buffer.readLong();
    int rangeLength = buffer.readInt();
    long highId = buffer.readLong();
    long defragCount = buffer.readLong();
    return new IdAllocation(new IdRange(defragIds, rangeStart, rangeLength), highId, defragCount);
}
Also used : IdAllocation(org.neo4j.kernel.ha.id.IdAllocation) IdRange(org.neo4j.kernel.impl.store.id.IdRange)

Aggregations

IdAllocation (org.neo4j.kernel.ha.id.IdAllocation)4 HandshakeResult (org.neo4j.kernel.ha.com.master.HandshakeResult)2 StoreId (org.neo4j.kernel.impl.store.StoreId)2 IdRange (org.neo4j.kernel.impl.store.id.IdRange)2 IdType (org.neo4j.kernel.impl.store.id.IdType)2 IOException (java.io.IOException)1 String.format (java.lang.String.format)1 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)1 Test (org.junit.Test)1 Client (org.neo4j.com.Client)1 Deserializer (org.neo4j.com.Deserializer)1 ObjectSerializer (org.neo4j.com.ObjectSerializer)1 Protocol (org.neo4j.com.Protocol)1 EMPTY_SERIALIZER (org.neo4j.com.Protocol.EMPTY_SERIALIZER)1 VOID_DESERIALIZER (org.neo4j.com.Protocol.VOID_DESERIALIZER)1 Protocol.readString (org.neo4j.com.Protocol.readString)1 Protocol.writeString (org.neo4j.com.Protocol.writeString)1 Protocol214 (org.neo4j.com.Protocol214)1 ProtocolVersion (org.neo4j.com.ProtocolVersion)1 INTERNAL_PROTOCOL_VERSION (org.neo4j.com.ProtocolVersion.INTERNAL_PROTOCOL_VERSION)1