Search in sources :

Example 1 with IdSequence

use of org.neo4j.internal.id.IdSequence in project neo4j by neo4j.

the class SecondaryUnitPrepareIdSequenceTest method shouldReturnIdImmediatelyAfterRecordIdOnlyOnce.

@Test
void shouldReturnIdImmediatelyAfterRecordIdOnlyOnce() {
    // given
    PrepareIdSequence idSequence = new SecondaryUnitPrepareIdSequence();
    IdSequence actual = mock(IdSequence.class);
    // when
    long recordId = 10;
    IdSequence prepared = idSequence.apply(actual).apply(recordId);
    long nextRecordId = prepared.nextId(NULL);
    assertEquals(10 + 1, nextRecordId);
    verifyNoMoreInteractions(actual);
    try {
        prepared.nextId(NULL);
        fail("Should've failed");
    } catch (IllegalStateException e) {
    // good
    }
    // and when
    recordId = 20;
    prepared = idSequence.apply(actual).apply(recordId);
    nextRecordId = prepared.nextId(NULL);
    // then
    assertEquals(20 + 1, nextRecordId);
    verifyNoMoreInteractions(actual);
}
Also used : IdSequence(org.neo4j.internal.id.IdSequence) Test(org.junit.jupiter.api.Test)

Example 2 with IdSequence

use of org.neo4j.internal.id.IdSequence in project neo4j by neo4j.

the class SecondaryUnitPrepareIdSequenceTest method shouldReturnIdImmediatelyAfterRecordId.

@Test
void shouldReturnIdImmediatelyAfterRecordId() {
    // given
    PrepareIdSequence idSequence = new SecondaryUnitPrepareIdSequence();
    IdSequence actual = mock(IdSequence.class);
    // when
    long recordId = 10;
    IdSequence prepared = idSequence.apply(actual).apply(recordId);
    long nextRecordId = prepared.nextId(NULL);
    // then
    assertEquals(10 + 1, nextRecordId);
    verifyNoMoreInteractions(actual);
}
Also used : IdSequence(org.neo4j.internal.id.IdSequence) Test(org.junit.jupiter.api.Test)

Example 3 with IdSequence

use of org.neo4j.internal.id.IdSequence in project neo4j by neo4j.

the class NodeRecordTest method shouldToStringBothUsedAndUnusedDynamicLabelRecords.

@Test
void shouldToStringBothUsedAndUnusedDynamicLabelRecords() {
    // GIVEN
    IdSequence ids = mock(IdSequence.class);
    when(ids.nextId(NULL)).thenReturn(1L, 2L);
    ReusableRecordsAllocator recordAllocator = new ReusableRecordsAllocator(30, new DynamicRecord(1), new DynamicRecord(2));
    NodeRecord node = newUsedNodeRecord(0);
    long labelId = 10_123;
    // A dynamic label record
    Collection<DynamicRecord> existing = allocateRecordsForDynamicLabels(node.getId(), new long[] { labelId }, recordAllocator, NULL, INSTANCE);
    // and a deleted one as well (simulating some deleted labels)
    DynamicRecord unused = newDeletedDynamicRecord(ids.nextId(NULL));
    unused.setInUse(false);
    existing.add(unused);
    node.setLabelField(dynamicPointer(existing), existing);
    // WHEN
    String toString = node.toString();
    // THEN
    assertThat(toString).contains(String.valueOf(labelId));
    assertThat(toString).contains(unused.toString());
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) IdSequence(org.neo4j.internal.id.IdSequence) ReusableRecordsAllocator(org.neo4j.kernel.impl.store.allocator.ReusableRecordsAllocator) Test(org.junit.jupiter.api.Test)

Example 4 with IdSequence

use of org.neo4j.internal.id.IdSequence in project neo4j by neo4j.

the class UpdateRecordsStep method process.

