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();
}
}
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;
}
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.
}
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);
}
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();
}
Aggregations