Search in sources :

Example 36 with RelationshipGroupRecord

use of org.neo4j.kernel.impl.store.record.RelationshipGroupRecord in project neo4j by neo4j.

the class RelationshipGroupGetterTest method shouldAbortLoadingGroupChainIfComeTooFar.

@Test
public void shouldAbortLoadingGroupChainIfComeTooFar() throws Exception {
    // GIVEN a node with relationship group chain 2-->4-->10-->23
    File dir = new File("dir");
    fs.get().mkdirs(dir);
    LogProvider logProvider = NullLogProvider.getInstance();
    StoreFactory storeFactory = new StoreFactory(dir, pageCache.getPageCache(fs.get()), fs.get(), logProvider);
    try (NeoStores stores = storeFactory.openNeoStores(true, StoreType.RELATIONSHIP_GROUP)) {
        RecordStore<RelationshipGroupRecord> store = spy(stores.getRelationshipGroupStore());
        RelationshipGroupRecord group_2 = group(0, 2);
        RelationshipGroupRecord group_4 = group(1, 4);
        RelationshipGroupRecord group_10 = group(2, 10);
        RelationshipGroupRecord group_23 = group(3, 23);
        link(group_2, group_4, group_10, group_23);
        store.updateRecord(group_2);
        store.updateRecord(group_4);
        store.updateRecord(group_10);
        store.updateRecord(group_23);
        RelationshipGroupGetter groupGetter = new RelationshipGroupGetter(store);
        NodeRecord node = new NodeRecord(0, true, group_2.getId(), -1);
        // WHEN trying to find relationship group 7
        RecordAccess<Long, RelationshipGroupRecord, Integer> access = new DirectRecordAccess<>(store, Loaders.relationshipGroupLoader(store));
        RelationshipGroupPosition result = groupGetter.getRelationshipGroup(node, 7, access);
        // THEN only groups 2, 4 and 10 should have been loaded
        InOrder verification = inOrder(store);
        verification.verify(store).getRecord(eq(group_2.getId()), any(RelationshipGroupRecord.class), any(RecordLoad.class));
        verification.verify(store).getRecord(eq(group_4.getId()), any(RelationshipGroupRecord.class), any(RecordLoad.class));
        verification.verify(store).getRecord(eq(group_10.getId()), any(RelationshipGroupRecord.class), any(RecordLoad.class));
        verification.verify(store, times(0)).getRecord(eq(group_23.getId()), any(RelationshipGroupRecord.class), any(RecordLoad.class));
        // it should also be reported as not found
        assertNull(result.group());
        // with group 4 as closes previous one
        assertEquals(group_4, result.closestPrevious().forReadingData());
    }
}
Also used : RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) InOrder(org.mockito.InOrder) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) RecordLoad(org.neo4j.kernel.impl.store.record.RecordLoad) LogProvider(org.neo4j.logging.LogProvider) NullLogProvider(org.neo4j.logging.NullLogProvider) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) DirectRecordAccess(org.neo4j.unsafe.batchinsert.DirectRecordAccess) NeoStores(org.neo4j.kernel.impl.store.NeoStores) File(java.io.File) RelationshipGroupPosition(org.neo4j.kernel.impl.transaction.state.RelationshipGroupGetter.RelationshipGroupPosition) Test(org.junit.Test)

Example 37 with RelationshipGroupRecord

use of org.neo4j.kernel.impl.store.record.RelationshipGroupRecord in project neo4j by neo4j.

the class RelationshipGroupGetterTest method group.

private RelationshipGroupRecord group(long id, int type) {
    RelationshipGroupRecord group = new RelationshipGroupRecord(id, type);
    group.setInUse(true);
    return group;
}
Also used : RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord)

Example 38 with RelationshipGroupRecord

use of org.neo4j.kernel.impl.store.record.RelationshipGroupRecord in project neo4j by neo4j.

the class ReadGroupsFromCacheStepTest method shouldProduceCompleteBatchesPerOwner.

@Test
public void shouldProduceCompleteBatchesPerOwner() throws Exception {
    // GIVEN
    Configuration config = Configuration.withBatchSize(DEFAULT, 10);
    Iterator<RelationshipGroupRecord> groups = groups(new Group(1, 3), new Group(2, 3), // ^^^ perfect batch size
    new Group(3, 4), new Group(4, 2), // ^^^ slightly bigger than batch size
    new Group(5, 10), // ^^^ much bigger than batch size
    new Group(6, 35), new Group(7, 2)).iterator();
    final AtomicInteger processCounter = new AtomicInteger();
    Stage stage = new Stage(getClass().getSimpleName(), config) {

        {
            add(new ReadGroupsFromCacheStep(control(), config, groups, 1));
            add(new VerifierStep(control(), config, processCounter));
        }
    };
    // WHEN processing the data
    superviseDynamicExecution(stage);
    // THEN
    assertEquals(4, processCounter.get());
}
Also used : RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Stage(org.neo4j.unsafe.impl.batchimport.staging.Stage) Test(org.junit.Test)

