use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.
the class ClusterLocksIT method lockCleanupOnModeSwitch.
@Test(timeout = TIMEOUT_MILLIS)
public void lockCleanupOnModeSwitch() throws Throwable {
HighlyAvailableGraphDatabase master = cluster.getMaster();
createNodeOnMaster(testLabel, master);
HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
ClusterManager.RepairKit repairKit = takeExclusiveLockAndKillSlave(testLabel, slave);
// repair of slave and new mode switch cycle on all members
repairKit.repair();
cluster.await(allSeesAllAsAvailable());
HighlyAvailableGraphDatabase clusterMaster = cluster.getMaster();
// now it should be possible to take exclusive lock on the same node
takeExclusiveLockOnSameNodeAfterSwitch(testLabel, master, clusterMaster);
}
use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.
the class ClusterManager method allSeesAllAsJoined.
public static Predicate<ManagedCluster> allSeesAllAsJoined() {
return new Predicate<ManagedCluster>() {
@Override
public boolean test(ManagedCluster cluster) {
int clusterSize = cluster.size();
int clusterMembersChecked = 0;
for (HighlyAvailableGraphDatabase database : cluster.getAllMembers()) {
clusterMembersChecked++;
ClusterMembers members = database.getDependencyResolver().resolveDependency(ClusterMembers.class);
if (count(members.getMembers()) < clusterSize) {
return false;
}
}
for (ObservedClusterMembers arbiter : cluster.getArbiters()) {
clusterMembersChecked++;
if (count(arbiter.getMembers()) < clusterSize) {
return false;
}
}
// Everyone sees everyone else as joined!
return clusterMembersChecked > 0;
}
@Override
public String toString() {
return "All instances should see all others as joined";
}
};
}
use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.
the class AutoIndexConfigIT method programmaticConfigShouldSurviveMasterSwitches.
@Test
public void programmaticConfigShouldSurviveMasterSwitches() throws Throwable {
String propertyToIndex = "programmatic-property";
// Given
ManagedCluster cluster = clusterRule.startCluster();
HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
AutoIndexer<Node> originalAutoIndex = slave.index().getNodeAutoIndexer();
originalAutoIndex.setEnabled(true);
originalAutoIndex.startAutoIndexingProperty(propertyToIndex);
// When
cluster.shutdown(cluster.getMaster());
cluster.await(masterAvailable());
// Then
AutoIndexer<Node> newAutoIndex = slave.index().getNodeAutoIndexer();
assertThat(newAutoIndex.isEnabled(), is(true));
assertThat(newAutoIndex.getAutoIndexedProperties(), hasItem(propertyToIndex));
}
use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.
the class IndexOperationsIT method index_modifications_are_propagated.
@Test
public void index_modifications_are_propagated() throws Exception {
// GIVEN
// -- a slave
String key = "name";
String value = "Mattias";
HighlyAvailableGraphDatabase author = cluster.getAnySlave();
// WHEN
// -- it creates a node associated with indexing in a transaction
long node = createNode(author, key, value, true);
// -- all instances should see it after pulling updates
for (HighlyAvailableGraphDatabase db : cluster.getAllMembers()) {
db.getDependencyResolver().resolveDependency(UpdatePuller.class).pullUpdates();
assertNodeAndIndexingExists(db, node, key, value);
}
}
use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.
the class IndexOperationsIT method index_objects_can_be_reused_after_role_switch.
@Test
public void index_objects_can_be_reused_after_role_switch() throws Throwable {
// GIVEN
// -- an existing index
String key = "key", value = "value";
HighlyAvailableGraphDatabase master = cluster.getMaster();
long nodeId = createNode(master, key, value, true);
cluster.sync();
// -- get Index and IndexManager references to all dbs
Map<HighlyAvailableGraphDatabase, IndexManager> indexManagers = new HashMap<>();
Map<HighlyAvailableGraphDatabase, Index<Node>> indexes = new HashMap<>();
for (HighlyAvailableGraphDatabase db : cluster.getAllMembers()) {
try (Transaction transaction = db.beginTx()) {
indexManagers.put(db, db.index());
indexes.put(db, db.index().forNodes(key));
transaction.success();
}
}
// WHEN
// -- there's a master switch
RepairKit repair = cluster.shutdown(master);
indexManagers.remove(master);
indexes.remove(master);
cluster.await(ClusterManager.masterAvailable(master));
cluster.await(ClusterManager.masterSeesSlavesAsAvailable(1));
// -- the index instances should still be viable to use
for (Map.Entry<HighlyAvailableGraphDatabase, IndexManager> entry : indexManagers.entrySet()) {
HighlyAvailableGraphDatabase db = entry.getKey();
try (Transaction transaction = db.beginTx()) {
IndexManager indexManager = entry.getValue();
assertTrue(indexManager.existsForNodes(key));
assertEquals(nodeId, indexManager.forNodes(key).get(key, value).getSingle().getId());
}
}
for (Map.Entry<HighlyAvailableGraphDatabase, Index<Node>> entry : indexes.entrySet()) {
HighlyAvailableGraphDatabase db = entry.getKey();
try (Transaction transaction = db.beginTx()) {
Index<Node> index = entry.getValue();
assertEquals(nodeId, index.get(key, value).getSingle().getId());
}
}
repair.repair();
}
Aggregations