Search in sources :

Example 31 with ONeedRetryException

use of com.orientechnologies.common.concur.ONeedRetryException in project orientdb by orientechnologies.

the class IndexConcurrencyTest method addSubTree.

public static void addSubTree(String parentName, char startLetter) {
    ODatabaseDocumentTx db = new ODatabaseDocumentTx(url).open("admin", "admin");
    for (int i = 0; ; ++i) {
        try {
            ODocument parent;
            final List<ODocument> result = db.command(new OCommandSQL("select from Person where name = '" + parentName + "'")).execute();
            parent = result.get(0);
            if (parent == null) {
                db.close();
                return;
            }
            String newName = parentName;
            newName += Character.toString(startLetter);
            StringBuilder newIdentifier = new StringBuilder(newName);
            newIdentifier.setCharAt(0, 'B');
            db.begin();
            PersonTree tree = new PersonTree();
            tree.SetRoot(parent);
            ODocument child = tree.AddChild(parent, newName, newIdentifier.toString());
            buildTree(tree, child.getIdentity(), newName, subnodes, depth - 1, startLetter);
            db.commit();
            break;
        } catch (ONeedRetryException e) {
            System.out.println("Concurrency change, retry " + i);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    // printPersons("After addSubTree", db);
    db.close();
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ONeedRetryException(com.orientechnologies.common.concur.ONeedRetryException) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ONeedRetryException(com.orientechnologies.common.concur.ONeedRetryException) IOException(java.io.IOException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 32 with ONeedRetryException

use of com.orientechnologies.common.concur.ONeedRetryException in project orientdb by orientechnologies.

the class OFunction method execute.

public Object execute(final Map<Object, Object> iArgs) {
    final long start = Orient.instance().getProfiler().startChrono();
    Object result;
    while (true) {
        try {
            if (callback != null)
                return callback.call(iArgs);
            final OCommandExecutorScript command = new OCommandExecutorScript();
            command.parse(new OCommandScript(getLanguage(), getCode()));
            result = command.execute(iArgs);
            break;
        } catch (ONeedRetryException e) {
            continue;
        } catch (ORetryQueryException e) {
            continue;
        }
    }
    if (Orient.instance().getProfiler().isRecording())
        Orient.instance().getProfiler().stopChrono("db." + ODatabaseRecordThreadLocal.INSTANCE.get().getName() + ".function.execute", "Time to execute a function", start, "db.*.function.execute");
    return result;
}
Also used : ONeedRetryException(com.orientechnologies.common.concur.ONeedRetryException) OCommandScript(com.orientechnologies.orient.core.command.script.OCommandScript) ORetryQueryException(com.orientechnologies.orient.core.exception.ORetryQueryException) OCommandExecutorScript(com.orientechnologies.orient.core.command.script.OCommandExecutorScript)

Example 33 with ONeedRetryException

use of com.orientechnologies.common.concur.ONeedRetryException in project orientdb by orientechnologies.

the class OTransactionNoTx method saveRecord.

/**
 * Update the record.
 *
 * @param iRecord
 * @param iForceCreate
 * @param iRecordCreatedCallback
 * @param iRecordUpdatedCallback
 */
public ORecord saveRecord(final ORecord iRecord, final String iClusterName, final OPERATION_MODE iMode, boolean iForceCreate, final ORecordCallback<? extends Number> iRecordCreatedCallback, ORecordCallback<Integer> iRecordUpdatedCallback) {
    try {
        ORecord toRet = null;
        ODirtyManager dirtyManager = ORecordInternal.getDirtyManager(iRecord);
        Set<ORecord> newRecord = dirtyManager.getNewRecords();
        Set<ORecord> updatedRecord = dirtyManager.getUpdateRecords();
        dirtyManager.clearForSave();
        if (newRecord != null) {
            for (ORecord rec : newRecord) {
                if (rec.getIdentity().isNew() && rec instanceof ODocument) {
                    ORecord ret = saveNew((ODocument) rec, dirtyManager, iClusterName, iRecord, iMode, iForceCreate, iRecordCreatedCallback, iRecordUpdatedCallback);
                    if (ret != null)
                        toRet = ret;
                }
            }
        }
        if (updatedRecord != null) {
            for (ORecord rec : updatedRecord) {
                if (rec == iRecord) {
                    toRet = database.executeSaveRecord(rec, iClusterName, rec.getVersion(), iMode, iForceCreate, iRecordCreatedCallback, iRecordUpdatedCallback);
                } else
                    database.executeSaveRecord(rec, getClusterName(rec), rec.getVersion(), OPERATION_MODE.SYNCHRONOUS, false, null, null);
            }
        }
        if (toRet != null)
            return toRet;
        else
            return database.executeSaveRecord(iRecord, iClusterName, iRecord.getVersion(), iMode, iForceCreate, iRecordCreatedCallback, iRecordUpdatedCallback);
    } catch (Exception e) {
        // REMOVE IT FROM THE CACHE TO AVOID DIRTY RECORDS
        final ORecordId rid = (ORecordId) iRecord.getIdentity();
        if (rid.isValid())
            database.getLocalCache().freeRecord(rid);
        if (e instanceof ONeedRetryException)
            throw (ONeedRetryException) e;
        throw OException.wrapException(new ODatabaseException("Error during saving of record" + (iRecord != null ? " with rid " + iRecord.getIdentity() : "")), e);
    }
}
Also used : ONeedRetryException(com.orientechnologies.common.concur.ONeedRetryException) ORecord(com.orientechnologies.orient.core.record.ORecord) ODirtyManager(com.orientechnologies.orient.core.record.impl.ODirtyManager) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) ONeedRetryException(com.orientechnologies.common.concur.ONeedRetryException) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) OException(com.orientechnologies.common.exception.OException) ORecordNotFoundException(com.orientechnologies.orient.core.exception.ORecordNotFoundException) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)33 OException (com.orientechnologies.common.exception.OException)13 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)8 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)8 HazelcastException (com.hazelcast.core.HazelcastException)7 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)7 OOfflineNodeException (com.orientechnologies.common.concur.OOfflineNodeException)7 OIOException (com.orientechnologies.common.io.OIOException)7 ORecordId (com.orientechnologies.orient.core.id.ORecordId)7 ODistributedRedirectException (com.orientechnologies.orient.enterprise.channel.binary.ODistributedRedirectException)7 OCallable (com.orientechnologies.common.util.OCallable)6 OPlaceholder (com.orientechnologies.orient.core.db.record.OPlaceholder)5 ORecordNotFoundException (com.orientechnologies.orient.core.exception.ORecordNotFoundException)5 ORecord (com.orientechnologies.orient.core.record.ORecord)5 IOException (java.io.IOException)5 Callable (java.util.concurrent.Callable)5 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)4 ORecordDuplicatedException (com.orientechnologies.orient.core.storage.ORecordDuplicatedException)4 Vertex (com.tinkerpop.blueprints.Vertex)4 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)4