Search in sources :

Example 11 with CountsTracker

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

the class RebuildCountsTest method shouldRebuildMissingCountsStoreAfterRecovery.

@Test
public void shouldRebuildMissingCountsStoreAfterRecovery() throws IOException {
    // given
    createAliensAndHumans();
    // when
    rotateLog();
    deleteHumans();
    FileSystemAbstraction fs = crash();
    deleteCounts(fs);
    restart(fs);
    // then
    CountsTracker tracker = counts();
    assertEquals(ALIENS, tracker.nodeCount(-1, newDoubleLongRegister()).readSecond());
    assertEquals(ALIENS, tracker.nodeCount(labelId(ALIEN), newDoubleLongRegister()).readSecond());
    assertEquals(0, tracker.nodeCount(labelId(HUMAN), newDoubleLongRegister()).readSecond());
    // and also
    internalLogProvider.assertAtLeastOnce(inLog(MetaDataStore.class).warn("Missing counts store, rebuilding it."));
}
Also used : UncloseableDelegatingFileSystemAbstraction(org.neo4j.graphdb.mockfs.UncloseableDelegatingFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) CountsTracker(org.neo4j.kernel.impl.store.counts.CountsTracker) Test(org.junit.Test)

Example 12 with CountsTracker

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

the class IndexStatisticsIT method shouldRecoverIndexCountsBySamplingThemOnStartup.

@Test
public void shouldRecoverIndexCountsBySamplingThemOnStartup() {
    // given some aliens in a database
    createAliens();
    // that have been indexed
    awaitIndexOnline(indexAliensBySpecimen());
    // where ALIEN and SPECIMEN are both the first ids of their kind
    NewIndexDescriptor index = NewIndexDescriptorFactory.forLabel(labelId(ALIEN), pkId(SPECIMEN));
    SchemaStorage storage = new SchemaStorage(neoStores().getSchemaStore());
    long indexId = storage.indexGetForSchema(index).getId();
    // for which we don't have index counts
    resetIndexCounts(indexId);
    // when we shutdown the database and restart it
    restart();
    // then we should have re-sampled the index
    CountsTracker tracker = neoStores().getCounts();
    assertEqualRegisters("Unexpected updates and size for the index", newDoubleLongRegister(0, 32), tracker.indexUpdatesAndSize(indexId, newDoubleLongRegister()));
    assertEqualRegisters("Unexpected sampling result", newDoubleLongRegister(16, 32), tracker.indexSample(indexId, newDoubleLongRegister()));
    // and also
    assertLogExistsForRecoveryOn(":Alien(specimen)");
}
Also used : NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) SchemaStorage(org.neo4j.kernel.impl.store.SchemaStorage) CountsTracker(org.neo4j.kernel.impl.store.counts.CountsTracker) Test(org.junit.Test)

Example 13 with CountsTracker

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

the class BatchInserterImpl method rebuildCounts.

private void rebuildCounts() {
    CountsTracker counts = neoStores.getCounts();
    try {
        counts.start();
    } catch (IOException e) {
        throw new UnderlyingStorageException(e);
    }
    CountsComputer.recomputeCounts(neoStores);
}
Also used : IOException(java.io.IOException) CountsTracker(org.neo4j.kernel.impl.store.counts.CountsTracker) UnderlyingStorageException(org.neo4j.kernel.impl.store.UnderlyingStorageException)

Example 14 with CountsTracker

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

the class NeoStores method flush.

public void flush(IOLimiter limiter) {
    try {
        CountsTracker counts = (CountsTracker) stores[StoreType.COUNTS.ordinal()];
        if (counts != null) {
            counts.rotate(getMetaDataStore().getLastCommittedTransactionId());
        }
        pageCache.flushAndForce(limiter);
    } catch (IOException e) {
        throw new UnderlyingStorageException("Failed to flush", e);
    }
}
Also used : IOException(java.io.IOException) CountsTracker(org.neo4j.kernel.impl.store.counts.CountsTracker) ReadOnlyCountsTracker(org.neo4j.kernel.impl.store.counts.ReadOnlyCountsTracker)

Example 15 with CountsTracker

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

the class NeoStores method createCountStore.

CountsTracker createCountStore(String storeName) {
    File storeFile = getStoreFile(storeName);
    boolean readOnly = config.get(GraphDatabaseSettings.read_only);
    CountsTracker counts = readOnly ? createReadOnlyCountsTracker(storeFile) : createWritableCountsTracker(storeFile);
    NeoStores neoStores = this;
    counts.setInitializer(new DataInitializer<CountsAccessor.Updater>() {

        private final Log log = logProvider.getLog(MetaDataStore.class);

        @Override
        public void initialize(CountsAccessor.Updater updater) {
            log.warn("Missing counts store, rebuilding it.");
            new CountsComputer(neoStores).initialize(updater);
        }

        @Override
        public long initialVersion() {
            return ((MetaDataStore) getOrCreateStore(StoreType.META_DATA)).getLastCommittedTransactionId();
        }
    });
    try {
        // TODO: move this to LifeCycle
        counts.init();
    } catch (IOException e) {
        throw new UnderlyingStorageException("Failed to initialize counts store", e);
    }
    return counts;
}
Also used : Log(org.neo4j.logging.Log) CountsAccessor(org.neo4j.kernel.impl.api.CountsAccessor) IOException(java.io.IOException) CountsTracker(org.neo4j.kernel.impl.store.counts.CountsTracker) ReadOnlyCountsTracker(org.neo4j.kernel.impl.store.counts.ReadOnlyCountsTracker) PagedFile(org.neo4j.io.pagecache.PagedFile) File(java.io.File)

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