use of org.neo4j.internal.counts.GBPTreeCountsStore in project neo4j by neo4j.
the class CountsComputerTest method shouldCreateACountsStoreWhenThereAreUnusedRelationshipRecordsInTheDB.
@Test
void shouldCreateACountsStoreWhenThereAreUnusedRelationshipRecordsInTheDB() throws IOException, KernelException {
DatabaseManagementService managementService = dbBuilder.build();
final GraphDatabaseAPI db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
Label[] labels = null;
int[] labelIds = null;
RelationshipType[] relTypes = null;
int[] relTypeIds = null;
Node[] nodes = null;
Relationship[] rels = null;
try (Transaction tx = db.beginTx()) {
labels = createLabels(4);
labelIds = getLabelIdsFrom(tx, labels);
relTypes = createRelationShipTypes(2);
relTypeIds = getRelTypeIdsFrom(tx, relTypes);
nodes = new Node[] { tx.createNode(labels[0]), tx.createNode(labels[1]) };
rels = new Relationship[] { nodes[0].createRelationshipTo(nodes[1], relTypes[0]), nodes[1].createRelationshipTo(nodes[0], relTypes[1]) };
rels[0].delete();
tx.commit();
}
long lastCommittedTransactionId = getLastTxId(db);
managementService.shutdown();
rebuildCounts(lastCommittedTransactionId);
try (GBPTreeCountsStore store = createCountsStore()) {
softly.assertThat(store.txId()).as("Store Transaction id").isEqualTo(lastCommittedTransactionId);
softly.assertThat(store.nodeCount(ANY_LABEL, NULL)).as("count: ()").isEqualTo(nodes.length);
softly.assertThat(store.nodeCount(labelIds[0], NULL)).as("count: (:%s)", labels[0]).isEqualTo(1);
softly.assertThat(store.nodeCount(labelIds[1], NULL)).as("count: (:%s)", labels[1]).isEqualTo(1);
softly.assertThat(store.nodeCount(labelIds[2], NULL)).as("count: (:%s)", labels[2]).isEqualTo(0);
softly.assertThat(store.nodeCount(labelIds[3], NULL)).as("count: (:%s)", labels[3]).isEqualTo(0);
softly.assertThat(store.relationshipCount(ANY_LABEL, ANY_RELATIONSHIP_TYPE, ANY_LABEL, NULL)).as("()-[]->()").isEqualTo(rels.length - 1);
softly.assertThat(store.relationshipCount(ANY_LABEL, relTypeIds[0], ANY_LABEL, NULL)).as("count: ()-[:%s]->()", relTypes[0]).isEqualTo(0);
softly.assertThat(store.relationshipCount(ANY_LABEL, relTypeIds[1], ANY_LABEL, NULL)).as("count: ()-[:%s]->()", relTypes[1]).isEqualTo(1);
}
}
use of org.neo4j.internal.counts.GBPTreeCountsStore in project neo4j by neo4j.
the class CountsComputerTest method rebuildCounts.
private void rebuildCounts(long lastCommittedTransactionId, ProgressReporter progressReporter) throws IOException {
cleanupCountsForRebuilding();
IdGeneratorFactory idGenFactory = new DefaultIdGeneratorFactory(fileSystem, immediate(), databaseLayout.getDatabaseName());
StoreFactory storeFactory = new StoreFactory(databaseLayout, CONFIG, idGenFactory, pageCache, fileSystem, LOG_PROVIDER, PageCacheTracer.NULL, writable());
try (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, NumberArrayFactories.AUTO_WITHOUT_PAGECACHE, databaseLayout, progressReporter, PageCacheTracer.NULL, INSTANCE);
try (GBPTreeCountsStore countsStore = createCountsStore(countsComputer)) {
countsStore.start(NULL, INSTANCE);
countsStore.checkpoint(NULL);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
use of org.neo4j.internal.counts.GBPTreeCountsStore in project neo4j by neo4j.
the class BatchInsertTest method shouldBuildCorrectCountsStoreOnIncrementalImport.
@Test
void shouldBuildCorrectCountsStoreOnIncrementalImport() throws Exception {
// given
Label label = Label.label("Person");
int denseNodeThreshold = dense_node_threshold.defaultValue();
for (int r = 0; r < 3; r++) {
// when
BatchInserter inserter = newBatchInserter(denseNodeThreshold);
try {
for (int i = 0; i < 100; i++) {
inserter.createNode(null, label);
}
} finally {
inserter.shutdown();
}
// then
try (GBPTreeCountsStore countsStore = new GBPTreeCountsStore(pageCache, databaseLayout.countStore(), fs, RecoveryCleanupWorkCollector.immediate(), new CountsBuilder() {
@Override
public void initialize(CountsAccessor.Updater updater, CursorContext cursorContext, MemoryTracker memoryTracker) {
throw new UnsupportedOperationException("Should not be required");
}
@Override
public long lastCommittedTxId() {
return TransactionIdStore.BASE_TX_ID;
}
}, readOnly(), PageCacheTracer.NULL, GBPTreeCountsStore.NO_MONITOR, databaseLayout.getDatabaseName(), 1000)) {
countsStore.start(NULL, INSTANCE);
assertEquals((r + 1) * 100, countsStore.nodeCount(0, NULL));
}
}
}
use of org.neo4j.internal.counts.GBPTreeCountsStore in project neo4j by neo4j.
the class BatchingNeoStores method buildCountsStore.
public void buildCountsStore(CountsBuilder builder, PageCacheTracer cacheTracer, CursorContext cursorContext, MemoryTracker memoryTracker) {
try {
deleteCountsStore();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
try (GBPTreeCountsStore countsStore = new GBPTreeCountsStore(pageCache, databaseLayout.countStore(), fileSystem, RecoveryCleanupWorkCollector.immediate(), builder, writable(), cacheTracer, GBPTreeCountsStore.NO_MONITOR, databaseName, neo4jConfig.get(counts_store_max_cached_entries))) {
countsStore.start(cursorContext, memoryTracker);
countsStore.checkpoint(cursorContext);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
use of org.neo4j.internal.counts.GBPTreeCountsStore in project neo4j by neo4j.
the class CountsComputerTest method skipPopulationWhenNodeAndRelationshipStoresAreEmpty.
@Test
void skipPopulationWhenNodeAndRelationshipStoresAreEmpty() throws IOException {
DatabaseManagementService managementService = dbBuilder.build();
GraphDatabaseAPI db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
long lastCommittedTransactionId = getLastTxId(db);
managementService.shutdown();
InvocationTrackingProgressReporter progressReporter = new InvocationTrackingProgressReporter();
rebuildCounts(lastCommittedTransactionId, progressReporter);
try (GBPTreeCountsStore store = createCountsStore(matchingBuilder(lastCommittedTransactionId))) {
store.start(NULL, INSTANCE);
softly.assertThat(store.txId()).as("Store Transaction id").isEqualTo(lastCommittedTransactionId);
store.accept(new AssertEmptyCountStoreVisitor(), NULL);
}
softly.assertThat(progressReporter.isCompleteInvoked()).as("Complete").isTrue();
softly.assertThat(progressReporter.isStartInvoked()).as("Start").isFalse();
}
Aggregations