Search in sources :

Example 6 with OAbstractRecordReplicatedTask

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

the class ORepairClusterTask method execute.

@Override
public Object execute(final ODistributedRequestId requestId, final OServer iServer, final ODistributedServerManager iManager, final ODatabaseDocumentInternal database) throws Exception {
    final String clusterName = database.getClusterNameById(clusterId);
    ODistributedServerLog.debug(this, iManager.getLocalNodeName(), getNodeSource(), ODistributedServerLog.DIRECTION.IN, "Repair cluster: repairing cluster '%s' db=%s (reqId=%s)...", clusterName, database.getName(), requestId);
    ODatabaseRecordThreadLocal.INSTANCE.set(database);
    final ODistributedDatabase ddb = iManager.getMessageService().getDatabase(database.getName());
    // CREATE A CONTEXT OF TX
    final ODistributedTxContext reqContext = ddb.registerTxContext(requestId);
    try {
        final ODistributedConfiguration dCfg = iManager.getDatabaseConfiguration(database.getName());
        // LOCK INSERTION ON THIS CLUSTER
        reqContext.lock(new ORecordId(clusterId, -1));
        for (OAbstractRecordReplicatedTask task : tasks) {
            final Object taskResult;
            // CHECK LOCAL CLUSTER IS AVAILABLE ON CURRENT SERVER
            if (!task.checkForClusterAvailability(iManager.getLocalNodeName(), dCfg))
                // SKIP EXECUTION BECAUSE THE CLUSTER IS NOT ON LOCAL NODE: THIS CAN HAPPENS IN CASE OF DISTRIBUTED TX WITH SHARDING
                taskResult = NON_LOCAL_CLUSTER;
            else {
                task.setLockRecords(false);
                task.checkRecordExists();
                task.execute(requestId, iServer, iManager, database);
                reqContext.addUndoTask(task.getUndoTask(requestId));
            }
        }
        return null;
    } catch (Throwable e) {
        // if (e instanceof ODistributedRecordLockedException)
        // ddb.dumpLocks();
        ODistributedServerLog.debug(this, iManager.getLocalNodeName(), getNodeSource(), ODistributedServerLog.DIRECTION.IN, "Repair cluster: rolling back transaction db=%s (reqId=%s error=%s)...", database.getName(), requestId, e);
        // ddb.popTxContext(requestId);
        reqContext.unlock();
        return e;
    } finally {
        ODistributedServerLog.debug(this, iManager.getLocalNodeName(), getNodeSource(), ODistributedServerLog.DIRECTION.IN, "Repair cluster: transaction completed db=%s (reqId=%s)...", database.getName(), requestId);
    }
}
Also used : OAbstractRecordReplicatedTask(com.orientechnologies.orient.server.distributed.task.OAbstractRecordReplicatedTask) ORecordId(com.orientechnologies.orient.core.id.ORecordId)

Aggregations

OAbstractRecordReplicatedTask (com.orientechnologies.orient.server.distributed.task.OAbstractRecordReplicatedTask)6 ORecordId (com.orientechnologies.orient.core.id.ORecordId)2 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)1 OPlaceholder (com.orientechnologies.orient.core.db.record.OPlaceholder)1 ORecordNotFoundException (com.orientechnologies.orient.core.exception.ORecordNotFoundException)1 OTransactionException (com.orientechnologies.orient.core.exception.OTransactionException)1 ORecordDuplicatedException (com.orientechnologies.orient.core.storage.ORecordDuplicatedException)1 OTransactionOptimistic (com.orientechnologies.orient.core.tx.OTransactionOptimistic)1 ORemoteTask (com.orientechnologies.orient.server.distributed.task.ORemoteTask)1 ArrayList (java.util.ArrayList)1