use of com.orientechnologies.orient.server.distributed.impl.OLocalClusterWrapperStrategy in project orientdb by orientechnologies.
the class DistributedDatabaseCRUDTest method startSQLUpdateThread.
private Runnable startSQLUpdateThread(final int id, final OrientGraphFactory graphFactory, final String propertyValue) {
Runnable th = new Runnable() {
@Override
public void run() {
log("Starting runnable for sql update thread for property " + propertyValue);
long st = System.currentTimeMillis();
try {
boolean isRunning = true;
for (int i = 1; i < 10000000 && isRunning; i++) {
if ((i % 100) == 0) {
long et = System.currentTimeMillis();
log(" [" + id + "] Total Records Processed: [" + i + "] Time taken for [100] records: [" + (et - st) / 1000 + "] seconds");
st = System.currentTimeMillis();
}
OrientGraph graph = graphFactory.getTx();
if (!graph.getRawGraph().getURL().startsWith("remote:"))
Assert.assertTrue(graph.getVertexType("TestNode").getClusterSelection() instanceof OLocalClusterWrapperStrategy);
try {
boolean update = true;
boolean isException = false;
Exception tex = null;
String sql = "Update TestNode set prop5='" + String.valueOf(System.currentTimeMillis()) + "'" + ", prop-7='value7-1', prop-8='value8-1', prop-9='value9-1',prop-10='value10-1', prop11='value11-1'" + ", prop-07='value07-1', prop-08='value08-1', prop-09='value09-1',prop-010='value010-1', prop011='value011-1'" + ", prop12='vaue12-1', prop13='value13-1'" + ", updateTime='" + new Date().toString() + "' where property4='" + propertyValue + "'";
int k = 1;
for (; k <= 100 && update; k++) {
try {
graph.command(new OCommandSQL(sql)).execute();
if (isException) {
// log("********** [" + id + "][" + k + "] Update success after distributed lock Exception");
}
update = false;
break;
} catch (Exception ex) {
if (ex instanceof ODatabaseException || ex instanceof ONeedRetryException || ex instanceof ODistributedException) {
tex = ex;
if (ex instanceof ONeedRetryException || ex.getCause() instanceof ONeedRetryException) {
// log("[" + id + "][" + propertyValue + "][ Retry: " + k + "] OrientDB Exception [" + ex + "]");
try {
Thread.sleep(new Random().nextInt(500));
} catch (InterruptedException e) {
e.printStackTrace();
}
} else {
log("[" + id + "][ Retry: " + k + "] Failed to update. OrientDB Exception [" + ex + "]");
}
isException = true;
} else {
tex = ex;
log("[" + id + "][" + k + "] Failed non OrientDB Exception [" + ex + "]");
}
if (update) {
log("*******#################******* [" + id + "][ Retry: " + k + "] Failed to update after Exception [" + ((tex != null) ? tex : "----") + "] for vertex with property4='" + propertyValue + "'");
}
}
}
} finally {
graph.shutdown();
}
}
} catch (Exception ex) {
System.out.println("ID: [" + id + "]********** Exception " + ex + " \n\n");
ex.printStackTrace();
} finally {
log("[" + id + "] Done................>>>>>>>>>>>>>>>>>>");
}
}
};
return th;
}
use of com.orientechnologies.orient.server.distributed.impl.OLocalClusterWrapperStrategy in project orientdb by orientechnologies.
the class HALocalGraphTest method startThread.
private Runnable startThread(final int id, final OrientGraphFactory graphFactory) {
Runnable th = new Runnable() {
@Override
public void run() {
// OrientBaseGraph graph = new OrientGraph(getDBURL());
// OrientGraph graph = graphFactory.getTx();
boolean useSQL = false;
StringBuilder sb = new StringBuilder(".");
for (int m = 0; m < id; m++) {
sb.append(".");
}
long st = System.currentTimeMillis();
try {
String query = "select from Test where prop2='v2-1'";
boolean isRunning = true;
for (int i = 1; i < TOTAL_CYCLES_PER_THREAD && isRunning; i++) {
if ((i % 2500) == 0) {
long et = System.currentTimeMillis();
log(sb.toString() + " [" + id + "] Total Records Processed: [" + i + "] Current: [2500] Time taken: [" + (et - st) / 1000 + "] seconds");
st = System.currentTimeMillis();
}
if (sleep > 0)
Thread.sleep(sleep);
OrientGraph graph = graphFactory.getTx();
if (!graph.getRawGraph().getURL().startsWith("remote:"))
Assert.assertTrue(graph.getVertexType("Test").getClusterSelection() instanceof OLocalClusterWrapperStrategy);
try {
if (useSQL) {
boolean update = true;
boolean isException = false;
String sql = "Update Test set prop5='" + String.valueOf(System.currentTimeMillis()) + "', updateTime='" + new Date().toString() + "' where prop2='v2-1'";
for (int k = 0; k < 10 && update; k++) {
try {
graph.command(new OCommandSQL(sql)).execute();
if (isException) {
log("********** [" + id + "][" + k + "] Update success after distributed lock Exception");
}
update = false;
break;
} catch (ONeedRetryException ex) {
if (ex instanceof OConcurrentModificationException || ex.getCause() instanceof OConcurrentModificationException) {
} else {
isException = true;
log("*$$$$$$$$$$$$$$ [" + id + "][" + k + "] Distributed Exception: [" + ex + "] Cause: [" + (ex.getCause() != null ? ex.getCause() : "--") + "] ");
}
} catch (ODistributedException ex) {
if (ex.getCause() instanceof OConcurrentModificationException) {
} else {
isException = true;
log("*$$$$$$$$$$$$$$ [" + id + "][" + k + "] Distributed Exception: [" + ex + "] Cause: [" + (ex.getCause() != null ? ex.getCause() : "--") + "] ");
}
} catch (Exception ex) {
log("[" + id + "][" + k + "] Exception " + ex);
}
}
} else {
boolean retry = true;
Iterable<Vertex> vtxs = null;
for (int k = 0; k < 100 && retry; k++) try {
vtxs = graph.command(new OCommandSQL(query)).execute();
break;
} catch (ONeedRetryException e) {
// RETRY
}
for (Vertex vtx : vtxs) {
if (retry) {
retry = true;
boolean isException = false;
for (int k = 0; k < 100 && retry; k++) {
OrientVertex vtx1 = (OrientVertex) vtx;
try {
vtx1.setProperty("prop5", "prop55");
vtx1.setProperty("updateTime", new Date().toString());
vtx1.setProperty("blob", new byte[1000]);
graph.commit();
if (isException) {
// log("********** [" + id + "][" + k + "] Update success after distributed lock Exception for vertex " +
// vtx1);
}
retry = false;
break;
} catch (OConcurrentModificationException ex) {
vtx1.reload();
} catch (ONeedRetryException ex) {
if (ex instanceof ODistributedRecordLockedException) {
if (k > 20)
log("*$$$$$$$$$$$$$$ [" + id + "][" + k + "] ODistributedRecordLockedException: [" + ex + "] Cause: [" + (ex.getCause() != null ? ex.getCause() : "--") + "] for vertex " + vtx1);
vtx1.reload();
} else if (ex instanceof ONeedRetryException || ex.getCause() instanceof ONeedRetryException) {
vtx1.reload();
} else {
if (ex.getCause() instanceof ConcurrentModificationException) {
ex.printStackTrace();
}
log("*$$$$$$$$$$$$$$ [" + id + "][" + k + "] Distributed Exception: [" + ex + "] Cause: [" + (ex.getCause() != null ? ex.getCause() : "--") + "] for vertex " + vtx1);
}
// log("*** [" + id + "][" + k + "] Distributed Exception: [" + ex + "] Cause: [" + (ex.getCause() != null ?
// ex.getCause() : "--") + "] for vertex " + vtx1);
isException = true;
} catch (ODistributedException ex) {
if (ex.getCause() instanceof ONeedRetryException) {
vtx1.reload();
} else {
if (ex.getCause() instanceof ConcurrentModificationException) {
ex.printStackTrace();
}
log("*$$$$$$$$$$$$$$ [" + id + "][" + k + "] Distributed Exception: [" + ex + "] Cause: [" + (ex.getCause() != null ? ex.getCause() : "--") + "] for vertex " + vtx1);
}
// log("*** [" + id + "][" + k + "] Distributed Exception: [" + ex + "] Cause: [" + (ex.getCause() != null ?
// ex.getCause() : "--") + "] for vertex " + vtx1);
isException = true;
} catch (Exception ex) {
log("[" + id + "][" + k + "] Exception " + ex + " for vertex " + vtx1);
}
}
if (retry) {
log("********** [" + id + "] Failed to update after Exception for vertex " + vtx);
}
}
}
}
} finally {
graph.shutdown();
}
operations.incrementAndGet();
}
} catch (Exception ex) {
System.out.println("ID: [" + id + "]********** Exception " + ex + " \n\n");
ex.printStackTrace();
} finally {
log("[" + id + "] Done................>>>>>>>>>>>>>>>>>>");
}
}
};
return th;
}
use of com.orientechnologies.orient.server.distributed.impl.OLocalClusterWrapperStrategy in project orientdb by orientechnologies.
the class DistributedDatabaseCRUDTest method createDBData.
public void createDBData() {
log("Creating data for database " + dbName);
checkAndCreateDatabase(dbName);
int totalClassCount = 50;
int mainNodeDataCount = 50;
OrientBaseGraph orientGraph = new OrientGraphNoTx(getDBURL());
createVertexTypeWithUniqueIndex(orientGraph, "Test", "property1", "property2");
for (int i = 1; i <= totalClassCount; i++) {
createVertexType(orientGraph, "Test" + i, "property1", "property2");
}
orientGraph.shutdown();
OrientBaseGraph graph = getGraphFactory().getTx();
boolean addTestData = true;
String query = "select count(*) as dataCount from TestNode";
Iterable<Vertex> vtxs = graph.command(new OCommandSQL(query)).execute();
for (Vertex vtx : vtxs) {
long count = vtx.getProperty("dataCount");
addTestData = (count == 0);
}
if (addTestData) {
for (int i = 1; i <= mainNodeDataCount; i++) {
Vertex vertex = graph.addVertex("class:TestNode");
vertex.setProperty("property1", "value1-" + i);
vertex.setProperty("property2", "value2-" + i);
vertex.setProperty("property3", "value3-" + i);
vertex.setProperty("property4", "value4-" + i);
vertex.setProperty("prop-6", "value6-" + i);
vertex.setProperty("prop-7", "v7-1");
vertex.setProperty("prop-8", "v7-1");
vertex.setProperty("prop-9", "v7-1");
vertex.setProperty("prop-10", "v7-1");
vertex.setProperty("prop11", "v7-1");
vertex.setProperty("prop12", "v7-1");
vertex.setProperty("prop13", "v7-1");
vertex.setProperty("prop14", "v7-1");
vertex.setProperty("prop15", System.currentTimeMillis());
graph.commit();
if ((i % 100) == 0) {
log("Created " + i + " nodes");
}
if (!graph.getRawGraph().getURL().startsWith("remote:"))
Assert.assertTrue(graph.getVertexType("TestNode").getClusterSelection() instanceof OLocalClusterWrapperStrategy);
}
}
int edgeCounter = 1;
for (int j = 1; j <= totalClassCount; j++) {
String edgeName = "Test" + j;
String className = edgeName + "Node";
System.out.print("[" + className + "] -> ");
for (int i = 1; i <= totalRecords; i++) {
Vertex vertex = graph.addVertex("class:" + className);
vertex.setProperty("property1", "value1-" + i);
vertex.setProperty("property2", "value2-" + i);
vertex.setProperty("property3", "value3-" + i);
vertex.setProperty("property4", "value4-1");
vertex.setProperty("prop-6", "value6-" + i);
vertex.setProperty("prop-7", "value7-" + i);
vertex.setProperty("prop-8", "value7-1");
vertex.setProperty("prop-9", "value7-1");
vertex.setProperty("prop-10", "value7-1");
vertex.setProperty("prop11", "value7-1");
vertex.setProperty("prop12", "value7-1");
vertex.setProperty("prop13", "value7-1");
vertex.setProperty("prop14", System.currentTimeMillis());
vertex.setProperty("prop15", System.currentTimeMillis());
graph.commit();
if ((i % 200) == 0) {
System.out.print(".[" + j + "]" + i + ".");
}
String edgeSQL = "Create EDGE " + edgeName + " FROM (SELECT FROM TestNode WHERE property1='value1-" + edgeCounter + "') " + "TO (SELECT FROM " + className + " WHERE property1='value1-" + i + "') ";
edgeCounter++;
if (edgeCounter > mainNodeDataCount) {
edgeCounter = 1;
}
graph.command(new OCommandSQL(edgeSQL)).execute();
if (!graph.getRawGraph().getURL().startsWith("remote:"))
Assert.assertTrue(graph.getVertexType("TestNode").getClusterSelection() instanceof OLocalClusterWrapperStrategy);
}
System.out.println();
}
graph.shutdown();
log("Done. Creating data for database " + dbName);
}
use of com.orientechnologies.orient.server.distributed.impl.OLocalClusterWrapperStrategy in project orientdb by orientechnologies.
the class DistributedDatabaseCRUDTest method startVertexUpdateThread.
private Runnable startVertexUpdateThread(final int id, final OrientGraphFactory graphFactory, final String propertyValue) {
Runnable th = new Runnable() {
@Override
public void run() {
log("Starting runnable for vertex update thread for property value " + propertyValue);
long st = System.currentTimeMillis();
try {
// String query = "select from TestNode where property4='value4-1'";
String query = "select from TestNode where property4='" + propertyValue + "'";
boolean isRunning = true;
for (int i = 1; i < 100000000 && isRunning; i++) {
if ((i % 100) == 0) {
long et = System.currentTimeMillis();
log(" Total Records Processed: [" + i + "] Time taken for [100] records: [" + (et - st) / 1000 + "] seconds");
st = System.currentTimeMillis();
}
OrientGraph graph = graphFactory.getTx();
try {
Iterable<Vertex> vtxs = graph.command(new OCommandSQL(query)).execute();
boolean retry = true;
for (Vertex vtx : vtxs) {
if (retry) {
retry = true;
boolean isException = false;
Exception tex = null;
int k = 1;
for (; k <= 100 && retry; k++) {
if (!graph.getRawGraph().getURL().startsWith("remote:"))
Assert.assertTrue(graph.getVertexType("TestNode").getClusterSelection() instanceof OLocalClusterWrapperStrategy);
OrientVertex vtx1 = (OrientVertex) vtx;
try {
vtx1.setProperty("prop5", "prop55");
vtx1.setProperty("updateTime", new Date().toString());
graph.commit();
if (isException) {
// log("********** [" + id + "][" + k + "] Update success after distributed lock Exception for vertex " +
// vtx1);
}
retry = false;
break;
} catch (Exception ex) {
if (ex instanceof ODatabaseException || ex instanceof ONeedRetryException || ex instanceof ODistributedException) {
tex = ex;
if (ex instanceof ONeedRetryException || ex.getCause() instanceof ONeedRetryException) {
// log("[" + id + "][" + vtx + "][ Retry: " + k + "] OrientDB Exception [" + ex + "]");
try {
Thread.sleep(new Random().nextInt(500));
} catch (InterruptedException e) {
e.printStackTrace();
}
vtx1.reload();
} else {
log("[" + id + "][" + vtx + "][ Retry: " + k + "] Failed to update. OrientDB Exception [" + ex + "]");
}
isException = true;
} else {
tex = ex;
log("[" + id + "][" + k + "] Failed to update non OrientDB Exception [" + ex + "] for vertex [" + vtx1 + "]");
}
Thread.sleep(200);
}
}
if (retry) {
log("*******#################******* [" + id + "][" + vtx + "][ Retry: " + k + "] Failed to update after Exception [" + ((tex != null) ? tex : "----") + "]");
}
}
}
} finally {
graph.shutdown();
}
}
} catch (Exception ex) {
System.out.println("ID: [" + id + "]********** Exception " + ex + " \n\n");
ex.printStackTrace();
} finally {
log("[" + id + "] Done................>>>>>>>>>>>>>>>>>>");
}
}
};
return th;
}
Aggregations