Search in sources :

Example 16 with HighlyAvailableGraphDatabase

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

Example 17 with HighlyAvailableGraphDatabase

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";
        }
    };
}
Also used : ObservedClusterMembers(org.neo4j.kernel.ha.cluster.member.ObservedClusterMembers) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) ClusterMembers(org.neo4j.kernel.ha.cluster.member.ClusterMembers) ObservedClusterMembers(org.neo4j.kernel.ha.cluster.member.ObservedClusterMembers) Predicate(java.util.function.Predicate)

Example 18 with HighlyAvailableGraphDatabase

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

Example 19 with HighlyAvailableGraphDatabase

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);
    }
}
Also used : HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) UpdatePuller(org.neo4j.kernel.ha.UpdatePuller) Test(org.junit.Test)

Example 20 with HighlyAvailableGraphDatabase

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();
}
Also used : HashMap(java.util.HashMap) Node(org.neo4j.graphdb.Node) Index(org.neo4j.graphdb.index.Index) IndexManager(org.neo4j.graphdb.index.IndexManager) Transaction(org.neo4j.graphdb.Transaction) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) RepairKit(org.neo4j.kernel.impl.ha.ClusterManager.RepairKit) HashMap(java.util.HashMap) Map(java.util.Map) 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