use of com.orientechnologies.orient.core.exception.ODatabaseException in project orientdb by orientechnologies.
the class TestExceptionNotOpen method testExceptionNotOpenPlocal.
@Test
public void testExceptionNotOpenPlocal() {
ODatabaseDocument db = new ODatabaseDocumentTx("plocal:./target/databaseCheck");
try {
db.save(new ODocument());
Assert.fail();
} catch (ODatabaseException ex) {
}
try {
db.delete(new ODocument());
Assert.fail();
} catch (ODatabaseException ex) {
}
try {
db.hide(new ORecordId());
Assert.fail();
} catch (ODatabaseException ex) {
}
try {
db.begin();
Assert.fail();
} catch (ODatabaseException ex) {
}
try {
db.begin(OTransaction.TXTYPE.NOTX);
Assert.fail();
} catch (ODatabaseException ex) {
}
try {
db.rollback();
Assert.fail();
} catch (ODatabaseException ex) {
}
try {
db.commit();
Assert.fail();
} catch (ODatabaseException ex) {
}
try {
db.getMetadata();
Assert.fail();
} catch (ODatabaseException ex) {
}
}
use of com.orientechnologies.orient.core.exception.ODatabaseException in project orientdb by orientechnologies.
the class OHazelcastPlugin method getRemoteServer.
public ORemoteServerController getRemoteServer(final String rNodeName) throws IOException {
if (rNodeName == null)
throw new IllegalArgumentException("Server name is NULL");
ORemoteServerController remoteServer = remoteServers.get(rNodeName);
if (remoteServer == null) {
Member member = activeNodes.get(rNodeName);
if (member == null) {
// SYNC PROBLEMS? TRY TO RETRIEVE THE SERVER INFORMATION FROM THE CLUSTER MAP
for (Iterator<Map.Entry<String, Object>> it = getConfigurationMap().localEntrySet().iterator(); it.hasNext(); ) {
final Map.Entry<String, Object> entry = it.next();
if (entry.getKey().startsWith(CONFIG_NODE_PREFIX)) {
final ODocument nodeCfg = (ODocument) entry.getValue();
if (rNodeName.equals(nodeCfg.field("name"))) {
// FOUND: USE THIS
final String uuid = entry.getKey().substring(CONFIG_NODE_PREFIX.length());
for (Member m : hazelcastInstance.getCluster().getMembers()) {
if (m.getUuid().equals(uuid)) {
member = m;
registerNode(member, rNodeName);
break;
}
}
}
}
}
if (member == null)
throw new ODistributedException("Cannot find node '" + rNodeName + "'");
}
for (int retry = 0; retry < 100; ++retry) {
ODocument cfg = getNodeConfigurationByUuid(member.getUuid(), false);
if (cfg == null || cfg.field("listeners") == null) {
try {
Thread.sleep(100);
continue;
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new ODistributedException("Cannot find node '" + rNodeName + "'");
}
}
final String url = ODistributedAbstractPlugin.getListeningBinaryAddress(cfg);
if (url == null)
throw new ODatabaseException("Cannot connect to a remote node because the url was not found");
final String userPassword = cfg.field("user_replicator");
if (userPassword != null) {
// OK
remoteServer = new ORemoteServerController(this, rNodeName, url, REPLICATOR_USER, userPassword);
final ORemoteServerController old = remoteServers.putIfAbsent(rNodeName, remoteServer);
if (old != null) {
remoteServer.close();
remoteServer = old;
}
break;
}
// RETRY TO GET USR+PASSWORD IN A WHILE
try {
Thread.sleep(100);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new OInterruptedException("Cannot connect to remote sevrer " + rNodeName);
}
}
}
if (remoteServer == null)
throw new ODistributedException("Cannot find node '" + rNodeName + "'");
return remoteServer;
}
use of com.orientechnologies.orient.core.exception.ODatabaseException in project orientdb by orientechnologies.
the class OCompleted2pcTask method execute.
@Override
public Object execute(final ODistributedRequestId msgId, final OServer iServer, ODistributedServerManager iManager, final ODatabaseDocumentInternal database) throws Exception {
ODistributedServerLog.debug(this, iManager.getLocalNodeName(), getNodeSource(), DIRECTION.IN, "%s transaction db=%s originalReqId=%s...", (success ? "Committing" : fixTasks.isEmpty() ? "Rolling back" : "Fixing"), database.getName(), requestId, requestId);
ODatabaseRecordThreadLocal.INSTANCE.set(database);
// UNLOCK ALL LOCKS ACQUIRED IN TX
final ODistributedDatabase ddb = iManager.getMessageService().getDatabase(database.getName());
if (ddb == null)
throw new ODatabaseException("Database '" + database.getName() + " is not available on server '" + iManager.getLocalNodeName() + "'");
final ODistributedTxContext pRequest = ddb.popTxContext(requestId);
try {
if (success) {
// COMMIT
if (pRequest != null)
pRequest.commit();
else {
// UNABLE TO FIND TX CONTEXT
ODistributedServerLog.debug(this, iManager.getLocalNodeName(), getNodeSource(), DIRECTION.IN, "Error on committing distributed transaction %s db=%s", requestId, database.getName());
return Boolean.FALSE;
}
} else if (fixTasks.isEmpty()) {
// ROLLBACK
if (pRequest != null)
pRequest.rollback(database);
else {
// UNABLE TO FIND TX CONTEXT
ODistributedServerLog.debug(this, iManager.getLocalNodeName(), getNodeSource(), DIRECTION.IN, "Error on rolling back distributed transaction %s db=%s", requestId, database.getName());
return Boolean.FALSE;
}
} else {
// FIX TRANSACTION CONTENT
if (pRequest != null)
pRequest.fix(database, fixTasks);
else {
// UNABLE TO FIX TX CONTEXT
ODistributedServerLog.debug(this, iManager.getLocalNodeName(), getNodeSource(), DIRECTION.IN, "Error on fixing distributed transaction %s db=%s", requestId, database.getName());
return Boolean.FALSE;
}
}
} finally {
if (pRequest != null)
pRequest.destroy();
}
return Boolean.TRUE;
}
use of com.orientechnologies.orient.core.exception.ODatabaseException 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.core.exception.ODatabaseException in project orientdb by orientechnologies.
the class DbDeleteTest method testDbDeleteNoCredential.
public void testDbDeleteNoCredential() throws IOException {
ODatabaseDocument db = new ODatabaseDocumentTx(url);
try {
db.drop();
Assert.fail("Should have thrown ODatabaseException because trying to delete a not opened");
} catch (ODatabaseException e) {
Assert.assertTrue(e.getMessage().contains("Database '" + url + "' is closed"));
} catch (OStorageException e) {
Assert.assertTrue(e.getMessage().startsWith("Cannot delete the remote storage:"));
}
}
Aggregations