Search in sources :

Example 1 with GraphDatabaseBuilder

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

the class DatabaseRebuildTool method run.

public void run(String... arguments) throws Exception {
    if (arguments.length == 0) {
        System.err.println("Tool for rebuilding database from transaction logs onto a new store");
        System.err.println("Example: dbrebuild --from path/to/some.db --to path/to/new.db apply next");
        System.err.println("         dbrebuild --from path/to/some.db --to path/to/new.db -i");
        System.err.println("          --from : which db to use as source for reading transactions");
        System.err.println("            --to : where to build the new db");
        System.err.println("  --overwrite-to : always starts from empty 'to' db");
        System.err.println("              -i : interactive mode (enter a shell)");
        return;
    }
    Args args = Args.withFlags("i", "overwrite-to").parse(arguments);
    File fromPath = getFrom(args);
    File toPath = getTo(args);
    GraphDatabaseBuilder dbBuilder = newDbBuilder(toPath, args);
    boolean interactive = args.getBoolean("i");
    if (interactive && !args.orphans().isEmpty()) {
        throw new IllegalArgumentException("No additional commands allowed in interactive mode");
    }
    @SuppressWarnings("resource") InputStream input = interactive ? in : oneCommand(args.orphansAsArray());
    LifeSupport life = new LifeSupport();
    ConsoleInput consoleInput = console(fromPath, dbBuilder, input, interactive ? staticPrompt("# ") : NO_PROMPT, life);
    life.start();
    try {
        consoleInput.waitFor();
    } finally {
        life.shutdown();
    }
}
Also used : Args(org.neo4j.helpers.Args) InputStream(java.io.InputStream) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) ConsoleInput(org.neo4j.tools.console.input.ConsoleInput) File(java.io.File) GraphDatabaseBuilder(org.neo4j.graphdb.factory.GraphDatabaseBuilder)

Example 2 with GraphDatabaseBuilder

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

the class TransactionGuardIntegrationTest method startCustomDatabase.

private GraphDatabaseAPI startCustomDatabase(File storeDir, Map<Setting<?>, String> configMap) {
    CustomClockCommunityFacadeFactory customClockCommunityFacadeFactory = new CustomClockCommunityFacadeFactory();
    GraphDatabaseBuilder databaseBuilder = new CustomGuardTestTestGraphDatabaseFactory(customClockCommunityFacadeFactory).newImpermanentDatabaseBuilder(storeDir);
    configMap.forEach(databaseBuilder::setConfig);
    GraphDatabaseAPI database = (GraphDatabaseAPI) databaseBuilder.newGraphDatabase();
    cleanupRule.add(database);
    return database;
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) GraphDatabaseBuilder(org.neo4j.graphdb.factory.GraphDatabaseBuilder)

Example 3 with GraphDatabaseBuilder

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

the class MetricsKernelExtensionFactoryIT method mustBeAbleToStartWithNullTracer.

@Test
public void mustBeAbleToStartWithNullTracer() throws Exception {
    // Start the database
    File disabledTracerDb = clusterRule.directory("disabledTracerDb");
    GraphDatabaseBuilder builder = new EnterpriseGraphDatabaseFactory().newEmbeddedDatabaseBuilder(disabledTracerDb);
    GraphDatabaseService nullTracerDatabase = builder.setConfig(MetricsSettings.neoEnabled, Settings.TRUE).setConfig(csvEnabled, Settings.TRUE).setConfig(csvPath, outputPath.getAbsolutePath()).setConfig(GraphDatabaseFacadeFactory.Configuration.tracer, // key point!
    "null").newGraphDatabase();
    try (Transaction tx = nullTracerDatabase.beginTx()) {
        Node node = nullTracerDatabase.createNode();
        node.setProperty("all", "is well");
        tx.success();
    } finally {
        nullTracerDatabase.shutdown();
    }
// We assert that no exception is thrown during startup or the operation of the database.
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) EnterpriseGraphDatabaseFactory(org.neo4j.graphdb.factory.EnterpriseGraphDatabaseFactory) Node(org.neo4j.graphdb.Node) File(java.io.File) GraphDatabaseBuilder(org.neo4j.graphdb.factory.GraphDatabaseBuilder) Test(org.junit.Test)

Example 4 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 5 with GraphDatabaseBuilder

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

the class JmxDocTest method startDb.

@BeforeClass
public static void startDb() throws Exception {
    File storeDir = test.graphDbDir();
    GraphDatabaseBuilder builder = new TestHighlyAvailableGraphDatabaseFactory().newEmbeddedDatabaseBuilder(storeDir);
    db = builder.setConfig(ClusterSettings.server_id, "1").setConfig(setting("jmx.port", STRING, NO_DEFAULT), "9913").setConfig(ClusterSettings.initial_hosts, ":5001").newGraphDatabase();
}
Also used : TestHighlyAvailableGraphDatabaseFactory(org.neo4j.graphdb.factory.TestHighlyAvailableGraphDatabaseFactory) File(java.io.File) GraphDatabaseBuilder(org.neo4j.graphdb.factory.GraphDatabaseBuilder) BeforeClass(org.junit.BeforeClass)

Aggregations

GraphDatabaseBuilder (org.neo4j.graphdb.factory.GraphDatabaseBuilder)23 GraphDatabaseFactory (org.neo4j.graphdb.factory.GraphDatabaseFactory)9 File (java.io.File)8 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)8 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)6 Test (org.junit.Test)5 Transaction (org.neo4j.graphdb.Transaction)5 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)4 Edge (com.tinkerpop.blueprints.Edge)2 Vertex (com.tinkerpop.blueprints.Vertex)2 Map (java.util.Map)2 TestHighlyAvailableGraphDatabaseFactory (org.neo4j.graphdb.factory.TestHighlyAvailableGraphDatabaseFactory)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 TinkerPopConfig (nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopConfig)1