Search in sources :

Example 1 with GBPTreeCountsStore

use of org.neo4j.internal.counts.GBPTreeCountsStore in project neo4j by neo4j.

the class CountsComputerTest method shouldCreateAnEmptyCountsStoreFromAnEmptyDatabase.

@Test
void shouldCreateAnEmptyCountsStoreFromAnEmptyDatabase() throws IOException {
    DatabaseManagementService managementService = dbBuilder.build();
    final GraphDatabaseAPI db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    long lastCommittedTransactionId = getLastTxId(db);
    managementService.shutdown();
    rebuildCounts(lastCommittedTransactionId);
    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);
    }
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) GBPTreeCountsStore(org.neo4j.internal.counts.GBPTreeCountsStore) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 2 with GBPTreeCountsStore

use of org.neo4j.internal.counts.GBPTreeCountsStore in project neo4j by neo4j.

the class CountsComputerTest method shouldCreateACountsStoreWhenThereAreNodesInTheDB.

@Test
void shouldCreateACountsStoreWhenThereAreNodesInTheDB() throws IOException, KernelException {
    DatabaseManagementService managementService = dbBuilder.build();
    final GraphDatabaseAPI db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    Label[] labels = null;
    int[] labelIds = null;
    Node[] nodes = null;
    try (Transaction tx = db.beginTx()) {
        labels = createLabels(4);
        labelIds = getLabelIdsFrom(tx, labels);
        nodes = new Node[] { tx.createNode(labels[0]), tx.createNode(labels[1]), tx.createNode(labels[2]), tx.createNode() };
        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(1);
        softly.assertThat(store.nodeCount(labelIds[3], NULL)).as("count: (:%s)", labels[3]).isEqualTo(0);
    }
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) GBPTreeCountsStore(org.neo4j.internal.counts.GBPTreeCountsStore) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 3 with GBPTreeCountsStore

use of org.neo4j.internal.counts.GBPTreeCountsStore in project neo4j by neo4j.

the class CountsComputerTest method shouldCreateACountStoreWhenDBContainsDenseNodes.

@Test
void shouldCreateACountStoreWhenDBContainsDenseNodes() throws IOException, KernelException {
    DatabaseManagementService managementService = dbBuilder.setConfig(GraphDatabaseSettings.dense_node_threshold, 2).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(5);
        relTypeIds = getRelTypeIdsFrom(tx, relTypes);
        nodes = new Node[] { tx.createNode(labels[0]), tx.createNode(labels[1]), tx.createNode(labels[2]) };
        rels = new Relationship[] { nodes[0].createRelationshipTo(nodes[0], relTypes[0]), nodes[0].createRelationshipTo(nodes[1], relTypes[1]), nodes[0].createRelationshipTo(nodes[2], relTypes[2]), nodes[2].createRelationshipTo(nodes[1], relTypes[3]) };
        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(1);
        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);
        softly.assertThat(store.relationshipCount(ANY_LABEL, relTypeIds[0], ANY_LABEL, NULL)).as("count: ()-[:%s]->()", relTypes[0]).isEqualTo(1);
        softly.assertThat(store.relationshipCount(ANY_LABEL, relTypeIds[1], ANY_LABEL, NULL)).as("count: ()-[:%s]->()", relTypes[1]).isEqualTo(1);
        softly.assertThat(store.relationshipCount(ANY_LABEL, relTypeIds[2], ANY_LABEL, NULL)).as("count: ()-[:%s]->()", relTypes[2]).isEqualTo(1);
        softly.assertThat(store.relationshipCount(ANY_LABEL, relTypeIds[3], ANY_LABEL, NULL)).as("count: ()-[:%s]->()", relTypes[3]).isEqualTo(1);
        softly.assertThat(store.relationshipCount(ANY_LABEL, relTypeIds[4], ANY_LABEL, NULL)).as("count: ()-[:%s]->()", relTypes[4]).isEqualTo(0);
        softly.assertThat(store.relationshipCount(ANY_LABEL, relTypeIds[1], labelIds[1], NULL)).as("count: ()-[:%s]->(:%s)", relTypes[1], labels[1]).isEqualTo(1);
        softly.assertThat(store.relationshipCount(ANY_LABEL, ANY_RELATIONSHIP_TYPE, labelIds[1], NULL)).as("count: ()-[]->(:%s)", labels[1]).isEqualTo(2);
        softly.assertThat(store.relationshipCount(labelIds[0], ANY_RELATIONSHIP_TYPE, ANY_LABEL, NULL)).as("count: (:%s)-[]->()", labels[0]).isEqualTo(3);
    }
}
Also used : Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) RelationshipType(org.neo4j.graphdb.RelationshipType) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Relationship(org.neo4j.graphdb.Relationship) GBPTreeCountsStore(org.neo4j.internal.counts.GBPTreeCountsStore) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 4 with GBPTreeCountsStore

