Search in sources :

Example 96 with NeoStores

use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.

the class MultipleIndexPopulatorUpdatesTest method updateForHigherNodeIgnoredWhenUsingFullNodeStoreScan.

@Test
public void updateForHigherNodeIgnoredWhenUsingFullNodeStoreScan() throws IndexPopulationFailedKernelException, IOException, IndexEntryConflictException {
    NeoStores neoStores = Mockito.mock(NeoStores.class);
    CountsTracker countsTracker = mock(CountsTracker.class);
    NodeStore nodeStore = mock(NodeStore.class);
    PropertyStore propertyStore = mock(PropertyStore.class);
    NodeRecord nodeRecord = getNodeRecord();
    PropertyRecord propertyRecord = getPropertyRecord();
    when(neoStores.getCounts()).thenReturn(countsTracker);
    when(neoStores.getNodeStore()).thenReturn(nodeStore);
    when(neoStores.getPropertyStore()).thenReturn(propertyStore);
    when(propertyStore.getPropertyRecordChain(anyInt())).thenReturn(Collections.singletonList(propertyRecord));
    when(countsTracker.nodeCount(anyInt(), any(Register.DoubleLongRegister.class))).thenReturn(Registers.newDoubleLongRegister(3, 3));
    when(nodeStore.getHighestPossibleIdInUse()).thenReturn(20L);
    when(nodeStore.newRecord()).thenReturn(nodeRecord);
    when(nodeStore.getRecord(anyInt(), eq(nodeRecord), any(RecordLoad.class))).thenAnswer(new SetNodeIdRecordAnswer(nodeRecord, 1));
    when(nodeStore.getRecord(eq(7L), eq(nodeRecord), any(RecordLoad.class))).thenAnswer(new SetNodeIdRecordAnswer(nodeRecord, 7));
    ProcessListenableNeoStoreIndexView storeView = new ProcessListenableNeoStoreIndexView(LockService.NO_LOCK_SERVICE, neoStores);
    MultipleIndexPopulator indexPopulator = new MultipleIndexPopulator(storeView, logProvider);
    storeView.setProcessListener(new NodeUpdateProcessListener(indexPopulator));
    IndexPopulator populator = createIndexPopulator();
    IndexUpdater indexUpdater = mock(IndexUpdater.class);
    when(populator.newPopulatingUpdater(storeView)).thenReturn(indexUpdater);
    addPopulator(indexPopulator, populator, 1, NewIndexDescriptorFactory.forLabel(1, 1));
    indexPopulator.create();
    StoreScan<IndexPopulationFailedKernelException> storeScan = indexPopulator.indexAllNodes();
    storeScan.run();
    Mockito.verify(indexUpdater, times(0)).process(any(IndexEntryUpdate.class));
}
Also used : IndexEntryUpdate(org.neo4j.kernel.api.index.IndexEntryUpdate) IndexPopulationFailedKernelException(org.neo4j.kernel.api.exceptions.index.IndexPopulationFailedKernelException) RecordLoad(org.neo4j.kernel.impl.store.record.RecordLoad) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) NodeStore(org.neo4j.kernel.impl.store.NodeStore) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) NeoStores(org.neo4j.kernel.impl.store.NeoStores) CountsTracker(org.neo4j.kernel.impl.store.counts.CountsTracker) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) PropertyStore(org.neo4j.kernel.impl.store.PropertyStore) Test(org.junit.Test)

Example 97 with NeoStores

use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.

the class TestCrashWithRebuildSlow method getHighIds.

private static Map<IdType, Long> getHighIds(GraphDatabaseAPI db) {
    final Map<IdType, Long> highIds = new HashMap<>();
    NeoStores neoStores = db.getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
    Visitor<CommonAbstractStore, RuntimeException> visitor = new Visitor<CommonAbstractStore, RuntimeException>() {

        @Override
        public boolean visit(CommonAbstractStore store) throws RuntimeException {
            highIds.put(store.getIdType(), store.getHighId());
            return true;
        }
    };
    neoStores.visitStore(visitor);
    return highIds;
}
Also used : Visitor(org.neo4j.helpers.collection.Visitor) HashMap(java.util.HashMap) RecordStorageEngine(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine) NeoStores(org.neo4j.kernel.impl.store.NeoStores) CommonAbstractStore(org.neo4j.kernel.impl.store.CommonAbstractStore) IdType(org.neo4j.kernel.impl.store.id.IdType)

