use of org.neo4j.kernel.impl.ha.ClusterManager in project neo4j by neo4j.
the class StoreMigratorTestUtil method buildClusterWithMasterDirIn.
public static ClusterManager.ManagedCluster buildClusterWithMasterDirIn(FileSystemAbstraction fs, final File legacyStoreDir, LifeSupport life, final Map<String, String> sharedConfig) throws Throwable {
File haRootDir = new File(legacyStoreDir.getParentFile(), "ha-migration");
fs.deleteRecursively(haRootDir);
ClusterManager clusterManager = new ClusterManager.Builder(haRootDir).withStoreDirInitializer((serverId, storeDir) -> {
if (// Initialize dir only for master, others will copy store from it
serverId == 1) {
FileUtils.copyRecursively(legacyStoreDir, storeDir);
}
}).withCluster(clusterOfSize(3)).withSharedConfig(sharedConfig).build();
life.add(clusterManager);
life.start();
return clusterManager.getCluster();
}
use of org.neo4j.kernel.impl.ha.ClusterManager in project neo4j by neo4j.
the class ClusterFailoverIT method testFailOver.
private void testFailOver(int clusterSize) throws Throwable {
// given
ClusterManager clusterManager = new ClusterManager.Builder().withRootDirectory(dir.cleanDirectory("failover")).withCluster(ClusterManager.clusterOfSize(clusterSize)).build();
clusterManager.start();
ClusterManager.ManagedCluster cluster = clusterManager.getCluster();
cluster.await(ClusterManager.allSeesAllAsAvailable());
HighlyAvailableGraphDatabase oldMaster = cluster.getMaster();
// When
long start = System.nanoTime();
ClusterManager.RepairKit repairKit = cluster.fail(oldMaster);
logger.getLogger().warning("Shut down master");
// Then
cluster.await(ClusterManager.masterAvailable(oldMaster));
long end = System.nanoTime();
logger.getLogger().warning("Failover took:" + (end - start) / 1000000 + "ms");
repairKit.repair();
// give repaired instance chance to cleanly rejoin and exit faster
Thread.sleep(3000);
clusterManager.safeShutdown();
}
use of org.neo4j.kernel.impl.ha.ClusterManager in project neo4j by neo4j.
the class ClusterPartitionIT method losingQuorumIncrementallyShouldMakeAllInstancesPendingAndReadOnly.
@Test
public void losingQuorumIncrementallyShouldMakeAllInstancesPendingAndReadOnly() throws Throwable {
// we need 5 to differentiate between all other instances gone and just quorum being gone
int clusterSize = 5;
assumeTrue(TestRunConditions.shouldRunAtClusterSize(clusterSize));
ClusterManager manager = new ClusterManager.Builder().withRootDirectory(dir.cleanDirectory("testcluster")).withCluster(ClusterManager.clusterOfSize(clusterSize)).withSharedConfig(config()).build();
try {
manager.start();
ClusterManager.ManagedCluster cluster = manager.getCluster();
cluster.await(allSeesAllAsAvailable());
cluster.await(masterAvailable());
HighlyAvailableGraphDatabase master = cluster.getMaster();
addSomeData(master);
/*
* we need 3 failures. We'll end up with the old master and a slave connected. They should both be in
* PENDING state, allowing reads but not writes. Repairing just one of the removed instances should
* result in a master being elected and all instances being read and writable.
* The instances we remove do not need additional verification for their state. Their behaviour is already
* known by other tests.
*/
HighlyAvailableGraphDatabase failed1;
ClusterManager.RepairKit rk1;
HighlyAvailableGraphDatabase failed2;
HighlyAvailableGraphDatabase failed3;
HighlyAvailableGraphDatabase remainingSlave;
failed1 = cluster.getAnySlave();
failed2 = cluster.getAnySlave(failed1);
failed3 = cluster.getAnySlave(failed1, failed2);
remainingSlave = cluster.getAnySlave(failed1, failed2, failed3);
CountDownLatch masterTransitionLatch = new CountDownLatch(1);
CountDownLatch slaveTransitionLatch = new CountDownLatch(1);
setupForWaitOnSwitchToDetached(master, masterTransitionLatch);
setupForWaitOnSwitchToDetached(remainingSlave, slaveTransitionLatch);
rk1 = killIncrementally(cluster, failed1, failed2, failed3);
cluster.await(memberSeesOtherMemberAsFailed(remainingSlave, failed1));
cluster.await(memberSeesOtherMemberAsFailed(remainingSlave, failed2));
cluster.await(memberSeesOtherMemberAsFailed(remainingSlave, failed3));
cluster.await(memberSeesOtherMemberAsFailed(master, failed1));
cluster.await(memberSeesOtherMemberAsFailed(master, failed2));
cluster.await(memberSeesOtherMemberAsFailed(master, failed3));
masterTransitionLatch.await();
slaveTransitionLatch.await();
ensureInstanceIsReadOnlyInPendingState(master);
ensureInstanceIsReadOnlyInPendingState(remainingSlave);
rk1.repair();
cluster.await(masterAvailable(failed2, failed3));
cluster.await(masterSeesSlavesAsAvailable(2));
ensureInstanceIsWritable(master);
ensureInstanceIsWritable(remainingSlave);
ensureInstanceIsWritable(failed1);
} finally {
manager.shutdown();
}
}
use of org.neo4j.kernel.impl.ha.ClusterManager in project neo4j by neo4j.
the class ClusterPartitionIT method isolatedMasterShouldRemoveSelfFromClusterAndBecomeReadOnly.
@Test
public void isolatedMasterShouldRemoveSelfFromClusterAndBecomeReadOnly() throws Throwable {
int clusterSize = 3;
ClusterManager manager = new ClusterManager.Builder().withRootDirectory(dir.cleanDirectory("testcluster")).withCluster(ClusterManager.clusterOfSize(clusterSize)).build();
try {
manager.start();
ClusterManager.ManagedCluster cluster = manager.getCluster();
cluster.await(allSeesAllAsAvailable());
cluster.await(masterAvailable());
HighlyAvailableGraphDatabase oldMaster = cluster.getMaster();
CountDownLatch masterTransitionLatch = new CountDownLatch(1);
setupForWaitOnSwitchToDetached(oldMaster, masterTransitionLatch);
addSomeData(oldMaster);
ClusterManager.RepairKit fail = cluster.fail(oldMaster, NetworkFlag.values());
cluster.await(instanceEvicted(oldMaster), 20);
masterTransitionLatch.await();
ensureInstanceIsReadOnlyInPendingState(oldMaster);
fail.repair();
cluster.await(allSeesAllAsAvailable());
ensureInstanceIsWritable(oldMaster);
} finally {
manager.safeShutdown();
}
}
use of org.neo4j.kernel.impl.ha.ClusterManager in project neo4j by neo4j.
the class ClusterTest method given4instanceClusterWhenMasterGoesDownThenElectNewMaster.
@Test
public void given4instanceClusterWhenMasterGoesDownThenElectNewMaster() throws Throwable {
ClusterManager clusterManager = new ClusterManager.Builder(testDirectory.directory("4instances")).withCluster(ClusterManager.clusterOfSize(4)).build();
try {
clusterManager.start();
ClusterManager.ManagedCluster cluster = clusterManager.getCluster();
cluster.await(allSeesAllAsAvailable());
logging.getLogger().info("STOPPING MASTER");
cluster.shutdown(cluster.getMaster());
logging.getLogger().info("STOPPED MASTER");
cluster.await(ClusterManager.masterAvailable());
GraphDatabaseService master = cluster.getMaster();
logging.getLogger().info("CREATE NODE");
try (Transaction tx = master.beginTx()) {
master.createNode();
logging.getLogger().info("CREATED NODE");
tx.success();
}
logging.getLogger().info("STOPPING CLUSTER");
} finally {
clusterManager.safeShutdown();
}
}
Aggregations