Search in sources :

Example 16 with ORemoteTask

use of com.orientechnologies.orient.server.distributed.task.ORemoteTask in project orientdb by orientechnologies.

the class ODistributedTxContextImpl method executeFix.

public static void executeFix(final Object me, final ODistributedTxContext context, final ODatabaseDocumentInternal database, final List<ORemoteTask> fixTasks, ODistributedRequestId requestId, final ODistributedDatabase ddb) {
    ODistributedServerLog.debug(me, ddb.getManager().getLocalNodeName(), null, ODistributedServerLog.DIRECTION.NONE, "Distributed transaction %s: fixing transaction (db=%s tasks=%d)", requestId, ddb.getDatabaseName(), fixTasks.size());
    // LOCK ALL THE RECORDS FIRST BY CANCELING ANY PENDING LOCKS
    final Set<ORID> locked = new HashSet<ORID>();
    for (ORemoteTask fixTask : fixTasks) {
        if (fixTask instanceof OAbstractRecordReplicatedTask) {
            final ORecordId rid = ((OAbstractRecordReplicatedTask) fixTask).getRid();
            if (ddb.forceLockRecord(rid, requestId))
                locked.add(rid);
        }
    }
    try {
        for (ORemoteTask fixTask : fixTasks) {
            try {
                if (fixTask instanceof OAbstractRecordReplicatedTask)
                    // AVOID LOCKING BECAUSE LOCKS WAS ALREADY ACQUIRED IN CONTEXT
                    ((OAbstractRecordReplicatedTask) fixTask).setLockRecords(false);
                fixTask.execute(requestId, ddb.getManager().getServerInstance(), ddb.getManager(), database);
            } catch (Exception e) {
                ODistributedServerLog.debug(me, ddb.getManager().getLocalNodeName(), null, ODistributedServerLog.DIRECTION.NONE, "Error on fixing transaction %s db=%s task=%s", e, requestId, ddb.getDatabaseName(), fixTask);
            }
        }
    } finally {
        // UNLOCK ALL THE RECORDS (THE TX IS FINISHED)
        for (ORID r : locked) ddb.unlockRecord(r, requestId);
    }
}
Also used : OAbstractRecordReplicatedTask(com.orientechnologies.orient.server.distributed.task.OAbstractRecordReplicatedTask) ORID(com.orientechnologies.orient.core.id.ORID) ORemoteTask(com.orientechnologies.orient.server.distributed.task.ORemoteTask) ORecordId(com.orientechnologies.orient.core.id.ORecordId)

Aggregations

ORemoteTask (com.orientechnologies.orient.server.distributed.task.ORemoteTask)16 ODistributedOperationException (com.orientechnologies.orient.server.distributed.task.ODistributedOperationException)6 OAbstractReplicatedTask (com.orientechnologies.orient.server.distributed.task.OAbstractReplicatedTask)4 ODistributedRecordLockedException (com.orientechnologies.orient.server.distributed.task.ODistributedRecordLockedException)4 OException (com.orientechnologies.common.exception.OException)3 IOException (java.io.IOException)3 OOfflineNodeException (com.orientechnologies.common.concur.OOfflineNodeException)2 OConfigurationException (com.orientechnologies.orient.core.exception.OConfigurationException)2 OSecurityAccessException (com.orientechnologies.orient.core.exception.OSecurityAccessException)2 ORecordId (com.orientechnologies.orient.core.id.ORecordId)2 OWaitForTask (com.orientechnologies.orient.server.distributed.impl.task.OWaitForTask)2 OAbstractRecordReplicatedTask (com.orientechnologies.orient.server.distributed.task.OAbstractRecordReplicatedTask)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)1 OModificationOperationProhibitedException (com.orientechnologies.common.concur.lock.OModificationOperationProhibitedException)1 OPlaceholder (com.orientechnologies.orient.core.db.record.OPlaceholder)1 ORID (com.orientechnologies.orient.core.id.ORID)1 OSecurityUser (com.orientechnologies.orient.core.metadata.security.OSecurityUser)1 ORecord (com.orientechnologies.orient.core.record.ORecord)1 ORawBuffer (com.orientechnologies.orient.core.storage.ORawBuffer)1