use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class IdBufferingRoleSwitchIT method createNodeWithProperties.
private Node createNodeWithProperties(GraphDatabaseService db, int numberOfProperties) {
try (Transaction tx = db.beginTx()) {
Node node = db.createNode();
for (int i = 0; i < numberOfProperties; i++) {
node.setProperty("key" + i, "value" + i);
}
tx.success();
return node;
}
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class IdBufferingRoleSwitchIT method deleteNode.
private void deleteNode(Node node, GraphDatabaseService db) {
try (Transaction tx = db.beginTx()) {
node.delete();
tx.success();
}
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class MeasureUpdatePullingRecordAndIndexGap method awaitIndexes.
private void awaitIndexes(ManagedCluster cluster) {
for (GraphDatabaseService db : cluster.getAllMembers()) {
try (Transaction tx = db.beginTx()) {
db.schema().awaitIndexesOnline(1, MINUTES);
tx.success();
}
}
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class SchemaIndexHaIT method createIndex.
private IndexDefinition createIndex(GraphDatabaseService db) {
try (Transaction tx = db.beginTx()) {
IndexDefinition index = db.schema().indexFor(label).on(key).create();
tx.success();
return index;
}
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class SchemaIndexHaIT method indexPopulationJobsShouldContinueThroughRoleSwitch.
@Test
public void indexPopulationJobsShouldContinueThroughRoleSwitch() throws Throwable {
// GIVEN a cluster of 3
ControlledGraphDatabaseFactory dbFactory = new ControlledGraphDatabaseFactory();
ManagedCluster cluster = clusterRule.withDbFactory(dbFactory).startCluster();
HighlyAvailableGraphDatabase firstMaster = cluster.getMaster();
// where the master gets some data created as well as an index
Map<Object, Node> data = createSomeData(firstMaster);
createIndex(firstMaster);
//dbFactory.awaitPopulationStarted( firstMaster );
dbFactory.triggerFinish(firstMaster);
// Pick a slave, pull the data and the index
HighlyAvailableGraphDatabase aSlave = cluster.getAnySlave();
aSlave.getDependencyResolver().resolveDependency(UpdatePuller.class).pullUpdates();
// and await the index population to start. It will actually block as long as we want it to
dbFactory.awaitPopulationStarted(aSlave);
// WHEN we shut down the master
cluster.shutdown(firstMaster);
dbFactory.triggerFinish(aSlave);
cluster.await(masterAvailable(firstMaster));
// get the new master, which should be the slave we pulled from above
HighlyAvailableGraphDatabase newMaster = cluster.getMaster();
// THEN
assertEquals("Unexpected new master", aSlave, newMaster);
try (Transaction tx = newMaster.beginTx()) {
IndexDefinition index = Iterables.single(newMaster.schema().getIndexes());
awaitIndexOnline(index, newMaster, data);
tx.success();
}
// FINALLY: let all db's finish
for (HighlyAvailableGraphDatabase db : cluster.getAllMembers()) {
dbFactory.triggerFinish(db);
}
}
Aggregations