Search in sources :

Example 1 with ClusterManager

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();
}
Also used : ClusterManager.clusterOfSize(org.neo4j.kernel.impl.ha.ClusterManager.clusterOfSize) Map(java.util.Map) FileUtils(org.neo4j.io.fs.FileUtils) IOException(java.io.IOException) ClusterManager(org.neo4j.kernel.impl.ha.ClusterManager) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) File(java.io.File) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) File(java.io.File) ClusterManager(org.neo4j.kernel.impl.ha.ClusterManager)

Example 2 with ClusterManager

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();
}
Also used : ClusterManager(org.neo4j.kernel.impl.ha.ClusterManager)

Example 3 with ClusterManager

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();
    }
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) ClusterManager(org.neo4j.kernel.impl.ha.ClusterManager) Test(org.junit.Test)

Example 4 with ClusterManager

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();
    }
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) ClusterManager(org.neo4j.kernel.impl.ha.ClusterManager) Test(org.junit.Test)

Example 5 with ClusterManager

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();
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) ClusterManager(org.neo4j.kernel.impl.ha.ClusterManager) Test(org.junit.Test)

Aggregations

ClusterManager (org.neo4j.kernel.impl.ha.ClusterManager)17 Test (org.junit.Test)14 File (java.io.File)5 HighlyAvailableGraphDatabase (org.neo4j.kernel.ha.HighlyAvailableGraphDatabase)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 Transaction (org.neo4j.graphdb.Transaction)3 ManagedCluster (org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster)3 RepairKit (org.neo4j.kernel.impl.ha.ClusterManager.RepairKit)3 IOException (java.io.IOException)2 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)2 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 After (org.junit.After)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Before (org.junit.Before)1 Rule (org.junit.Rule)1 Label (org.neo4j.graphdb.Label)1 TransactionTerminatedException (org.neo4j.graphdb.TransactionTerminatedException)1