Example 39 with RelationshipGroupRecord

use of org.neo4j.kernel.impl.store.record.RelationshipGroupRecord in project neo4j by neo4j.

the class RelationshipGroupCacheTest method shouldPutGroupsOnlyWithinPreparedRange.

@Test
public void shouldPutGroupsOnlyWithinPreparedRange() throws Exception {
    // GIVEN
    int nodeCount = 1000;
    RelationshipGroupCache cache = new RelationshipGroupCache(HEAP, ByteUnit.kibiBytes(4), nodeCount);
    int[] counts = new int[nodeCount];
    for (int nodeId = 0; nodeId < counts.length; nodeId++) {
        counts[nodeId] = random.nextInt(10);
        setCount(cache, nodeId, counts[nodeId]);
    }
    long toNodeId = cache.prepare(0);
    assertTrue(toNodeId < nodeCount);
    // WHEN
    boolean thereAreMoreGroups = true;
    int cachedCount = 0;
    while (thereAreMoreGroups) {
        thereAreMoreGroups = false;
        for (int nodeId = 0; nodeId < nodeCount; nodeId++) {
            if (counts[nodeId] > 0) {
                thereAreMoreGroups = true;
                int typeId = counts[nodeId]--;
                if (cache.put(new RelationshipGroupRecord(nodeId).initialize(true, typeId, -1, -1, -1, nodeId, -1))) {
                    cachedCount++;
                }
            }
        }
    }
    assertTrue(cachedCount >= toNodeId);
    // THEN the relationship groups we get back are only for those we prepared for
    int readCount = 0;
    for (RelationshipGroupRecord cachedGroup : cache) {
        assertTrue(cachedGroup.getOwningNode() >= 0 && cachedGroup.getOwningNode() < toNodeId);
        readCount++;
    }
    assertEquals(cachedCount, readCount);
}
Also used : RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) Test(org.junit.Test)

Example 40 with RelationshipGroupRecord

use of org.neo4j.kernel.impl.store.record.RelationshipGroupRecord in project neo4j by neo4j.

the class RelationshipGroupCacheTest method shouldHandleGroupCountBeyondSignedShortRange.

@Test
public void shouldHandleGroupCountBeyondSignedShortRange() throws Exception {
    // GIVEN
    long nodeId = 0;
    int limit = Short.MAX_VALUE + 10;
    RelationshipGroupCache cache = new RelationshipGroupCache(HEAP, ByteUnit.kibiBytes(100), nodeId + 1);
    // WHEN first counting all groups per node
    for (int type = 0; type < limit; type++) {
        cache.incrementGroupCount(nodeId);
    }
    // and WHEN later putting group records into the cache
    RelationshipGroupRecord group = new RelationshipGroupRecord(-1);
    group.setOwningNode(nodeId);
    for (int type = 0; type < limit; type++) {
        group.setId(type);
        // just some relationship
        group.setFirstOut(type);
        group.setType(type);
        cache.put(group);
    }
    long prepared = cache.prepare(nodeId);
    // THEN that should work, because it used to fail inside prepare, but we can also ask
    // the groupCount method to be sure
    assertEquals(nodeId, prepared);
    assertEquals(limit, cache.groupCount(nodeId));
}
Also used : RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) Test(org.junit.Test)

Aggregations

RelationshipGroupRecord (org.neo4j.kernel.impl.store.record.RelationshipGroupRecord)83 Test (org.junit.Test)42 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)24 GraphStoreFixture (org.neo4j.consistency.checking.GraphStoreFixture)11 IdGenerator (org.neo4j.consistency.checking.GraphStoreFixture.IdGenerator)11 TransactionDataBuilder (org.neo4j.consistency.checking.GraphStoreFixture.TransactionDataBuilder)11 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)11 RelationshipRecord (org.neo4j.kernel.impl.store.record.RelationshipRecord)10 Command (org.neo4j.kernel.impl.transaction.command.Command)5 IOException (java.io.IOException)4 InMemoryClosableChannel (org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel)4 File (java.io.File)3 Node (org.neo4j.graphdb.Node)3 Relationship (org.neo4j.graphdb.Relationship)3 Transaction (org.neo4j.graphdb.Transaction)3 RecordStorageEngine (org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine)3 NeoStores (org.neo4j.kernel.impl.store.NeoStores)3 RelationshipStore (org.neo4j.kernel.impl.store.RelationshipStore)3 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)3 RelationshipGroupCommand (org.neo4j.kernel.impl.transaction.command.Command.RelationshipGroupCommand)3