Search in sources :

Example 1 with LabelTokenHolder

use of org.neo4j.kernel.impl.core.LabelTokenHolder in project neo4j by neo4j.

the class CountsRotationTest method shouldRotateCountsStoreWhenRotatingLog.

@Test
public void shouldRotateCountsStoreWhenRotatingLog() throws IOException {
    // GIVEN
    GraphDatabaseAPI db = (GraphDatabaseAPI) dbBuilder.newGraphDatabase();
    // WHEN doing a transaction (actually two, the label-mini-tx also counts)
    try (Transaction tx = db.beginTx()) {
        db.createNode(B);
        tx.success();
    }
    // and rotating the log (which implies flushing)
    checkPoint(db);
    // and creating another node after it
    try (Transaction tx = db.beginTx()) {
        db.createNode(C);
        tx.success();
    }
    // THEN
    assertTrue(fs.fileExists(alphaStoreFile()));
    assertTrue(fs.fileExists(betaStoreFile()));
    final PageCache pageCache = db.getDependencyResolver().resolveDependency(PageCache.class);
    try (Lifespan life = new Lifespan()) {
        CountsTracker store = life.add(createCountsTracker(pageCache));
        // NOTE since the rotation happens before the second transaction is committed we do not see those changes
        // in the stats
        // a transaction for creating the label and a transaction for the node
        assertEquals(BASE_TX_ID + 1 + 1, store.txId());
        assertEquals(INITIAL_MINOR_VERSION, store.minorVersion());
        // one for all nodes and one for the created "B" label
        assertEquals(1 + 1, store.totalEntriesStored());
        assertEquals(1 + 1, allRecords(store).size());
    }
    // on the other hand the tracker should read the correct value by merging data on disk and data in memory
    final CountsTracker tracker = db.getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores().getCounts();
    assertEquals(1 + 1, tracker.nodeCount(-1, newDoubleLongRegister()).readSecond());
    final LabelTokenHolder holder = db.getDependencyResolver().resolveDependency(LabelTokenHolder.class);
    int labelId = holder.getIdByName(C.name());
    assertEquals(1, tracker.nodeCount(labelId, newDoubleLongRegister()).readSecond());
    db.shutdown();
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) LabelTokenHolder(org.neo4j.kernel.impl.core.LabelTokenHolder) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Example 2 with LabelTokenHolder

use of org.neo4j.kernel.impl.core.LabelTokenHolder in project neo4j by neo4j.

the class IndexingServiceIntegrationTest method testSchemaIndexMatchIndexingService.

@Test
public void testSchemaIndexMatchIndexingService() throws IndexNotFoundKernelException {
    try (Transaction transaction = database.beginTx()) {
        database.schema().constraintFor(Label.label(CLOTHES_LABEL)).assertPropertyIsUnique(PROPERTY_NAME).create();
        database.schema().indexFor(Label.label(WEATHER_LABEL)).on(PROPERTY_NAME).create();
        transaction.success();
    }
    try (Transaction transaction = database.beginTx()) {
        database.schema().awaitIndexesOnline(1, TimeUnit.MINUTES);
    }
    IndexingService indexingService = getIndexingService(database);
    LabelTokenHolder labelTokenHolder = getLabelTokenHolder(database);
    PropertyKeyTokenHolder propertyKeyTokenHolder = getPropertyKeyTokenHolder(database);
    int clothedLabelId = labelTokenHolder.getIdByName(CLOTHES_LABEL);
    int weatherLabelId = labelTokenHolder.getIdByName(WEATHER_LABEL);
    int propertyId = propertyKeyTokenHolder.getIdByName(PROPERTY_NAME);
    IndexProxy clothesIndex = indexingService.getIndexProxy(SchemaDescriptorFactory.forLabel(clothedLabelId, propertyId));
    IndexProxy weatherIndex = indexingService.getIndexProxy(SchemaDescriptorFactory.forLabel(weatherLabelId, propertyId));
    assertEquals(InternalIndexState.ONLINE, clothesIndex.getState());
    assertEquals(InternalIndexState.ONLINE, weatherIndex.getState());
}
Also used : Transaction(org.neo4j.graphdb.Transaction) PropertyKeyTokenHolder(org.neo4j.kernel.impl.core.PropertyKeyTokenHolder) LabelTokenHolder(org.neo4j.kernel.impl.core.LabelTokenHolder) Test(org.junit.Test)

Example 3 with LabelTokenHolder

use of org.neo4j.kernel.impl.core.LabelTokenHolder in project neo4j by neo4j.

the class IndexingServiceIntegrationTest method testManualIndexPopulation.

@Test
public void testManualIndexPopulation() throws IOException, IndexNotFoundKernelException, InterruptedException {
    IndexingService indexingService = getIndexingService(database);
    SchemaStore schemaStore = getSchemaStore(database);
    LabelTokenHolder labelTokenHolder = getLabelTokenHolder(database);
    PropertyKeyTokenHolder propertyKeyTokenHolder = getPropertyKeyTokenHolder(database);
    int foodId = labelTokenHolder.getIdByName(FOOD_LABEL);
    int propertyId = propertyKeyTokenHolder.getIdByName(PROPERTY_NAME);
    IndexRule rule = IndexRule.indexRule(schemaStore.nextId(), NewIndexDescriptorFactory.forLabel(foodId, propertyId), indexDescriptor);
    indexingService.createIndexes(rule);
    IndexProxy indexProxy = indexingService.getIndexProxy(rule.getId());
    waitIndexOnline(indexProxy);
    assertEquals(InternalIndexState.ONLINE, indexProxy.getState());
    PopulationProgress progress = indexProxy.getIndexPopulationProgress();
    assertEquals(progress.getCompleted(), progress.getTotal());
}
Also used : IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) PopulationProgress(org.neo4j.storageengine.api.schema.PopulationProgress) SchemaStore(org.neo4j.kernel.impl.store.SchemaStore) PropertyKeyTokenHolder(org.neo4j.kernel.impl.core.PropertyKeyTokenHolder) LabelTokenHolder(org.neo4j.kernel.impl.core.LabelTokenHolder) Test(org.junit.Test)

Example 4 with LabelTokenHolder

use of org.neo4j.kernel.impl.core.LabelTokenHolder 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)

Aggregations

Test (org.junit.Test)4 LabelTokenHolder (org.neo4j.kernel.impl.core.LabelTokenHolder)4 Transaction (org.neo4j.graphdb.Transaction)3 PropertyKeyTokenHolder (org.neo4j.kernel.impl.core.PropertyKeyTokenHolder)2 Node (org.neo4j.graphdb.Node)1 PageCache (org.neo4j.io.pagecache.PageCache)1 SchemaStore (org.neo4j.kernel.impl.store.SchemaStore)1 CountsTracker (org.neo4j.kernel.impl.store.counts.CountsTracker)1 IndexRule (org.neo4j.kernel.impl.store.record.IndexRule)1 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)1 Lifespan (org.neo4j.kernel.lifecycle.Lifespan)1 PopulationProgress (org.neo4j.storageengine.api.schema.PopulationProgress)1