Search in sources :

Example 71 with HighlyAvailableGraphDatabase

use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.

the class TestInstanceJoin method start.

private static HighlyAvailableGraphDatabase start(File storeDir, int i, Map<String, String> additionalConfig) {
    HighlyAvailableGraphDatabase db = (HighlyAvailableGraphDatabase) new TestHighlyAvailableGraphDatabaseFactory().newEmbeddedDatabaseBuilder(storeDir).setConfig(ClusterSettings.cluster_server, "127.0.0.1:" + (5001 + i)).setConfig(ClusterSettings.server_id, i + "").setConfig(HaSettings.ha_server, "127.0.0.1:" + (6666 + i)).setConfig(HaSettings.pull_interval, "0ms").setConfig(additionalConfig).newGraphDatabase();
    awaitStart(db);
    return db;
}
Also used : HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) TestHighlyAvailableGraphDatabaseFactory(org.neo4j.graphdb.factory.TestHighlyAvailableGraphDatabaseFactory)

Example 72 with HighlyAvailableGraphDatabase

use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.

the class TestInstanceJoin method makeSureSlaveCanJoinEvenIfTooFarBackComparedToMaster.

@Test
public void makeSureSlaveCanJoinEvenIfTooFarBackComparedToMaster() throws Exception {
    String key = "foo";
    String value = "bar";
    HighlyAvailableGraphDatabase master = null;
    HighlyAvailableGraphDatabase slave = null;
    File masterDir = testDirectory.directory("master");
    File slaveDir = testDirectory.directory("slave");
    try {
        master = start(masterDir, 0, stringMap(keep_logical_logs.name(), "1 txs", ClusterSettings.initial_hosts.name(), "127.0.0.1:5001"));
        createNode(master, "something", "unimportant");
        checkPoint(master);
        // Need to start and shutdown the slave so when we start it up later it verifies instead of copying
        slave = start(slaveDir, 1, stringMap(ClusterSettings.initial_hosts.name(), "127.0.0.1:5001,127.0.0.1:5002"));
        slave.shutdown();
        createNode(master, key, value);
        checkPoint(master);
        // Rotating, moving the above transactions away so they are removed on shutdown.
        rotateLog(master);
        /*
             * We need to shutdown - rotating is not enough. The problem is that log positions are cached and they
             * are not removed from the cache until we run into the cache limit. This means that the information
             * contained in the log can actually be available even if the log is removed. So, to trigger the case
             * of the master information missing from the master we need to also flush the log entry cache - hence,
             * restart.
             */
        master.shutdown();
        master = start(masterDir, 0, stringMap(keep_logical_logs.name(), "1 txs", ClusterSettings.initial_hosts.name(), "127.0.0.1:5001"));
        /**
             * The new log on master needs to have at least one transaction, so here we go.
             */
        int importantNodeCount = 10;
        for (int i = 0; i < importantNodeCount; i++) {
            createNode(master, key, value);
            checkPoint(master);
            rotateLog(master);
        }
        checkPoint(master);
        slave = start(slaveDir, 1, stringMap(ClusterSettings.initial_hosts.name(), "127.0.0.1:5001,127.0.0.1:5002"));
        slave.getDependencyResolver().resolveDependency(UpdatePuller.class).pullUpdates();
        try (Transaction ignore = slave.beginTx()) {
            assertEquals("store contents differ", importantNodeCount + 1, nodesHavingProperty(slave, key, value));
        }
    } finally {
        if (slave != null) {
            slave.shutdown();
        }
        if (master != null) {
            master.shutdown();
        }
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) UpdatePuller(org.neo4j.kernel.ha.UpdatePuller) File(java.io.File) Test(org.junit.Test)

Example 73 with HighlyAvailableGraphDatabase

use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.

the class ClusterTest method lastTxCommitTimestampShouldGetInitializedOnSlaveIfNotPresent.

@Test
public void lastTxCommitTimestampShouldGetInitializedOnSlaveIfNotPresent() throws Throwable {
    ClusterManager clusterManager = new ClusterManager.Builder(testDirectory.directory("lastTxTimestamp")).withCluster(ClusterManager.clusterOfSize(3)).build();
    try {
        clusterManager.start();
        ClusterManager.ManagedCluster cluster = clusterManager.getCluster();
        cluster.await(allSeesAllAsAvailable());
        runSomeTransactions(cluster.getMaster());
        cluster.sync();
        HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
        File storeDir = new File(slave.getStoreDir());
        ClusterManager.RepairKit slaveRepairKit = cluster.shutdown(slave);
        clearLastTransactionCommitTimestampField(storeDir);
        HighlyAvailableGraphDatabase repairedSlave = slaveRepairKit.repair();
        cluster.await(allSeesAllAsAvailable());
        assertEquals(lastCommittedTxTimestamp(cluster.getMaster()), lastCommittedTxTimestamp(repairedSlave));
    } finally {
        clusterManager.stop();
    }
}
Also used : HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) ClusterManager(org.neo4j.kernel.impl.ha.ClusterManager) File(java.io.File) Test(org.junit.Test)

