use of org.neo4j.kernel.impl.store.id.IdRange in project neo4j by neo4j.
the class IdRangeIteratorTest method shouldNotHaveAnyGaps.
@Test
public void shouldNotHaveAnyGaps() throws Exception {
// given
int rangeLength = 1024;
IdRangeIterator iterator = new IdRangeIterator(new IdRange(new long[] {}, 0, rangeLength));
// when
Set<Long> seenIds = new HashSet<>();
for (int i = 0; i < rangeLength; i++) {
seenIds.add(iterator.next());
if (i > 0) {
// then
assertTrue("Missing id " + (i - 1), seenIds.contains((long) i - 1));
}
}
}
use of org.neo4j.kernel.impl.store.id.IdRange in project neo4j by neo4j.
the class IdRangeIteratorTest method shouldReturnValueRepresentingNullIfWeExhaustIdRange.
@Test
public void shouldReturnValueRepresentingNullIfWeExhaustIdRange() throws Exception {
// given
int rangeLength = 1024;
IdRangeIterator iterator = new IdRangeIterator(new IdRange(new long[] {}, 0, rangeLength));
// when
for (int i = 0; i < rangeLength; i++) {
iterator.next();
}
// then
assertEquals(IdRangeIterator.VALUE_REPRESENTING_NULL, iterator.next());
}
use of org.neo4j.kernel.impl.store.id.IdRange 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);
}
use of org.neo4j.kernel.impl.store.id.IdRange in project neo4j by neo4j.
the class ReplicatedIdRangeAcquirer method acquireIds.
IdAllocation acquireIds(IdType idType) {
while (true) {
long firstUnallocated = idAllocationStateMachine.firstUnallocated(idType);
ReplicatedIdAllocationRequest idAllocationRequest = new ReplicatedIdAllocationRequest(me, idType, firstUnallocated, allocationSizes.get(idType));
if (replicateIdAllocationRequest(idType, idAllocationRequest)) {
IdRange idRange = new IdRange(EMPTY_LONG_ARRAY, firstUnallocated, allocationSizes.get(idType));
return new IdAllocation(idRange, -1, 0);
} else {
log.info("Retrying ID generation due to conflict. Request was: " + idAllocationRequest);
}
}
}
Aggregations