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