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);
}
}
Aggregations