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();
}
}
}
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();
}
}
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();
}
}
}
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();
}
}
use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.
the class MasterInfoServiceTest method slaveShouldRespond404AndUNKNOWNWhenUnknown.
@Test
public void slaveShouldRespond404AndUNKNOWNWhenUnknown() throws Exception {
// given
HighlyAvailableGraphDatabase database = mock(HighlyAvailableGraphDatabase.class);
when(database.role()).thenReturn("unknown");
MasterInfoService service = new MasterInfoService(null, database);
// when
Response response = service.isSlave();
// then
assertEquals(404, response.getStatus());
assertEquals("UNKNOWN", String.valueOf(response.getEntity()));
}
Aggregations