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);
}
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
}
}
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);
}
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);
}
Aggregations