Search in sources :

Example 16 with CountsTracker

use of org.neo4j.kernel.impl.store.counts.CountsTracker in project neo4j by neo4j.

the class TestRecoveryScenarios method shouldRecoverCounts.

@Test
public void shouldRecoverCounts() throws Exception {
    // GIVEN
    Node node = createNode(label);
    checkPoint();
    deleteNode(node);
    // WHEN
    crashAndRestart(indexProvider);
    // -- really the problem was that recovery threw exception, so mostly assert that.
    try (Transaction tx = db.beginTx()) {
        CountsTracker tracker = db.getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores().getCounts();
        assertEquals(0, tracker.nodeCount(-1, newDoubleLongRegister()).readSecond());
        final LabelTokenHolder holder = db.getDependencyResolver().resolveDependency(LabelTokenHolder.class);
        int labelId = holder.getIdByName(label.name());
        assertEquals(0, tracker.nodeCount(labelId, newDoubleLongRegister()).readSecond());
        tx.success();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) LabelTokenHolder(org.neo4j.kernel.impl.core.LabelTokenHolder) CountsTracker(org.neo4j.kernel.impl.store.counts.CountsTracker) Test(org.junit.Test)

Example 17 with CountsTracker

use of org.neo4j.kernel.impl.store.counts.CountsTracker in project neo4j by neo4j.

the class IndexSamplingIntegrationTest method fetchIndexSizeValues.

private DoubleLongRegister fetchIndexSizeValues(GraphDatabaseService db) throws IndexNotFoundKernelException {
    try {
        // Then
        db = new TestGraphDatabaseFactory().newEmbeddedDatabase(testDirectory.graphDbDir());
        @SuppressWarnings("deprecation") GraphDatabaseAPI api = (GraphDatabaseAPI) db;
        CountsTracker countsTracker = api.getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores().getCounts();
        IndexStatisticsKey key = CountsKeyFactory.indexStatisticsKey(indexId(api));
        return countsTracker.get(key, Registers.newDoubleLongRegister());
    } finally {
        if (db != null) {
            db.shutdown();
        }
    }
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) IndexStatisticsKey(org.neo4j.kernel.impl.store.counts.keys.IndexStatisticsKey) CountsTracker(org.neo4j.kernel.impl.store.counts.CountsTracker)

Example 18 with CountsTracker

use of org.neo4j.kernel.impl.store.counts.CountsTracker 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 19 with CountsTracker

use of org.neo4j.kernel.impl.store.counts.CountsTracker in project neo4j by neo4j.

the class RecordStorageEngineTest method obtainCountsStoreResetterAfterFailedTransaction.

@Test(timeout = 30_000)
public void obtainCountsStoreResetterAfterFailedTransaction() throws Throwable {
    RecordStorageEngine engine = buildRecordStorageEngine();
    Exception applicationError = executeFailingTransaction(engine);
    assertNotNull(applicationError);
    CountsTracker countsStore = engine.testAccessNeoStores().getCounts();
    // possible to obtain a resetting updater that internally has a write lock on the counts store
    try (CountsAccessor.Updater updater = countsStore.reset(0)) {
        assertNotNull(updater);
    }
}
Also used : CountsAccessor(org.neo4j.kernel.impl.api.CountsAccessor) CountsTracker(org.neo4j.kernel.impl.store.counts.CountsTracker) UnderlyingStorageException(org.neo4j.kernel.impl.store.UnderlyingStorageException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

CountsTracker (org.neo4j.kernel.impl.store.counts.CountsTracker)19 Test (org.junit.Test)10 IOException (java.io.IOException)4 CountsAccessor (org.neo4j.kernel.impl.api.CountsAccessor)4 Transaction (org.neo4j.graphdb.Transaction)3 UncloseableDelegatingFileSystemAbstraction (org.neo4j.graphdb.mockfs.UncloseableDelegatingFileSystemAbstraction)3 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)3 File (java.io.File)2 Node (org.neo4j.graphdb.Node)2 PagedFile (org.neo4j.io.pagecache.PagedFile)2 HighlyAvailableGraphDatabase (org.neo4j.kernel.ha.HighlyAvailableGraphDatabase)2 ManagedCluster (org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster)2 NeoStores (org.neo4j.kernel.impl.store.NeoStores)2 NodeStore (org.neo4j.kernel.impl.store.NodeStore)2 UnderlyingStorageException (org.neo4j.kernel.impl.store.UnderlyingStorageException)2 ReadOnlyCountsTracker (org.neo4j.kernel.impl.store.counts.ReadOnlyCountsTracker)2 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)2 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)2 InterruptedIOException (java.io.InterruptedIOException)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1