Search in sources :

Example 6 with GraphDatabaseBuilder

use of org.neo4j.graphdb.factory.GraphDatabaseBuilder in project neo4j by neo4j.

the class BackupServiceStressTesting method shouldBehaveCorrectlyUnderStress.

@Test
public void shouldBehaveCorrectlyUnderStress() throws Exception {
    long durationInMinutes = parseLong(fromEnv("BACKUP_SERVICE_STRESS_DURATION", DEFAULT_DURATION_IN_MINUTES));
    String directory = fromEnv("BACKUP_SERVICE_STRESS_WORKING_DIRECTORY", DEFAULT_WORKING_DIR);
    String backupHostname = fromEnv("BACKUP_SERVICE_STRESS_BACKUP_HOSTNAME", DEFAULT_HOSTNAME);
    int backupPort = parseInt(fromEnv("BACKUP_SERVICE_STRESS_BACKUP_PORT", DEFAULT_PORT));
    String txPrune = fromEnv("BACKUP_SERVICE_STRESS_TX_PRUNE", DEFAULT_TX_PRUNE);
    boolean enableIndexes = parseBoolean(fromEnv("BACKUP_SERVICE_STRESS_ENABLE_INDEXES", DEFAULT_ENABLE_INDEXES));
    File store = new File(directory, "store");
    File work = new File(directory, "work");
    FileUtils.deleteRecursively(store);
    FileUtils.deleteRecursively(work);
    File storeDirectory = ensureExistsAndEmpty(store);
    File workDirectory = ensureExistsAndEmpty(work);
    final Map<String, String> config = configureBackup(configureTxLogRotationAndPruning(new HashMap<>(), txPrune), backupHostname, backupPort);
    GraphDatabaseBuilder graphDatabaseBuilder = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(storeDirectory.getAbsoluteFile()).setConfig(config);
    final AtomicBoolean stopTheWorld = new AtomicBoolean();
    BooleanSupplier notExpired = untilTimeExpired(durationInMinutes, MINUTES);
    Runnable onFailure = () -> stopTheWorld.set(true);
    BooleanSupplier keepGoingSupplier = () -> !stopTheWorld.get() && notExpired.getAsBoolean();
    AtomicReference<GraphDatabaseService> dbRef = new AtomicReference<>();
    ExecutorService service = Executors.newFixedThreadPool(3);
    try {
        dbRef.set(graphDatabaseBuilder.newGraphDatabase());
        if (enableIndexes) {
            WorkLoad.setupIndexes(dbRef.get());
        }
        Future<Throwable> workload = service.submit(new WorkLoad(keepGoingSupplier, onFailure, dbRef::get));
        Future<Throwable> backupWorker = service.submit(new BackupLoad(keepGoingSupplier, onFailure, backupHostname, backupPort, workDirectory));
        Future<Throwable> startStopWorker = service.submit(new StartStop(keepGoingSupplier, onFailure, graphDatabaseBuilder::newGraphDatabase, dbRef));
        long expirationTime = currentTimeMillis() + TimeUnit.MINUTES.toMillis(durationInMinutes + 5);
        assertSuccessfulExecution(workload, maxWaitTime(expirationTime), expirationTime);
        assertSuccessfulExecution(backupWorker, maxWaitTime(expirationTime), expirationTime);
        assertSuccessfulExecution(startStopWorker, maxWaitTime(expirationTime), expirationTime);
        service.shutdown();
        if (!service.awaitTermination(30, TimeUnit.SECONDS)) {
            ThreadTestUtils.dumpAllStackTraces();
            fail("Didn't manage to shut down the workers correctly, dumped threads for forensic purposes");
        }
    } finally {
        dbRef.get().shutdown();
        service.shutdown();
    }
    // let's cleanup disk space when everything went well
    FileUtils.deleteRecursively(storeDirectory);
    FileUtils.deleteRecursively(workDirectory);
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GraphDatabaseFactory(org.neo4j.graphdb.factory.GraphDatabaseFactory) ExecutorService(java.util.concurrent.ExecutorService) File(java.io.File) BooleanSupplier(java.util.function.BooleanSupplier) GraphDatabaseBuilder(org.neo4j.graphdb.factory.GraphDatabaseBuilder) Test(org.junit.Test)

Example 7 with GraphDatabaseBuilder

use of org.neo4j.graphdb.factory.GraphDatabaseBuilder in project blueprints by tinkerpop.

the class Neo4jBatchGraph method removeReferenceNodeAndFinalizeKeyIndices.

private void removeReferenceNodeAndFinalizeKeyIndices() {
    GraphDatabaseService rawGraphDB = null;
    try {
        GraphDatabaseBuilder builder = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(this.rawGraph.getStoreDir());
        if (this.vertexIndexKeys.size() > 0)
            builder.setConfig(GraphDatabaseSettings.node_keys_indexable, vertexIndexKeys.toString().replace("[", "").replace("]", "")).setConfig(GraphDatabaseSettings.node_auto_indexing, GraphDatabaseSetting.TRUE);
        if (this.edgeIndexKeys.size() > 0)
            builder.setConfig(GraphDatabaseSettings.relationship_keys_indexable, edgeIndexKeys.toString().replace("[", "").replace("]", "")).setConfig(GraphDatabaseSettings.relationship_auto_indexing, GraphDatabaseSetting.TRUE);
        rawGraphDB = builder.newGraphDatabase();
        Transaction tx = rawGraphDB.beginTx();
        try {
            rawGraphDB.getReferenceNode().delete();
            tx.success();
        } catch (Exception e) {
            tx.failure();
        } finally {
            tx.finish();
        }
        GlobalGraphOperations graphOperations = GlobalGraphOperations.at(rawGraphDB);
        if (this.vertexIndexKeys.size() > 0)
            populateKeyIndices(rawGraphDB, rawGraphDB.index().getNodeAutoIndexer(), graphOperations.getAllNodes(), Vertex.class);
        if (this.edgeIndexKeys.size() > 0)
            populateKeyIndices(rawGraphDB, rawGraphDB.index().getRelationshipAutoIndexer(), graphOperations.getAllRelationships(), Edge.class);
    } catch (Exception e) {
        throw new RuntimeException(e.getMessage(), e);
    } finally {
        if (rawGraphDB != null)
            rawGraphDB.shutdown();
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Vertex(com.tinkerpop.blueprints.Vertex) Transaction(org.neo4j.graphdb.Transaction) GraphDatabaseFactory(org.neo4j.graphdb.factory.GraphDatabaseFactory) Edge(com.tinkerpop.blueprints.Edge) GraphDatabaseBuilder(org.neo4j.graphdb.factory.GraphDatabaseBuilder) GlobalGraphOperations(org.neo4j.tooling.GlobalGraphOperations)

Example 8 with GraphDatabaseBuilder

use of org.neo4j.graphdb.factory.GraphDatabaseBuilder in project neo4j by neo4j.

the class ConflictingServerIdIT method testConflictingIdDoesNotSilentlyFail.

@Test
public void testConflictingIdDoesNotSilentlyFail() throws Exception {
    HighlyAvailableGraphDatabase master = null, dbWithId21 = null, dbWithId22 = null;
    try {
        GraphDatabaseBuilder masterBuilder = new TestHighlyAvailableGraphDatabaseFactory().newEmbeddedDatabaseBuilder(path(1)).setConfig(ClusterSettings.initial_hosts, "127.0.0.1:5002").setConfig(ClusterSettings.cluster_server, "127.0.0.1:" + (5001 + 1)).setConfig(ClusterSettings.server_id, "" + 1).setConfig(HaSettings.ha_server, ":" + (8001 + 1)).setConfig(HaSettings.tx_push_factor, "0");
        master = (HighlyAvailableGraphDatabase) masterBuilder.newGraphDatabase();
        GraphDatabaseBuilder db21Builder = new TestHighlyAvailableGraphDatabaseFactory().newEmbeddedDatabaseBuilder(path(2)).setConfig(ClusterSettings.initial_hosts, "127.0.0.1:5002,127.0.0.1:5003").setConfig(ClusterSettings.cluster_server, "127.0.0.1:" + (5001 + 2)).setConfig(ClusterSettings.server_id, "" + 2).setConfig(HaSettings.ha_server, ":" + (8001 + 2)).setConfig(HaSettings.tx_push_factor, "0");
        dbWithId21 = (HighlyAvailableGraphDatabase) db21Builder.newGraphDatabase();
        GraphDatabaseBuilder db22Builder = new TestHighlyAvailableGraphDatabaseFactory().newEmbeddedDatabaseBuilder(path(3)).setConfig(ClusterSettings.initial_hosts, "127.0.0.1:5002").setConfig(ClusterSettings.cluster_server, "127.0.0.1:" + (5001 + 3)).setConfig(ClusterSettings.server_id, // Conflicting with the above
        "" + 2).setConfig(HaSettings.ha_server, ":" + (8001 + 3)).setConfig(HaSettings.tx_push_factor, "0");
        try {
            dbWithId22 = (HighlyAvailableGraphDatabase) db22Builder.newGraphDatabase();
            fail("Should not be able to startup when a cluster already has my id");
        } catch (Exception e) {
        // awesome
        }
        assertTrue(master.isMaster());
        assertTrue(!dbWithId21.isMaster());
        try (Transaction transaction = dbWithId21.beginTx()) {
            transaction.success();
        }
    } finally {
        if (dbWithId21 != null) {
            dbWithId21.shutdown();
        }
        if (dbWithId22 != null) {
            dbWithId22.shutdown();
        }
        if (master != null) {
            master.shutdown();
        }
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) TestHighlyAvailableGraphDatabaseFactory(org.neo4j.graphdb.factory.TestHighlyAvailableGraphDatabaseFactory) GraphDatabaseBuilder(org.neo4j.graphdb.factory.GraphDatabaseBuilder) Test(org.junit.Test)

Example 9 with GraphDatabaseBuilder

use of org.neo4j.graphdb.factory.GraphDatabaseBuilder in project neo4j by neo4j.

the class CheckPointingLogRotationStressTesting method shouldBehaveCorrectlyUnderStress.

@Test
public void shouldBehaveCorrectlyUnderStress() throws Throwable {
    long durationInMinutes = parseLong(fromEnv("CHECK_POINT_LOG_ROTATION_STRESS_DURATION", DEFAULT_DURATION_IN_MINUTES));
    File storeDir = new File(fromEnv("CHECK_POINT_LOG_ROTATION_STORE_DIRECTORY", DEFAULT_STORE_DIR));
    long nodeCount = parseLong(fromEnv("CHECK_POINT_LOG_ROTATION_NODE_COUNT", DEFAULT_NODE_COUNT));
    int threads = parseInt(fromEnv("CHECK_POINT_LOG_ROTATION_WORKER_THREADS", DEFAULT_WORKER_THREADS));
    String pageCacheMemory = fromEnv("CHECK_POINT_LOG_ROTATION_PAGE_CACHE_MEMORY", DEFAULT_PAGE_CACHE_MEMORY);
    System.out.println("1/6\tBuilding initial store...");
    try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction()) {
        new ParallelBatchImporter(ensureExistsAndEmpty(storeDir), fileSystem, DEFAULT, NullLogService.getInstance(), ExecutionMonitors.defaultVisible(), Config.defaults()).doImport(new NodeCountInputs(nodeCount));
    }
    System.out.println("2/6\tStarting database...");
    GraphDatabaseBuilder builder = new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder(storeDir);
    GraphDatabaseService db = builder.setConfig(GraphDatabaseSettings.pagecache_memory, pageCacheMemory).setConfig(GraphDatabaseSettings.keep_logical_logs, Settings.FALSE).setConfig(GraphDatabaseSettings.check_point_interval_time, CHECK_POINT_INTERVAL_MINUTES + "m").setConfig(GraphDatabaseFacadeFactory.Configuration.tracer, "timer").newGraphDatabase();
    System.out.println("3/6\tWarm up db...");
    try (Workload workload = new Workload(db, defaultRandomMutation(nodeCount, db), threads)) {
        // make sure to run at least one checkpoint during warmup
        long warmUpTimeMillis = TimeUnit.SECONDS.toMillis(CHECK_POINT_INTERVAL_MINUTES * 2);
        workload.run(warmUpTimeMillis, Workload.TransactionThroughput.NONE);
    }
    System.out.println("4/6\tStarting workload...");
    TransactionThroughputChecker throughput = new TransactionThroughputChecker();
    try (Workload workload = new Workload(db, defaultRandomMutation(nodeCount, db), threads)) {
        workload.run(TimeUnit.MINUTES.toMillis(durationInMinutes), throughput);
    }
    System.out.println("5/6\tShutting down...");
    db.shutdown();
    try {
        System.out.println("6/6\tPrinting stats and recorded timings...");
        TimerTransactionTracer.printStats(System.out);
        throughput.assertThroughput(System.out);
    } finally {
        System.out.println("Done.");
    }
    // let's cleanup disk space when everything went well
    FileUtils.deleteRecursively(storeDir);
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) Workload(org.neo4j.kernel.stresstests.transaction.checkpoint.workload.Workload) ParallelBatchImporter(org.neo4j.unsafe.impl.batchimport.ParallelBatchImporter) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) File(java.io.File) GraphDatabaseBuilder(org.neo4j.graphdb.factory.GraphDatabaseBuilder) Test(org.junit.Test)

Example 10 with GraphDatabaseBuilder

use of org.neo4j.graphdb.factory.GraphDatabaseBuilder in project neo4j by neo4j.

the class DatabaseRebuildTool method newDbBuilder.

private static GraphDatabaseBuilder newDbBuilder(File path, Args args) {
    GraphDatabaseBuilder builder = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(path);
    for (Map.Entry<String, String> entry : args.asMap().entrySet()) {
        if (entry.getKey().startsWith("D")) {
            String key = entry.getKey().substring(1);
            String value = entry.getValue();
            builder = builder.setConfig(key, value);
        }
    }
    return builder;
}
Also used : GraphDatabaseFactory(org.neo4j.graphdb.factory.GraphDatabaseFactory) Map(java.util.Map) GraphDatabaseBuilder(org.neo4j.graphdb.factory.GraphDatabaseBuilder)

Aggregations

GraphDatabaseBuilder (org.neo4j.graphdb.factory.GraphDatabaseBuilder)21 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)8 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)8 File (java.io.File)6 Test (org.junit.Test)6 Transaction (org.neo4j.graphdb.Transaction)5 GraphDatabaseFactory (org.neo4j.graphdb.factory.GraphDatabaseFactory)5 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)5 Edge (com.tinkerpop.blueprints.Edge)2 Vertex (com.tinkerpop.blueprints.Vertex)2 Map (java.util.Map)2 GlobalGraphOperations (org.neo4j.tooling.GlobalGraphOperations)2 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 BooleanSupplier (java.util.function.BooleanSupplier)1 ConsistencyCheckService (org.neo4j.consistency.ConsistencyCheckService)1 AccessStatsKeepingStoreAccess (org.neo4j.consistency.statistics.AccessStatsKeepingStoreAccess)1