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();
}
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());
}
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());
}
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();
}
}
Aggregations