Example 98 with NeoStores

use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.

the class CountsComputerTest method rebuildCounts.

private void rebuildCounts(long lastCommittedTransactionId) throws IOException {
    cleanupCountsForRebuilding();
    StoreFactory storeFactory = new StoreFactory(dir, pageCache, fs, NullLogProvider.getInstance());
    try (Lifespan life = new Lifespan();
        NeoStores neoStores = storeFactory.openAllNeoStores()) {
        NodeStore nodeStore = neoStores.getNodeStore();
        RelationshipStore relationshipStore = neoStores.getRelationshipStore();
        int highLabelId = (int) neoStores.getLabelTokenStore().getHighId();
        int highRelationshipTypeId = (int) neoStores.getRelationshipTypeTokenStore().getHighId();
        CountsComputer countsComputer = new CountsComputer(lastCommittedTransactionId, nodeStore, relationshipStore, highLabelId, highRelationshipTypeId);
        CountsTracker countsTracker = createCountsTracker();
        life.add(countsTracker.setInitializer(countsComputer));
    }
}
Also used : NodeStore(org.neo4j.kernel.impl.store.NodeStore) CountsComputer(org.neo4j.kernel.impl.store.CountsComputer) NeoStores(org.neo4j.kernel.impl.store.NeoStores) RelationshipStore(org.neo4j.kernel.impl.store.RelationshipStore) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) Lifespan(org.neo4j.kernel.lifecycle.Lifespan)

Example 99 with NeoStores

use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.

the class NonIndexedConflictResolverTest method setUp.

@Before
public void setUp() {
    api = dbRule.getGraphDatabaseAPI();
    String propKeyA = "keyA";
    String propKeyB = "keyB";
    String propKeyC = "keyC";
    String propKeyD = "keyD";
    String propKeyE = "keyE";
    try (Transaction transaction = api.beginTx()) {
        Node nodeA = api.createNode();
        nodeA.setProperty(propKeyA, "value");
        nodeA.setProperty(propKeyB, "value");
        nodeIdA = nodeA.getId();
        Node nodeB = api.createNode();
        nodeB.setProperty(propKeyA, "value");
        nodeB.setProperty(propKeyB, "value");
        nodeIdB = nodeB.getId();
        Node nodeC = api.createNode();
        nodeC.setProperty(propKeyA, "longer val");
        nodeC.setProperty(propKeyB, "longer val");
        nodeC.setProperty(propKeyC, "longer val");
        nodeC.setProperty(propKeyD, "longer val");
        nodeC.setProperty(propKeyE, "longer val");
        nodeIdC = nodeC.getId();
        transaction.success();
    }
    DependencyResolver resolver = api.getDependencyResolver();
    NeoStores neoStores = resolver.resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
    nodeStore = neoStores.getNodeStore();
    propertyStore = neoStores.getPropertyStore();
    propertyKeyTokenStore = neoStores.getPropertyKeyTokenStore();
    tokenA = findTokenFor(propertyKeyTokenStore, propKeyA);
    Token tokenB = findTokenFor(propertyKeyTokenStore, propKeyB);
    Token tokenC = findTokenFor(propertyKeyTokenStore, propKeyC);
    Token tokenD = findTokenFor(propertyKeyTokenStore, propKeyD);
    Token tokenE = findTokenFor(propertyKeyTokenStore, propKeyE);
    replacePropertyKey(propertyStore, nodeStore.getRecord(nodeIdA, nodeStore.newRecord(), FORCE), tokenB, tokenA);
    replacePropertyKey(propertyStore, nodeStore.getRecord(nodeIdB, nodeStore.newRecord(), FORCE), tokenB, tokenA);
    NodeRecord nodeRecordC = nodeStore.getRecord(nodeIdC, nodeStore.newRecord(), FORCE);
    replacePropertyKey(propertyStore, nodeRecordC, tokenB, tokenA);
    replacePropertyKey(propertyStore, nodeRecordC, tokenC, tokenA);
    replacePropertyKey(propertyStore, nodeRecordC, tokenD, tokenA);
    replacePropertyKey(propertyStore, nodeRecordC, tokenE, tokenA);
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) Transaction(org.neo4j.graphdb.Transaction) RecordStorageEngine(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine) Node(org.neo4j.graphdb.Node) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Token(org.neo4j.storageengine.api.Token) DependencyResolver(org.neo4j.graphdb.DependencyResolver) Before(org.junit.Before)