use of org.neo4j.internal.counts.GBPTreeCountsStore in project neo4j by neo4j.

the class CountsComputerTest method shouldCreateACountsStoreWhenThereAreNodesAndRelationshipsInTheDB.

@Test
void shouldCreateACountsStoreWhenThereAreNodesAndRelationshipsInTheDB() 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(3);
        relTypeIds = getRelTypeIdsFrom(tx, relTypes);
        nodes = new Node[] { tx.createNode(labels[0]), tx.createNode(labels[1]), tx.createNode(labels[2]), tx.createNode() };
        rels = new Relationship[] { nodes[0].createRelationshipTo(nodes[2], relTypes[0]), nodes[3].createRelationshipTo(nodes[1], relTypes[1]) };
        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(1);
        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);
        softly.assertThat(store.relationshipCount(ANY_LABEL, relTypeIds[0], ANY_LABEL, NULL)).as("count: ()-[:%s]->()", relTypes[0]).isEqualTo(1);
        softly.assertThat(store.relationshipCount(ANY_LABEL, relTypeIds[1], ANY_LABEL, NULL)).as("count: ()-[:%s]->()", relTypes[1]).isEqualTo(1);
        softly.assertThat(store.relationshipCount(ANY_LABEL, relTypeIds[2], ANY_LABEL, NULL)).as("count: ()-[:%s]->()", relTypes[2]).isEqualTo(0);
        softly.assertThat(store.relationshipCount(ANY_LABEL, relTypeIds[1], labelIds[1], NULL)).as("count: ()-[:%s]->(:%s)", relTypes[1], labels[1]).isEqualTo(1);
        softly.assertThat(store.relationshipCount(ANY_LABEL, relTypeIds[0], labelIds[1], NULL)).as("count: ()-[:%s]->(:%s)", relTypes[0], labels[1]).isEqualTo(0);
    }
}
Also used : Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) RelationshipType(org.neo4j.graphdb.RelationshipType) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Relationship(org.neo4j.graphdb.Relationship) GBPTreeCountsStore(org.neo4j.internal.counts.GBPTreeCountsStore) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 5 with GBPTreeCountsStore

use of org.neo4j.internal.counts.GBPTreeCountsStore in project neo4j by neo4j.

the class CountsComputerTest method shouldCreateACountsStoreWhenThereAreUnusedNodeRecordsInTheDB.

@Test
void shouldCreateACountsStoreWhenThereAreUnusedNodeRecordsInTheDB() throws IOException, KernelException {
    DatabaseManagementService managementService = dbBuilder.build();
    final GraphDatabaseAPI db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    Label[] labels = null;
    int[] labelIds = null;
    Node[] nodes = null;
    try (Transaction tx = db.beginTx()) {
        labels = createLabels(4);
        labelIds = getLabelIdsFrom(tx, labels);
        nodes = new Node[] { tx.createNode(labels[0]), tx.createNode(labels[1]), tx.createNode(labels[2]), tx.createNode() };
        nodes[2].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 - 1);
        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);
    }
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) GBPTreeCountsStore(org.neo4j.internal.counts.GBPTreeCountsStore) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Aggregations

GBPTreeCountsStore (org.neo4j.internal.counts.GBPTreeCountsStore)12 Test (org.junit.jupiter.api.Test)10 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)7 Label (org.neo4j.graphdb.Label)6 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)6 Node (org.neo4j.graphdb.Node)5 Transaction (org.neo4j.graphdb.Transaction)5 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)5 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)5 IOException (java.io.IOException)3 Relationship (org.neo4j.graphdb.Relationship)3 RelationshipType (org.neo4j.graphdb.RelationshipType)3 CursorContext (org.neo4j.io.pagecache.context.CursorContext)3 CountsAccessor (org.neo4j.counts.CountsAccessor)2 CountsBuilder (org.neo4j.internal.counts.CountsBuilder)2 DefaultIdGeneratorFactory (org.neo4j.internal.id.DefaultIdGeneratorFactory)2 CountsComputer (org.neo4j.kernel.impl.store.CountsComputer)2 NeoStores (org.neo4j.kernel.impl.store.NeoStores)2 NodeStore (org.neo4j.kernel.impl.store.NodeStore)2 RelationshipStore (org.neo4j.kernel.impl.store.RelationshipStore)2