Search in sources :

Example 6 with KernelAPI

use of org.neo4j.kernel.api.KernelAPI in project neo4j by neo4j.

the class ClusterDiscoveryIT method getMembers.

@SuppressWarnings("unchecked")
private List<Map<String, Object>> getMembers(GraphDatabaseFacade db) throws TransactionFailureException, org.neo4j.kernel.api.exceptions.ProcedureException {
    KernelAPI kernel = db.getDependencyResolver().resolveDependency(KernelAPI.class);
    KernelTransaction transaction = kernel.newTransaction(Type.implicit, AnonymousContext.read());
    try (Statement statement = transaction.acquireStatement()) {
        // when
        List<Object[]> currentMembers = asList(statement.procedureCallOperations().procedureCallRead(procedureName(GET_SERVERS_V1.fullyQualifiedProcedureName()), new Object[0]));
        return (List<Map<String, Object>>) currentMembers.get(0)[1];
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Statement(org.neo4j.kernel.api.Statement) List(java.util.List) Iterators.asList(org.neo4j.helpers.collection.Iterators.asList) Matchers.containsString(org.hamcrest.Matchers.containsString) KernelAPI(org.neo4j.kernel.api.KernelAPI)

Example 7 with KernelAPI

use of org.neo4j.kernel.api.KernelAPI in project neo4j by neo4j.

the class ClusterMembershipChangeIT method discoverClusterMembers.

private List<Object[]> discoverClusterMembers(GraphDatabaseFacade db) throws TransactionFailureException, org.neo4j.kernel.api.exceptions.ProcedureException {
    KernelAPI kernel = db.getDependencyResolver().resolveDependency(KernelAPI.class);
    KernelTransaction transaction = kernel.newTransaction(KernelTransaction.Type.implicit, AnonymousContext.read());
    Statement statement = transaction.acquireStatement();
    // when
    return asList(statement.procedureCallOperations().procedureCallRead(procedureName(GET_SERVERS_V1.fullyQualifiedProcedureName()), new Object[0]));
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Statement(org.neo4j.kernel.api.Statement) KernelAPI(org.neo4j.kernel.api.KernelAPI)

Example 8 with KernelAPI

use of org.neo4j.kernel.api.KernelAPI in project neo4j by neo4j.

the class ClusterOverviewIT method clusterOverview.

private List<MemberInfo> clusterOverview(GraphDatabaseFacade db) throws TransactionFailureException, ProcedureException {
    KernelAPI kernel = db.getDependencyResolver().resolveDependency(KernelAPI.class);
    KernelTransaction transaction = kernel.newTransaction(Type.implicit, AnonymousContext.read());
    List<MemberInfo> infos = new ArrayList<>();
    try (Statement statement = transaction.acquireStatement()) {
        RawIterator<Object[], ProcedureException> itr = statement.procedureCallOperations().procedureCallRead(procedureName("dbms", "cluster", ClusterOverviewProcedure.PROCEDURE_NAME), null);
        while (itr.hasNext()) {
            Object[] row = itr.next();
            Object[] addresses = (Object[]) row[1];
            infos.add(new MemberInfo(Arrays.copyOf(addresses, addresses.length, String[].class), Role.valueOf((String) row[2])));
        }
    }
    return infos;
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Statement(org.neo4j.kernel.api.Statement) ArrayList(java.util.ArrayList) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) KernelAPI(org.neo4j.kernel.api.KernelAPI)

Example 9 with KernelAPI

use of org.neo4j.kernel.api.KernelAPI in project neo4j by neo4j.

the class StoreUpgradeIntegrationTest method checkIndexCounts.

private static void checkIndexCounts(Store store, GraphDatabaseAPI db) throws KernelException {
    KernelAPI kernel = db.getDependencyResolver().resolveDependency(KernelAPI.class);
    try (KernelTransaction tx = kernel.newTransaction(KernelTransaction.Type.implicit, AnonymousContext.read());
        Statement statement = tx.acquireStatement()) {
        Iterator<NewIndexDescriptor> indexes = getAllIndexes(db);
        DoubleLongRegister register = Registers.newDoubleLongRegister();
        for (int i = 0; indexes.hasNext(); i++) {
            NewIndexDescriptor descriptor = indexes.next();
            // wait index to be online since sometimes we need to rebuild the indexes on migration
            awaitOnline(statement.readOperations(), descriptor);
            assertDoubleLongEquals(store.indexCounts[i][0], store.indexCounts[i][1], statement.readOperations().indexUpdatesAndSize(descriptor, register));
            assertDoubleLongEquals(store.indexCounts[i][2], store.indexCounts[i][3], statement.readOperations().indexSample(descriptor, register));
            double selectivity = statement.readOperations().indexUniqueValuesSelectivity(descriptor);
            assertEquals(store.indexSelectivity[i], selectivity, 0.0000001d);
        }
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Statement(org.neo4j.kernel.api.Statement) DoubleLongRegister(org.neo4j.register.Register.DoubleLongRegister) KernelAPI(org.neo4j.kernel.api.KernelAPI)

Example 10 with KernelAPI

use of org.neo4j.kernel.api.KernelAPI in project neo4j by neo4j.

the class StoreMigratorFrom21IT method mustMendDuplicatePropertiesWhenUpgradingFromVersion21.

@Test
public void mustMendDuplicatePropertiesWhenUpgradingFromVersion21() throws Exception {
    // The rules:
    // If an index is present, all duplicates should be removed and the property set to the value in the index
    // If an index is not present, the property should be set to the value of the last duplicate in the property
    // chain, all duplicates except the first should be removed
    // If an index is not present, the first property in the duplicate chain should be kept for the users
    // benefit, moved to a special property value, `__DUPLICATE_<propkey>`
    //
    // This is the broken store that we are upgrading:
    //
    //   (#0:Label { keyA: "actual", keyA: "phony!", keyA: "phony!" })
    //   (#1 { keyA: "actual", keyA: "actual", keyA: "actual" })
    //   (#2:Label { keyA: "real1", keyA: "phony", keyA: "phony", keyD: "real2", keyD: "phony", keyD: "phony" })
    //   (#3 { keyA: "real1", keyA: "phony", keyA: "phony", keyD: "real2", keyD: "phony", keyD: "phony" })
    //   (#4 { keyA: "actual", keyB: "actual", keyC: "actual" })
    //   (#0)-[#0:REL { keyA: "actual", keyA: "actual", keyA: "actual" }]->(#1)
    //   (#0)-[#1:REL { keyA: "real1", keyA: "phony", keyA: "phony",
    //                  keyD: "real2", keyE: "phony", keyF: "phony" }]->(#1)
    //   (#2)-[#2:REL { keyA: "actual", keyB: "actual", keyC: "actual" }]->(#0)
    //
    // And this is what we want to end up with, after upgrading:
    //
    //   (#0:Label { keyA: "actual" })
    //   (#1 { keyA: "actual", __DUPLICATE_keyA: "actual" })
    //   (#2:Label { keyA: "real1", keyD: "real2" })
    //   (#3 { keyA: "real1", __DUPLICATE_keyA_1: "real1", __DUPLICATE_keyA_2: "real1",
    //         keyD: "real2", __DUPLICATE_keyD_1: "real2", __DUPLICATE_keyD_2: "real2" })
    //   (#4 { keyA: "actual", keyB: "actual", keyC: "actual" })
    //   (#0)-[#0:REL { keyA: "actual", __DUPLICATE_keyA: "actual" }]->(#1)
    //   (#0)-[#1:REL { keyA: "real1", __DUPLICATE_keyA_1: "real1", __DUPLICATE_keyA_2: "real1",
    //                  keyD: "real2", __DUPLICATE_keyD_1: "real2", __DUPLICATE_keyD_2: "real2" }]->(#1)
    //   (#2)-[#2:REL { keyA: "actual", keyB: "actual", keyC: "actual" }]->(#0)
    File dir = MigrationTestUtils.find21FormatStoreDirectoryWithDuplicateProperties(storeDir.directory());
    TestGraphDatabaseFactory factory = new TestGraphDatabaseFactory();
    GraphDatabaseBuilder builder = factory.newEmbeddedDatabaseBuilder(dir).setConfig(GraphDatabaseSettings.allow_store_upgrade, "true");
    GraphDatabaseService database = builder.newGraphDatabase();
    database.shutdown();
    ConsistencyCheckService service = new ConsistencyCheckService();
    ConsistencyCheckService.Result result = service.runFullConsistencyCheck(dir.getAbsoluteFile(), Config.empty(), ProgressMonitorFactory.NONE, NullLogProvider.getInstance(), false);
    assertTrue(result.isSuccessful());
    database = builder.newGraphDatabase();
    // Upgrade is now completed. Verify the contents:
    DependencyResolver dependencyResolver = ((GraphDatabaseAPI) database).getDependencyResolver();
    // Verify that the properties appear correct to the outside world:
    try (Transaction ignore = database.beginTx()) {
        verifyProperties(database.getNodeById(0), Pair.of("keyA", new Object[] { "actual", "phony!", "phony!" }));
        verifyProperties(database.getNodeById(1), Pair.of("keyA", new Object[] { "actual", "actual", "actual" }));
        verifyProperties(database.getNodeById(2), Pair.of("keyA", new Object[] { "real1", "phony", "phony" }), Pair.of("keyD", new Object[] { "real2", "phony", "phony" }));
        verifyProperties(database.getNodeById(3), Pair.of("keyA", new Object[] { "real1", "real1", "real1" }), Pair.of("keyD", new Object[] { "real2", "real2", "real2" }));
        verifyProperties(database.getNodeById(4), Pair.of("keyA", new Object[] { "actual" }), Pair.of("keyB", new Object[] { "actual" }), Pair.of("keyC", new Object[] { "actual" }));
        verifyProperties(database.getRelationshipById(0), Pair.of("keyA", new Object[] { "actual", "actual", "actual" }));
        verifyProperties(database.getRelationshipById(1), Pair.of("keyA", new Object[] { "real1", "real1", "real1" }), Pair.of("keyD", new Object[] { "real2", "real2", "real2" }));
        verifyProperties(database.getRelationshipById(2), Pair.of("keyA", new Object[] { "actual" }), Pair.of("keyB", new Object[] { "actual" }), Pair.of("keyC", new Object[] { "actual" }));
    }
    // Verify that there are no two properties on the entities, that have the same key:
    // (This is important because the verification above cannot tell if we have two keys with the same value)
    KernelAPI kernel = dependencyResolver.resolveDependency(KernelAPI.class);
    try (KernelTransaction tx = kernel.newTransaction(KernelTransaction.Type.implicit, AnonymousContext.read());
        Statement statement = tx.acquireStatement()) {
        Iterators.asUniqueSet(statement.readOperations().nodeGetPropertyKeys(0));
        Iterators.asUniqueSet(statement.readOperations().nodeGetPropertyKeys(1));
        Iterators.asUniqueSet(statement.readOperations().nodeGetPropertyKeys(2));
        Iterators.asUniqueSet(statement.readOperations().relationshipGetPropertyKeys(0));
        Iterators.asUniqueSet(statement.readOperations().relationshipGetPropertyKeys(1));
    }
    database.shutdown();
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Statement(org.neo4j.kernel.api.Statement) DependencyResolver(org.neo4j.graphdb.DependencyResolver) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) File(java.io.File) KernelAPI(org.neo4j.kernel.api.KernelAPI) GraphDatabaseBuilder(org.neo4j.graphdb.factory.GraphDatabaseBuilder) Test(org.junit.Test)

Aggregations

KernelAPI (org.neo4j.kernel.api.KernelAPI)12 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)8 Statement (org.neo4j.kernel.api.Statement)8 CommunityCompatibilityFactory (org.neo4j.cypher.internal.CommunityCompatibilityFactory)3 GraphDatabaseCypherService (org.neo4j.cypher.javacompat.internal.GraphDatabaseCypherService)3 DependencyResolver (org.neo4j.graphdb.DependencyResolver)3 Monitors (org.neo4j.kernel.monitoring.Monitors)3 List (java.util.List)2 Test (org.junit.Test)2 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)2 LogService (org.neo4j.kernel.impl.logging.LogService)2 QueryExecutionEngine (org.neo4j.kernel.impl.query.QueryExecutionEngine)2 LogProvider (org.neo4j.logging.LogProvider)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 ConsistencyCheckService (org.neo4j.consistency.ConsistencyCheckService)1 EnterpriseCompatibilityFactory (org.neo4j.cypher.internal.EnterpriseCompatibilityFactory)1 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)1