use of com.orientechnologies.orient.server.distributed.ServerRun in project orientdb by orientechnologies.
the class IsolatedNodeRejoinScenarioTest method executeTest.
@Override
public void executeTest() throws Exception {
/*
* Test with quorum = 1
*/
banner("Test with quorum = 2");
System.out.print("\nChanging configuration (writeQuorum=2, autoDeploy=false)...");
ODocument cfg = null;
ServerRun server = serverInstance.get(2);
OHazelcastPlugin manager = (OHazelcastPlugin) server.getServerInstance().getDistributedManager();
OModifiableDistributedConfiguration databaseConfiguration = manager.getDatabaseConfiguration(getDatabaseName()).modify();
cfg = databaseConfiguration.getDocument();
cfg.field("writeQuorum", 2);
cfg.field("autoDeploy", true);
cfg.field("version", (Integer) cfg.field("version") + 1);
manager.updateCachedDatabaseConfiguration(getDatabaseName(), databaseConfiguration, true);
System.out.println("\nConfiguration updated.");
// isolating server3
System.out.println("Network fault on server3.\n");
simulateServerFault(serverInstance.get(2), "net-fault");
assertFalse(serverInstance.get(2).isActive());
// execute writes on server1 and server2
executeMultipleWrites(super.executeTestsOnServers, "plocal");
// server3 joins the cluster
System.out.println("Restart server3.\n");
try {
serverInstance.get(2).startServer(getDistributedServerConfiguration(server));
} catch (Exception e) {
fail();
}
// waiting for propagation
waitForMultipleInsertsInClassPropagation(1000L, "Person", 5000L);
// check consistency
super.checkWritesAboveCluster(serverInstance, executeTestsOnServers);
}
use of com.orientechnologies.orient.server.distributed.ServerRun in project orientdb by orientechnologies.
the class DeleteAndLazarusScenarioTest method executeTest.
@Override
public void executeTest() throws Exception {
/*
* Test with writeQuorum = majority
*/
banner("Test with writeQuorum = majority");
ODatabaseDocumentTx dbServer1 = poolFactory.get(getDatabaseURL(serverInstance.get(0)), "admin", "admin").acquire();
// changing configuration: readQuorum=2, autoDeploy=false
System.out.print("\nChanging configuration (autoDeploy=false)...");
ODocument cfg = null;
ServerRun server = serverInstance.get(2);
OHazelcastPlugin manager = (OHazelcastPlugin) server.getServerInstance().getDistributedManager();
ODistributedConfiguration databaseConfiguration = manager.getDatabaseConfiguration(getDatabaseName());
cfg = databaseConfiguration.getDocument();
System.out.println("\nConfiguration updated.");
// inserting record r1 and checking consistency on all the servers
try {
ODatabaseRecordThreadLocal.INSTANCE.set(dbServer1);
System.out.print("Inserting record r1...");
new ODocument("Person").fields("id", "R001", "firstName", "Luke", "lastName", "Skywalker").save();
System.out.println("Done.");
} catch (Exception e) {
e.printStackTrace();
fail("Record r1 not inserted!.");
}
waitForInsertedRecordPropagation("R001");
System.out.print("Checking consistency for record r1...");
ODocument r1onServer1 = retrieveRecord(getDatabaseURL(serverInstance.get(0)), "R001");
ODocument r1onServer2 = retrieveRecord(getDatabaseURL(serverInstance.get(1)), "R001");
ODocument r1onServer3 = retrieveRecord(getDatabaseURL(serverInstance.get(2)), "R001");
final ORecordId r1Rid = (ORecordId) r1onServer1.getIdentity();
assertEquals(r1onServer1.field("@version"), r1onServer2.field("@version"));
assertEquals(r1onServer1.field("id"), r1onServer2.field("id"));
assertEquals(r1onServer1.field("firstName"), r1onServer2.field("firstName"));
assertEquals(r1onServer1.field("lastName"), r1onServer2.field("lastName"));
assertEquals(r1onServer2.field("@version"), r1onServer3.field("@version"));
assertEquals(r1onServer2.field("id"), r1onServer3.field("id"));
assertEquals(r1onServer2.field("firstName"), r1onServer3.field("firstName"));
assertEquals(r1onServer2.field("lastName"), r1onServer3.field("lastName"));
System.out.println("\tDone.");
// initial version of the record r1
int initialVersion = r1onServer1.field("@version");
// isolating server3
System.out.println("Network fault on server3.\n");
simulateServerFault(serverInstance.get(2), "net-fault");
assertFalse(serverInstance.get(2).isActive());
waitForDatabaseIsOffline(serverInstance.get(2).getServerInstance().getDistributedManager().getLocalNodeName(), getDatabaseName(), 10000);
// updating r1 in r1* on server3
banner("Updating r1* on server3 (isolated from the the cluster)");
ODatabaseDocumentTx dbServer3 = null;
try {
r1onServer3 = retrieveRecord(getPlocalDatabaseURL(serverInstance.get(2)), "R001");
dbServer3 = new ODatabaseDocumentTx(getPlocalDatabaseURL(serverInstance.get(2))).open("admin", "admin");
r1onServer3.field("firstName", "Darth");
r1onServer3.field("lastName", "Vader");
r1onServer3.save();
System.out.println(r1onServer3.getRecord().toString());
} catch (Exception e) {
e.printStackTrace();
fail();
}
// restarting server3
serverInstance.get(2).startServer(getDistributedServerConfiguration(serverInstance.get(SERVERS - 1)));
System.out.println("Server 3 restarted.");
assertTrue(serverInstance.get(2).isActive());
waitForDatabaseIsOnline(2, serverInstance.get(2).getServerInstance().getDistributedManager().getLocalNodeName(), getDatabaseName(), 10000);
// reading r1* on server3
dbServer3 = poolFactory.get(getDatabaseURL(serverInstance.get(2)), "admin", "admin").acquire();
try {
r1onServer3 = retrieveRecord(getPlocalDatabaseURL(serverInstance.get(2)), "R001");
} catch (Exception e) {
e.printStackTrace();
} finally {
dbServer3.close();
}
// r1 was not modified both on server1 and server2
r1onServer1 = retrieveRecord(getDatabaseURL(serverInstance.get(0)), "R001");
r1onServer2 = retrieveRecord(getDatabaseURL(serverInstance.get(1)), "R001");
assertEquals(1, r1onServer1.field("@version"));
assertEquals("R001", r1onServer1.field("id"));
assertEquals("Luke", r1onServer1.field("firstName"));
assertEquals("Skywalker", r1onServer1.field("lastName"));
assertEquals(r1onServer1.field("@version"), r1onServer2.field("@version"));
assertEquals(r1onServer1.field("id"), r1onServer2.field("id"));
assertEquals(r1onServer1.field("firstName"), r1onServer2.field("firstName"));
assertEquals(r1onServer1.field("lastName"), r1onServer2.field("lastName"));
// checking we have different values for r1* on server3
assertEquals("R001", r1onServer3.field("id"));
assertEquals("Darth", r1onServer3.field("firstName"));
assertEquals("Vader", r1onServer3.field("lastName"));
assertEquals(initialVersion + 1, r1onServer3.field("@version"));
// shutdown server1
System.out.println("Network fault on server1.\n");
simulateServerFault(serverInstance.get(0), "net-fault");
assertFalse(serverInstance.get(0).isActive());
// delete request on server3 for r1*
dbServer3 = poolFactory.get(getDatabaseURL(serverInstance.get(2)), "admin", "admin").acquire();
try {
dbServer3.command(new OCommandSQL("delete from Person where @rid=#27:0")).execute();
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
dbServer3.close();
}
// restarting server1
serverInstance.get(0).startServer(getDistributedServerConfiguration(serverInstance.get(0)));
System.out.println("Server 1 restarted.");
assertTrue(serverInstance.get(0).isActive());
waitForDatabaseIsOnline(0, serverInstance.get(0).getServerInstance().getDistributedManager().getLocalNodeName(), getDatabaseName(), 10000);
// r1 is still present both on server1 and server2
r1onServer1 = retrieveRecord(getDatabaseURL(serverInstance.get(0)), "R001");
r1onServer2 = retrieveRecord(getDatabaseURL(serverInstance.get(1)), "R001");
assertEquals(1, r1onServer1.field("@version"));
assertEquals("R001", r1onServer1.field("id"));
assertEquals("Luke", r1onServer1.field("firstName"));
assertEquals("Skywalker", r1onServer1.field("lastName"));
assertEquals(r1onServer1.field("@version"), r1onServer2.field("@version"));
assertEquals(r1onServer1.field("id"), r1onServer2.field("id"));
assertEquals(r1onServer1.field("firstName"), r1onServer2.field("firstName"));
assertEquals(r1onServer1.field("lastName"), r1onServer2.field("lastName"));
// r1* is still present on server3
r1onServer3 = retrieveRecord(getDatabaseURL(serverInstance.get(2)), "R001");
assertEquals(2, r1onServer3.field("@version"));
assertEquals("R001", r1onServer3.field("id"));
assertEquals("Darth", r1onServer3.field("firstName"));
assertEquals("Vader", r1onServer3.field("lastName"));
waitForDatabaseIsOnline(0, serverInstance.get(2).getServerInstance().getDistributedManager().getLocalNodeName(), getDatabaseName(), 10000);
// delete request on server1 for r1
dbServer1 = poolFactory.get(getRemoteDatabaseURL(serverInstance.get(0)), "admin", "admin").acquire();
try {
Integer result = dbServer1.command(new OCommandSQL("delete from " + r1Rid)).execute();
} catch (Exception e) {
e.printStackTrace();
} finally {
dbServer1.close();
}
// r1 is no more present neither on server1, server2 nor server3
r1onServer1 = retrieveRecord(getDatabaseURL(serverInstance.get(0)), "R001", true, new OCallable<ODocument, ODocument>() {
@Override
public ODocument call(ODocument doc) {
assertEquals(MISSING_DOCUMENT, doc);
return null;
}
});
r1onServer2 = retrieveRecord(getDatabaseURL(serverInstance.get(1)), "R001", true, new OCallable<ODocument, ODocument>() {
@Override
public ODocument call(ODocument doc) {
assertEquals(MISSING_DOCUMENT, doc);
return null;
}
});
r1onServer3 = retrieveRecord(getDatabaseURL(serverInstance.get(2)), "R001", true, new OCallable<ODocument, ODocument>() {
@Override
public ODocument call(ODocument doc) {
assertEquals(MISSING_DOCUMENT, doc);
return null;
}
});
}
use of com.orientechnologies.orient.server.distributed.ServerRun in project orientdb by orientechnologies.
the class MultipleDBAlignmentOnNodesJoining method prepare.
/**
* Creates the databases as follows:
* - server1: db A, db B
* - server2: db B, db C
*
* @throws IOException
*/
@Override
protected void prepare(final boolean iCopyDatabaseToNodes, final boolean iCreateDatabase, final OCallable<Object, OrientGraphFactory> iCfgCallback) throws IOException {
serverInstance.remove(2);
// creating databases on server1
ServerRun master = serverInstance.get(0);
if (iCreateDatabase) {
final OrientBaseGraph graph1 = master.createDatabase(dbA, iCfgCallback);
final OrientBaseGraph graph2 = master.createDatabase(dbB, iCfgCallback);
try {
onAfterDatabaseCreation(graph1, "plocal:" + serverInstance.get(0).getDatabasePath(dbA));
onAfterDatabaseCreation(graph2, "plocal:" + serverInstance.get(0).getDatabasePath(dbB));
} finally {
if (!graph1.isClosed()) {
graph1.shutdown();
}
if (!graph1.isClosed()) {
graph2.shutdown();
}
}
}
// copying db-B on server2
if (iCopyDatabaseToNodes)
master.copyDatabase(dbB, serverInstance.get(1).getDatabasePath(dbB));
// creating db-C on server2
master = serverInstance.get(1);
if (iCreateDatabase) {
final OrientBaseGraph graph1 = master.createDatabase(dbC, iCfgCallback);
try {
onAfterDatabaseCreation(graph1, "plocal:" + serverInstance.get(1).getDatabasePath(dbC));
} finally {
if (!graph1.isClosed()) {
graph1.shutdown();
}
}
}
}
use of com.orientechnologies.orient.server.distributed.ServerRun in project orientdb by orientechnologies.
the class Quorum1ScenarioTest method executeTest.
@Override
public void executeTest() throws Exception {
/*
* Test with quorum = 1
*/
banner("Test with quorum = 1");
System.out.print("\nChanging configuration (writeQuorum=1, autoDeploy=false)...");
ODocument cfg = null;
ServerRun server = serverInstance.get(0);
OHazelcastPlugin manager = (OHazelcastPlugin) server.getServerInstance().getDistributedManager();
OModifiableDistributedConfiguration databaseConfiguration = manager.getDatabaseConfiguration(getDatabaseName()).modify();
cfg = databaseConfiguration.getDocument();
cfg.field("writeQuorum", 1);
cfg.field("autoDeploy", true);
cfg.field("version", (Integer) cfg.field("version") + 1);
manager.updateCachedDatabaseConfiguration(getDatabaseName(), databaseConfiguration, true);
System.out.println("\nConfiguration updated.");
// execute writes on server1 and server2
executeMultipleWrites(super.executeTestsOnServers, "plocal");
// waiting for propagation
waitForMultipleInsertsInClassPropagation(executeTestsOnServers.size() * writerCount * count, "Person", 5000L);
// check consistency
super.checkWritesAboveCluster(serverInstance, executeTestsOnServers);
}
use of com.orientechnologies.orient.server.distributed.ServerRun in project orientdb by orientechnologies.
the class WWConflictAndNodeInDeadlockScenarioTest method executeTest.
@Override
public void executeTest() throws Exception {
/*
* Test with quorum = 1
*/
banner("Test with quorum = 1");
ODatabaseDocumentTx dbServer1 = poolFactory.get(getDatabaseURL(serverInstance.get(0)), "admin", "admin").acquire();
ODatabaseDocumentTx dbServer2 = poolFactory.get(getDatabaseURL(serverInstance.get(1)), "admin", "admin").acquire();
ODatabaseDocumentTx dbServer3 = poolFactory.get(getDatabaseURL(serverInstance.get(2)), "admin", "admin").acquire();
// changing configuration: writeQuorum=1, autoDeploy=false
System.out.print("\nChanging configuration (writeQuorum=1, autoDeploy=false)...");
ODocument cfg = null;
ServerRun server = serverInstance.get(2);
OHazelcastPlugin manager = (OHazelcastPlugin) server.getServerInstance().getDistributedManager();
OModifiableDistributedConfiguration databaseConfiguration = manager.getDatabaseConfiguration(getDatabaseName()).modify();
cfg = databaseConfiguration.getDocument();
cfg.field("writeQuorum", 1);
cfg.field("version", (Integer) cfg.field("version") + 1);
manager.updateCachedDatabaseConfiguration(getDatabaseName(), databaseConfiguration, true);
System.out.println("\nConfiguration updated.");
// deadlock on server3
this.server3inDeadlock.set(true);
// waiting for deadlock
Thread.sleep(200);
// inserting record r1 and checking consistency on server1 and server2
System.out.print("Inserting record r1 and on server1 and checking consistency on both server1 and server2...");
ODatabaseRecordThreadLocal.INSTANCE.set(dbServer1);
ODocument r1onServer1 = new ODocument("Person").fields("id", "R001", "firstName", "Han", "lastName", "Solo");
r1onServer1.save();
Thread.sleep(200);
r1onServer1 = retrieveRecord(getDatabaseURL(serverInstance.get(1)), "R001");
ODocument r1onServer2 = retrieveRecord(getDatabaseURL(serverInstance.get(1)), "R001");
assertEquals(r1onServer1.field("@version"), r1onServer2.field("@version"));
assertEquals(r1onServer1.field("id"), r1onServer2.field("id"));
assertEquals(r1onServer1.field("firstName"), r1onServer2.field("firstName"));
assertEquals(r1onServer1.field("lastName"), r1onServer2.field("lastName"));
System.out.println("\tDone.");
// initial version of the record r1
int initialVersion = r1onServer1.field("@version");
// creating and executing two clients c1 and c2 (updating r1)
System.out.print("Building client c1 and client c2...");
List<Callable<Void>> clients = new LinkedList<Callable<Void>>();
clients.add(new RecordUpdater(getDatabaseURL(serverInstance.get(0)), r1onServer1, lukeFields, false));
clients.add(new RecordUpdater(getDatabaseURL(serverInstance.get(1)), r1onServer2, darthFields, false));
System.out.println("\tDone.");
ExecutorService executor = Executors.newCachedThreadPool();
System.out.println("Concurrent update:");
List<Future<Void>> futures = executor.invokeAll(clients);
try {
for (Future f : futures) {
f.get();
}
assertTrue("Concurrent update correctly managed!", true);
} catch (Exception e) {
e.printStackTrace();
fail("Concurrent update NOT correctly managed!");
System.out.println("Exception was thrown!");
}
// wait for propagation
Thread.sleep(500);
// end of deadlock on server3 and sync
try {
this.server3inDeadlock.set(false);
// waiting for sync of server3
Thread.sleep(500);
} catch (Exception e) {
e.printStackTrace();
fail("Exception was thrown!");
}
// check consistency
r1onServer1 = retrieveRecord(getDatabaseURL(serverInstance.get(0)), "R001");
r1onServer2 = retrieveRecord(getDatabaseURL(serverInstance.get(1)), "R001");
ODocument r1onServer3 = retrieveRecord(getDatabaseURL(serverInstance.get(2)), "R001");
ODatabaseRecordThreadLocal.INSTANCE.set(dbServer1);
r1onServer1.reload();
ODatabaseRecordThreadLocal.INSTANCE.set(dbServer2);
r1onServer2.reload();
ODatabaseRecordThreadLocal.INSTANCE.set(dbServer3);
r1onServer3.reload();
/**
* Checking records' values - CASE 1 - r1 on server1 has the values set by the client c1 - r1 on server2 has the values set by
* the client c2 - CASE 2 - r1 and r2 have the same value (case: the "remote-update-message" arrives on the current server
* before of the "local-update-message", e.g. due to delay in the stack)
*/
boolean case11 = false;
boolean case12 = false;
boolean case2 = false;
// r1 on server1 has the values set by the client c1
if (r1onServer1.field("firstName").equals("Luke") && r1onServer1.field("lastName").equals("Skywalker")) {
case11 = true;
System.out.println("The record on server1 has been updated by the client c1 without exceptions!");
}
// r1 on server2 has the values set by the client c2
if (r1onServer2.field("firstName").equals("Darth") && r1onServer2.field("lastName").equals("Vader")) {
case12 = true;
System.out.println("The record on server1 has been updated by the client c2 without exceptions!");
}
// message, e.g. due to delay in the stack)
if (r1onServer1.field("firstName").equals(r1onServer2.field("firstName")) && r1onServer1.field("lastName").equals(r1onServer2.field("lastName"))) {
case2 = true;
System.out.println("The record on server1 has been updated by the client c2 without exceptions!");
}
if ((case11 && case12) || case2) {
assertTrue("Condition for the records' values satisfied", true);
} else {
fail("Condition for the records' values NOT satisfied");
}
// r1 on server3 has the values set by the client c1 or the values set by the client c2, but not the old one
if ((r1onServer3.field("firstName").equals("Luke") && r1onServer3.field("lastName").equals("Skywalker")) || r1onServer3.field("firstName").equals("Darth") && r1onServer3.field("lastName").equals("Vader")) {
assertTrue("The record on server3 has been updated by a client without exceptions!", true);
} else {
fail("The record on server3 has not been updated by any client!");
}
// r1 has version x+1 on all the servers
System.out.printf("Checking version consistency among servers...");
int finalVersion = r1onServer1.field("@version");
assertEquals(finalVersion, initialVersion + 1);
assertEquals(r1onServer1.field("@version"), r1onServer2.field("@version"));
assertEquals(r1onServer2.field("@version"), r1onServer3.field("@version"));
System.out.println("Done.");
}
Aggregations