Search in sources :

Example 11 with IdRange

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));
        }
    }
}
Also used : IdRange(org.neo4j.kernel.impl.store.id.IdRange) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 12 with IdRange

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());
}
Also used : IdRange(org.neo4j.kernel.impl.store.id.IdRange) Test(org.junit.Test)

Example 13 with IdRange

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);
}
Also used : IdAllocation(org.neo4j.kernel.ha.id.IdAllocation) IdRange(org.neo4j.kernel.impl.store.id.IdRange)

Example 14 with IdRange

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);
        }
    }
}
Also used : IdRange(org.neo4j.kernel.impl.store.id.IdRange)

Aggregations

IdRange (org.neo4j.kernel.impl.store.id.IdRange)14 Test (org.junit.Test)12 RequestContext (org.neo4j.com.RequestContext)5 IdGenerator (org.neo4j.kernel.impl.store.id.IdGenerator)5 IdType (org.neo4j.kernel.impl.store.id.IdType)5 HashSet (java.util.HashSet)2 IdAllocation (org.neo4j.kernel.ha.id.IdAllocation)1