@Override
protected void process(RECORD[] batch, BatchSender sender, CursorContext cursorContext) {
    LongFunction<IdSequence> idSequence = prepareIdSequence.apply(store);
    int recordsUpdatedInThisBatch = 0;
    try (PageCursor cursor = store.openPageCursorForWriting(0, cursorContext)) {
        for (RECORD record : batch) {
            if (record != null && record.inUse() && !IdValidator.isReservedId(record.getId())) {
                store.prepareForCommit(record, idSequence.apply(record.getId()), cursorContext);
                // Don't update id generators because at the time of writing this they require special handling for multi-threaded updates
                // instead just note the highId. It will be mostly correct in the end.
                store.updateRecord(record, IGNORE, cursor, cursorContext);
                recordsUpdatedInThisBatch++;
            }
        }
    }
    recordsUpdated.add(recordsUpdatedInThisBatch);
}
Also used : IdSequence(org.neo4j.internal.id.IdSequence) PrepareIdSequence(org.neo4j.internal.batchimport.store.PrepareIdSequence) PageCursor(org.neo4j.io.pagecache.PageCursor)

Example 5 with IdSequence

use of org.neo4j.internal.id.IdSequence in project neo4j by neo4j.

the class RelationshipModifierTest method setUp.

@BeforeEach
void setUp() {
    RelationshipGroupGetter relationshipGroupGetter = new RelationshipGroupGetter(idSequence(), CursorContext.NULL);
    PropertyDeleter propertyDeleter = new PropertyDeleter(new PropertyTraverser(CursorContext.NULL), null, null, NullLogProvider.nullLogProvider(), Config.defaults(), CursorContext.NULL, EmptyMemoryTracker.INSTANCE);
    modifier = new RelationshipModifier(relationshipGroupGetter, propertyDeleter, DENSE_THRESHOLD - 1, /*because the trigger happens on > */
    true, CursorContext.NULL, EmptyMemoryTracker.INSTANCE);
    monitors = new Monitors(null, (t, m) -> {
        Exceptions.throwIfUnchecked(t);
        throw new RuntimeException(t);
    });
    locks = new TrackingResourceLocker(random, monitors.newMonitor(TrackingResourceLocker.LockAcquisitionMonitor.class));
    txState = mock(ReadableTransactionState.class);
    store = new MapRecordStore();
    monitors.addMonitorListener(new LockVerificationMonitor(locks, txState, store));
    groupUpdater = new GroupUpdater(store);
}
Also used : RelationshipModifications(org.neo4j.storageengine.api.txstate.RelationshipModifications) BeforeEach(org.junit.jupiter.api.BeforeEach) Record.isNull(org.neo4j.kernel.impl.store.record.Record.isNull) RepeatedTest(org.junit.jupiter.api.RepeatedTest) MutableInt(org.apache.commons.lang3.mutable.MutableInt) ArrayUtil.indexOf(org.neo4j.internal.helpers.ArrayUtil.indexOf) LongSupplier(java.util.function.LongSupplier) RandomExtension(org.neo4j.test.extension.RandomExtension) OUTGOING(org.neo4j.storageengine.api.RelationshipDirection.OUTGOING) CursorContext(org.neo4j.io.pagecache.context.CursorContext) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Config(org.neo4j.configuration.Config) LockType(org.neo4j.lock.LockType) GroupDegreeCommand.combinedKeyOnGroupAndDirection(org.neo4j.internal.recordstorage.Command.GroupDegreeCommand.combinedKeyOnGroupAndDirection) NullLogProvider(org.neo4j.logging.NullLogProvider) IdSequence(org.neo4j.internal.id.IdSequence) Collections.singletonList(java.util.Collections.singletonList) NO_LABELS_FIELD(org.neo4j.kernel.impl.store.record.Record.NO_LABELS_FIELD) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Monitors(org.neo4j.monitoring.Monitors) RandomRule(org.neo4j.test.rule.RandomRule) MutableLong(org.apache.commons.lang3.mutable.MutableLong) Map(java.util.Map) RelationshipData(org.neo4j.internal.recordstorage.FlatRelationshipModifications.RelationshipData) FlatRelationshipModifications.relationship(org.neo4j.internal.recordstorage.FlatRelationshipModifications.relationship) EXCLUSIVE(org.neo4j.lock.LockType.EXCLUSIVE) Exceptions(org.neo4j.internal.helpers.Exceptions) RELATIONSHIP_GROUP(org.neo4j.lock.ResourceTypes.RELATIONSHIP_GROUP) Record(org.neo4j.kernel.impl.store.record.Record) RelationshipGroupDegreesStore(org.neo4j.internal.counts.RelationshipGroupDegreesStore) FlatRelationshipModifications.creations(org.neo4j.internal.recordstorage.FlatRelationshipModifications.creations) LOOP(org.neo4j.storageengine.api.RelationshipDirection.LOOP) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) FlatRelationshipModifications.modifications(org.neo4j.internal.recordstorage.FlatRelationshipModifications.modifications) RELATIONSHIP_DELETE(org.neo4j.lock.ResourceTypes.RELATIONSHIP_DELETE) Test(org.junit.jupiter.api.Test) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) FlatRelationshipModifications.relationships(org.neo4j.internal.recordstorage.FlatRelationshipModifications.relationships) NODE(org.neo4j.lock.ResourceTypes.NODE) EMPTY_LONG_ARRAY(org.apache.commons.lang3.ArrayUtils.EMPTY_LONG_ARRAY) Mockito.mock(org.mockito.Mockito.mock) FlatRelationshipModifications.singleCreate(org.neo4j.internal.recordstorage.FlatRelationshipModifications.singleCreate) HashMap(java.util.HashMap) MutableLongObjectMap(org.eclipse.collections.api.map.primitive.MutableLongObjectMap) EmptyMemoryTracker(org.neo4j.memory.EmptyMemoryTracker) Supplier(java.util.function.Supplier) ResourceType(org.neo4j.lock.ResourceType) RelationshipDirection(org.neo4j.storageengine.api.RelationshipDirection) ArrayList(java.util.ArrayList) Iterables.asSet(org.neo4j.internal.helpers.collection.Iterables.asSet) LongObjectMaps(org.eclipse.collections.impl.factory.primitive.LongObjectMaps) HashSet(java.util.HashSet) Inject(org.neo4j.test.extension.Inject) RelationshipChainVisitor.relationshipCollector(org.neo4j.internal.recordstorage.RelationshipChainVisitor.relationshipCollector) IntSupplier(java.util.function.IntSupplier) INCOMING(org.neo4j.storageengine.api.RelationshipDirection.INCOMING) Integer.min(java.lang.Integer.min) RELATIONSHIP(org.neo4j.lock.ResourceTypes.RELATIONSHIP) NONE(org.neo4j.lock.LockTracer.NONE) ReadableTransactionState(org.neo4j.storageengine.api.txstate.ReadableTransactionState) FlatRelationshipModifications.deletions(org.neo4j.internal.recordstorage.FlatRelationshipModifications.deletions) IGNORE(org.neo4j.lock.ResourceLocker.IGNORE) ResourceLocker(org.neo4j.lock.ResourceLocker) FlatRelationshipModifications.singleDelete(org.neo4j.internal.recordstorage.FlatRelationshipModifications.singleDelete) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) NULL_MONITOR(org.neo4j.internal.recordstorage.RecordAccess.LoadMonitor.NULL_MONITOR) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) Monitors(org.neo4j.monitoring.Monitors) ReadableTransactionState(org.neo4j.storageengine.api.txstate.ReadableTransactionState) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

IdSequence (org.neo4j.internal.id.IdSequence)5 Test (org.junit.jupiter.api.Test)4 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)2 Integer.min (java.lang.Integer.min)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections.singletonList (java.util.Collections.singletonList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Consumer (java.util.function.Consumer)1 IntSupplier (java.util.function.IntSupplier)1 LongSupplier (java.util.function.LongSupplier)1 Predicate (java.util.function.Predicate)1 Supplier (java.util.function.Supplier)1 Stream (java.util.stream.Stream)1