use of com.tinkerpop.blueprints.impls.orient.OrientGraphFactory in project orientdb by orientechnologies.
the class BasicShardingNoReplicaScenarioTest method executeTest.
@Override
public void executeTest() throws Exception {
OHazelcastPlugin manager1 = (OHazelcastPlugin) serverInstance.get(0).getServerInstance().getDistributedManager();
final OModifiableDistributedConfiguration databaseConfiguration = manager1.getDatabaseConfiguration(this.getDatabaseName()).modify();
ODocument cfg = databaseConfiguration.getDocument();
OrientGraphFactory localFactory = new OrientGraphFactory("plocal:target/server0/databases/" + getDatabaseName());
OrientGraphNoTx graphNoTx = null;
try {
graphNoTx = localFactory.getNoTx();
final OrientVertexType clientType = graphNoTx.createVertexType("Client", 1);
OModifiableDistributedConfiguration dCfg = new OModifiableDistributedConfiguration(cfg);
for (int i = 0; i < serverInstance.size(); ++i) {
final String serverName = serverInstance.get(i).getServerInstance().getDistributedManager().getLocalNodeName();
clientType.addCluster("client_" + serverName);
dCfg.setServerOwner("client_" + serverName, serverName);
}
manager1.updateCachedDatabaseConfiguration(this.getDatabaseName(), dCfg, true);
final OrientVertexType.OrientVertexProperty prop = clientType.createProperty("name", OType.STRING);
prop.createIndex(OClass.INDEX_TYPE.NOTUNIQUE);
assertTrue(graphNoTx.getRawGraph().getMetadata().getIndexManager().existsIndex("Client.name"));
Thread.sleep(500);
graphNoTx.getRawGraph().close();
// writes on the three clusters
executeMultipleWritesOnShards(executeTestsOnServers, "plocal");
// check consistency (no-replica)
checkAvailabilityOnShardsNoReplica(serverInstance, executeTestsOnServers);
// network fault on server3
System.out.println("Shutdown on server3.\n");
simulateServerFault(serverInstance.get(2), "shutdown");
assertFalse(serverInstance.get(2).isActive());
waitForDatabaseIsOffline(executeTestsOnServers.get(2).getServerInstance().getDistributedManager().getLocalNodeName(), getDatabaseName(), 10000);
// check consistency (no-replica)
executeTestsOnServers.remove(2);
checkAvailabilityOnShardsNoReplica(executeTestsOnServers, executeTestsOnServers);
// this query doesn't return any result
try {
System.out.print("Checking that records on server3 are not available in the cluster...");
graphNoTx = localFactory.getNoTx();
ODatabaseRecordThreadLocal.INSTANCE.set(graphNoTx.getRawGraph());
final String uniqueId = "client_asia-s2-t10-v0";
Iterable<Vertex> it = graphNoTx.command(new OCommandSQL("select from Client where name = '" + uniqueId + "'")).execute();
List<OrientVertex> result = new LinkedList<OrientVertex>();
for (Vertex v : it) {
result.add((OrientVertex) v);
}
assertEquals(0, result.size());
System.out.println("Done");
graphNoTx.getRawGraph().close();
ODatabaseRecordThreadLocal.INSTANCE.set(null);
} 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(0, serverInstance.get(2).getServerInstance().getDistributedManager().getLocalNodeName(), getDatabaseName(), 10000);
// checking server3 status by querying a record inserted on it
try {
System.out.print("Checking server3 status by querying a record inserted on it...");
localFactory = new OrientGraphFactory("plocal:target/server2/databases/" + getDatabaseName());
graphNoTx = localFactory.getNoTx();
ODatabaseRecordThreadLocal.INSTANCE.set(graphNoTx.getRawGraph());
final String uniqueId = "client_asia-s2-t10-v0";
Iterable<Vertex> it = graphNoTx.command(new OCommandSQL("select from Client where name = '" + uniqueId + "'")).execute();
List<OrientVertex> result = new LinkedList<OrientVertex>();
for (Vertex v : it) {
result.add((OrientVertex) v);
}
assertEquals(1, result.size());
graphNoTx.getRawGraph().close();
ODatabaseRecordThreadLocal.INSTANCE.set(null);
} catch (Exception e) {
e.printStackTrace();
fail(e.toString());
}
// check consistency (no-replica)
executeTestsOnServers.add(serverInstance.get(2));
checkAvailabilityOnShardsNoReplica(serverInstance, executeTestsOnServers);
} catch (Exception e) {
e.printStackTrace();
fail(e.toString());
} finally {
if (!graphNoTx.getRawGraph().isClosed()) {
ODatabaseRecordThreadLocal.INSTANCE.set(graphNoTx.getRawGraph());
graphNoTx.getRawGraph().close();
ODatabaseRecordThreadLocal.INSTANCE.set(null);
}
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraphFactory in project orientdb by orientechnologies.
the class AbstractShardingScenarioTest method checkAvailabilityOnShardsNoReplica.
// checks the consistency in the cluster after the writes in a no-replica sharding scenario
protected void checkAvailabilityOnShardsNoReplica(List<ServerRun> checkConsistencyOnServers, List<ServerRun> writerServer) {
String checkOnServer = "";
for (ServerRun server : checkConsistencyOnServers) {
checkOnServer += server.getServerInstance().getDistributedManager().getLocalNodeName() + ",";
}
checkOnServer = checkOnServer.substring(0, checkOnServer.length() - 1);
String writtenServer = "";
for (ServerRun server : writerServer) {
writtenServer += server.getServerInstance().getDistributedManager().getLocalNodeName() + ",";
}
writtenServer = writtenServer.substring(0, writtenServer.length() - 1);
List<OrientBaseGraph> dbs = new LinkedList<OrientBaseGraph>();
OrientGraphFactory localFactory = null;
for (ServerRun server : checkConsistencyOnServers) {
localFactory = new OrientGraphFactory(getPlocalDatabaseURL(server));
dbs.add(localFactory.getNoTx());
}
Map<Integer, Integer> serverIndex2thresholdThread = new LinkedHashMap<Integer, Integer>();
Map<Integer, String> serverIndex2serverName = new LinkedHashMap<Integer, String>();
int lastThread = 0;
int serverIndex = 0;
for (ServerRun server : writerServer) {
serverIndex2thresholdThread.put(serverIndex, lastThread + 5);
serverIndex++;
lastThread += 5;
}
serverIndex = 0;
for (ServerRun server : writerServer) {
serverIndex2serverName.put(serverIndex, server.getServerInstance().getDistributedManager().getLocalNodeName());
serverIndex++;
}
List<OrientVertex> verticesToCheck = new LinkedList<OrientVertex>();
super.banner("Checking consistency among servers...\nChecking on servers {" + checkOnServer + "} that all the vertices written on {" + writtenServer + "} are consistent.");
try {
int index = 0;
String serverName = null;
for (int serverId : serverIndex2thresholdThread.keySet()) {
serverName = serverIndex2serverName.get(serverId);
System.out.println("Checking records originally inserted on server " + serverName + "...");
String clusterName = "client_" + serverName;
// checking records inserted on server0
int i;
if (serverId == 0)
i = 0;
else
i = serverIndex2thresholdThread.get(serverId - 1);
while (i < serverIndex2thresholdThread.get(serverId)) {
for (int j = 0; j < 100; j++) {
// load records to compare
for (OrientBaseGraph db : dbs) {
verticesToCheck.add(loadVertex(db, clusterName, serverId, i, j + baseCount));
}
// checking that record is present on each server db
OrientVertex currentVertex = null;
int k = 0;
while (k < verticesToCheck.size()) {
assertTrue(verticesToCheck.get(k) != null);
k++;
}
// checking that all the records have the same version and values (each record is equal to the next one)
k = 0;
while (k <= verticesToCheck.size() - 2) {
assertEquals(verticesToCheck.get(k).getProperty("@version"), verticesToCheck.get(k + 1).getProperty("@version"));
assertEquals(verticesToCheck.get(k).getProperty("name"), verticesToCheck.get(k + 1).getProperty("name"));
assertEquals(verticesToCheck.get(k).getProperty("updated"), verticesToCheck.get(k + 1).getProperty("updated"));
k++;
}
verticesToCheck.clear();
}
i++;
}
System.out.println("All records originally inserted on server " + serverName + " in the cluster " + clusterName + " available in the shard.");
index++;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
for (OrientBaseGraph db : dbs) {
ODatabaseRecordThreadLocal.INSTANCE.set(db.getRawGraph());
db.getRawGraph().close();
ODatabaseRecordThreadLocal.INSTANCE.set(null);
}
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraphFactory in project orientdb by orientechnologies.
the class AbstractShardingScenarioTest method executeMultipleWritesOnShards.
/*
* It executes multiple writes using different concurrent writers (as specified by the value writerCount) on all the servers
* present in the collection passed as parameter in a specific cluster-shards. Each write performs a vertex insert and some update
* and check operations on it. Vertex name: <shardName>-s<serverId>-t<threadId>-<recordId>
*/
protected void executeMultipleWritesOnShards(List<ServerRun> executeOnServers, String storageType) throws InterruptedException, ExecutionException {
System.out.println("Creating Writers threads...");
final ExecutorService writerExecutors = Executors.newCachedThreadPool();
runningWriters = new CountDownLatch(executeOnServers.size() * writerCount);
String shardName = "client_";
int serverId = 0;
int threadId = 0;
List<Callable<Void>> writerWorkers = new ArrayList<Callable<Void>>();
for (ServerRun server : executeOnServers) {
if (server.isActive()) {
shardName += server.getServerInstance().getDistributedManager().getLocalNodeName();
for (int j = 0; j < writerCount; j++) {
Callable writer = null;
if (storageType.equals("plocal")) {
writer = new ShardWriter(serverId, shardName, threadId++, getPlocalDatabaseURL(server));
} else if (storageType.equals("remote")) {
writer = new ShardWriter(serverId, shardName, threadId++, getPlocalDatabaseURL(server));
}
writerWorkers.add(writer);
}
}
serverId++;
shardName = "client_";
}
expected = writerCount * count * serverId + baseCount;
List<Future<Void>> futures = writerExecutors.invokeAll(writerWorkers);
System.out.println("Threads started, waiting for the end");
for (Future<Void> future : futures) {
future.get();
}
writerExecutors.shutdown();
assertTrue(writerExecutors.awaitTermination(1, TimeUnit.MINUTES));
System.out.println("All writer threads have finished.");
// checking inserted vertices
OrientBaseGraph graph;
OrientGraphFactory graphFactory;
// checking total amount of records (map-reduce aggregation)
graphFactory = new OrientGraphFactory("plocal:target/server0/databases/" + getDatabaseName());
graph = graphFactory.getNoTx();
try {
OResultSet<ODocument> clients = new OCommandSQL("select from Client").execute();
int total = clients.size();
assertEquals(expected, total);
List<ODocument> result = new OCommandSQL("select count(*) from Client").execute();
total = ((Number) result.get(0).field("count")).intValue();
// assertEquals(expected, total);
} finally {
graph.getRawGraph().close();
}
serverId = 0;
for (ServerRun server : serverInstance) {
if (server.isActive()) {
graphFactory = new OrientGraphFactory("plocal:target/server" + serverId + "/databases/" + getDatabaseName());
graph = graphFactory.getNoTx();
try {
String sqlCommand = "select from cluster:client_" + server.getServerInstance().getDistributedManager().getLocalNodeName();
List<ODocument> result = new OCommandSQL(sqlCommand).execute();
int total = result.size();
// assertEquals(count * writerCount, total);
sqlCommand = "select count(*) from cluster:client_" + server.getServerInstance().getDistributedManager().getLocalNodeName();
result = new OCommandSQL(sqlCommand).execute();
total = ((Number) result.get(0).field("count")).intValue();
// assertEquals(count * writerCount, total);
} catch (Exception e) {
e.printStackTrace();
} finally {
graph.getRawGraph().close();
}
}
serverId++;
}
// checking indexes
// serverId = 0;
// for (ServerRun server : serverInstance) {
// if (server.isActive()) {
// graphFactory = new OrientGraphFactory("plocal:target/server" + serverId + "/databases/" + getDatabaseName());
// graph = graphFactory.getNoTx();
// try {
// final long indexSize = graph.getRawGraph().getMetadata().getIndexManager().getIndex("Client.name").getSize();
//
// if (indexSize != count) {
// // ERROR: DUMP ALL THE RECORDS
// List<ODocument> result = graph.command(new OCommandSQL("select from index:Client.name")).execute();
// int i = 0;
// for (ODocument d : result) {
// System.out.println((i++) + ": " + ((OIdentifiable) d.field("rid")).getRecord());
// }
// }
//
// junit.framework.Assert.assertEquals(count, indexSize);
//
// System.out.println("From metadata: indexes " + indexSize + " items");
//
// List<ODocument> result = graph.command(new OCommandSQL("select count(*) from index:Client.name")).execute();
// junit.framework.Assert.assertEquals(count, ((Long) result.get(0).field("count")).longValue());
//
// System.out.println("From sql: indexes " + indexSize + " items");
// } finally {
// graph.getRawGraph().close();
// }
// }
// serverId++;
// }
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraphFactory in project orientdb by orientechnologies.
the class TestDistributedDatabaseRepair method executeTest.
@Override
protected void executeTest() throws Exception {
final OrientGraphFactory localFactory0 = new OrientGraphFactory("plocal:target/server0/databases/" + getDatabaseName(), false);
final OrientGraphFactory localFactory1 = new OrientGraphFactory("plocal:target/server1/databases/" + getDatabaseName(), false);
final OrientGraphFactory localFactory2 = new OrientGraphFactory("plocal:target/server2/databases/" + getDatabaseName(), false);
try {
final OrientGraphNoTx graph = localFactory0.getNoTx();
graph.createVertexType("ProductType");
graph.shutdown();
testNoWinner(localFactory0, localFactory1, localFactory2);
testWinnerIsMajority(localFactory0, localFactory1, localFactory2);
testWinnerIsMajorityPlusVersion(localFactory0, localFactory1, localFactory2);
// testRepairClusters(localFactory0, localFactory1, localFactory2);
} finally {
localFactory0.close();
localFactory1.close();
localFactory2.close();
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraphFactory in project orientdb by orientechnologies.
the class BareBonesServer method createDB.
public void createDB(String orientUrl) {
OLogManager.instance().info(this, "creating the database:" + orientUrl);
OrientGraphFactory factory = new OrientGraphFactory(orientUrl);
OrientBaseGraph graph = factory.getTx();
graph.executeOutsideTx(new OCallable<Object, OrientBaseGraph>() {
@Override
public Object call(OrientBaseGraph g) {
if (g.getEdgeType("edgetype") == null)
g.createEdgeType("edgetype");
if (g.getVertexType("vertextype") == null)
g.createVertexType("vertextype");
return null;
}
});
graph.shutdown();
factory.close();
}
Aggregations