Example 100 with NeoStores

use of org.neo4j.kernel.impl.store.NeoStores in project neo4j by neo4j.

the class DeferredIndexedConflictResolutionTest method setUp.

@Before
public void setUp() {
    GraphDatabaseFactory factory = new TestGraphDatabaseFactory();
    db = factory.newEmbeddedDatabase(storePath.absolutePath());
    GraphDatabaseAPI api = (GraphDatabaseAPI) db;
    Label nodeLabel = Label.label("Label");
    String propertyKey = "someProp";
    long nodeId;
    try (Transaction transaction = db.beginTx()) {
        Node node = db.createNode(nodeLabel);
        node.setProperty(propertyKey, "someVal");
        nodeId = node.getId();
        transaction.success();
    }
    DependencyResolver resolver = api.getDependencyResolver();
    NeoStores neoStores = resolver.resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
    nodeStore = neoStores.getNodeStore();
    propertyStore = neoStores.getPropertyStore();
    Map<String, Integer> propertyKeys = PropertyDeduplicatorTestUtil.indexPropertyKeys(neoStores.getPropertyKeyTokenStore());
    nodeRecord = RecordStore.getRecord(nodeStore, nodeId);
    int propertyKeyId = propertyKeys.get(propertyKey);
    clusterToRemove = createDuplicateCluster(propertyKeyId, nodeRecord.getNextProp());
    clusters = new ArrayList<>();
    clusters.add(createDuplicateCluster(propertyKeyId + 1, nodeRecord.getNextProp()));
    // This is the one we want to remove
    clusters.add(clusterToRemove);
    clusters.add(createDuplicateCluster(propertyKeyId + 2, nodeRecord.getNextProp()));
}
Also used : Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) DependencyResolver(org.neo4j.graphdb.DependencyResolver) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) GraphDatabaseFactory(org.neo4j.graphdb.factory.GraphDatabaseFactory) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) RecordStorageEngine(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine) NeoStores(org.neo4j.kernel.impl.store.NeoStores) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Before(org.junit.Before)

Aggregations

NeoStores (org.neo4j.kernel.impl.store.NeoStores)122 Test (org.junit.Test)46 StoreFactory (org.neo4j.kernel.impl.store.StoreFactory)32 Test (org.junit.jupiter.api.Test)25 ArrayList (java.util.ArrayList)17 DefaultIdGeneratorFactory (org.neo4j.internal.id.DefaultIdGeneratorFactory)16 PageCache (org.neo4j.io.pagecache.PageCache)16 NodeStore (org.neo4j.kernel.impl.store.NodeStore)15 Transaction (org.neo4j.graphdb.Transaction)14 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)14 RecordStorageEngine (org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine)13 File (java.io.File)11 IOException (java.io.IOException)11 Node (org.neo4j.graphdb.Node)11 RelationshipStore (org.neo4j.kernel.impl.store.RelationshipStore)11 MetaDataStore (org.neo4j.kernel.impl.store.MetaDataStore)10 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)9 PropertyStore (org.neo4j.kernel.impl.store.PropertyStore)9