Example 74 with HighlyAvailableGraphDatabase

use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.

the class ClusterTest method testInstancesWithConflictingClusterPorts.

@Test
public void testInstancesWithConflictingClusterPorts() throws Throwable {
    HighlyAvailableGraphDatabase first = null;
    try {
        File masterStoreDir = testDirectory.directory("testConflictingClusterPortsMaster");
        first = (HighlyAvailableGraphDatabase) new TestHighlyAvailableGraphDatabaseFactory().newEmbeddedDatabaseBuilder(masterStoreDir).setConfig(ClusterSettings.initial_hosts, "127.0.0.1:5001").setConfig(ClusterSettings.cluster_server, "127.0.0.1:5001").setConfig(ClusterSettings.server_id, "1").setConfig(HaSettings.ha_server, "127.0.0.1:6666").newGraphDatabase();
        try {
            File slaveStoreDir = testDirectory.directory("testConflictingClusterPortsSlave");
            HighlyAvailableGraphDatabase failed = (HighlyAvailableGraphDatabase) new TestHighlyAvailableGraphDatabaseFactory().newEmbeddedDatabaseBuilder(slaveStoreDir).setConfig(ClusterSettings.initial_hosts, "127.0.0.1:5001").setConfig(ClusterSettings.cluster_server, "127.0.0.1:5001").setConfig(ClusterSettings.server_id, "2").setConfig(HaSettings.ha_server, "127.0.0.1:6667").newGraphDatabase();
            failed.shutdown();
            fail("Should not start when ports conflict");
        } catch (Exception e) {
        // good
        }
    } finally {
        if (first != null) {
            first.shutdown();
        }
    }
}
Also used : HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) TestHighlyAvailableGraphDatabaseFactory(org.neo4j.graphdb.factory.TestHighlyAvailableGraphDatabaseFactory) File(java.io.File) TransientTransactionFailureException(org.neo4j.graphdb.TransientTransactionFailureException) IOException(java.io.IOException) TransactionTerminatedException(org.neo4j.graphdb.TransactionTerminatedException) Test(org.junit.Test)

Example 75 with HighlyAvailableGraphDatabase

use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.

the class ClusterTest method lastTxCommitTimestampShouldBeUnknownAfterStartIfNoFiledOrLogsPresent.

@Test
public void lastTxCommitTimestampShouldBeUnknownAfterStartIfNoFiledOrLogsPresent() throws Throwable {
    ClusterManager clusterManager = new ClusterManager.Builder(testDirectory.directory("lastTxTimestamp")).withCluster(ClusterManager.clusterOfSize(3)).build();
    try {
        clusterManager.start();
        ClusterManager.ManagedCluster cluster = clusterManager.getCluster();
        cluster.await(allSeesAllAsAvailable());
        runSomeTransactions(cluster.getMaster());
        cluster.sync();
        HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
        File storeDir = new File(slave.getStoreDir());
        ClusterManager.RepairKit slaveRepairKit = cluster.shutdown(slave);
        clearLastTransactionCommitTimestampField(storeDir);
        deleteLogs(storeDir);
        HighlyAvailableGraphDatabase repairedSlave = slaveRepairKit.repair();
        cluster.await(allSeesAllAsAvailable());
        assertEquals(TransactionIdStore.UNKNOWN_TX_COMMIT_TIMESTAMP, lastCommittedTxTimestamp(repairedSlave));
    } finally {
        clusterManager.stop();
    }
}
Also used : HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) ClusterManager(org.neo4j.kernel.impl.ha.ClusterManager) File(java.io.File) Test(org.junit.Test)

Aggregations

HighlyAvailableGraphDatabase (org.neo4j.kernel.ha.HighlyAvailableGraphDatabase)80 Test (org.junit.Test)68 Transaction (org.neo4j.graphdb.Transaction)38 ClusterManager (org.neo4j.kernel.impl.ha.ClusterManager)24 Node (org.neo4j.graphdb.Node)22 ManagedCluster (org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster)16 File (java.io.File)12 InstanceId (org.neo4j.cluster.InstanceId)10 Response (javax.ws.rs.core.Response)9 CountDownLatch (java.util.concurrent.CountDownLatch)8 TransientTransactionFailureException (org.neo4j.graphdb.TransientTransactionFailureException)5 TestHighlyAvailableGraphDatabaseFactory (org.neo4j.graphdb.factory.TestHighlyAvailableGraphDatabaseFactory)5 RepairKit (org.neo4j.kernel.impl.ha.ClusterManager.RepairKit)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 ClusterClient (org.neo4j.cluster.client.ClusterClient)4 TransactionTerminatedException (org.neo4j.graphdb.TransactionTerminatedException)4 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)4 IOException (java.io.IOException)3 URI (java.net.URI)3 ExecutionException (java.util.concurrent.ExecutionException)3