review second phase logic to trigger data sync only on really needed cases
@@ -522,7 +522,6 @@ public class ODatabaseDocumentDistributed extends ODatabaseDocumentEmbedded {
/**
* @param transactionId
- *
* @return null returned means that commit failed
*/
public boolean commit2pc(ODistributedRequestId transactionId, boolean local, ODistributedRequestId requestId) {
@@ -569,13 +568,16 @@ public class ODatabaseDocumentDistributed extends ODatabaseDocumentEmbedded {
OException.wrapException(new OInterruptedException(e.getMessage()), e);
}
}
- if (localDistributedDatabase.validate(txContext.getTransactionId()).isPresent()) {
- return false;
+ boolean valid = true;
+ Optional<OTransactionId> validateResult = localDistributedDatabase.validate(txContext.getTransactionId());
+ if (validateResult.isPresent()) {
+ valid = validateResult.get().getNodeOwner().isPresent();
}
+ if (valid) {
internalBegin2pc(txContext, local);
txContext.setStatus(SUCCESS);
break;
-
+ }
} catch (ODistributedRecordLockedException | ODistributedKeyLockedException ex) {
// Just retry
} catch (Exception ex) {
@@ -584,17 +586,7 @@ public class ODatabaseDocumentDistributed extends ODatabaseDocumentEmbedded {
break;
}
}
- if (!SUCCESS.equals(txContext.getStatus())) {
- txContext.destroy();
- localDistributedDatabase.popTxContext(transactionId);
- Orient.instance().submit(() -> {
- OLogManager.instance()
- .warn(ODatabaseDocumentDistributed.this, "Reached limit of retry for commit tx:%s forcing database re-install",
- transactionId);
- distributedManager.installDatabase(false, ODatabaseDocumentDistributed.this.getName(), true, true);
- });
- return true;
- }
+ if (SUCCESS.equals(txContext.getStatus())) {
try {
txContext.commit(this);
localDistributedDatabase.popTxContext(transactionId);
@@ -610,7 +602,17 @@ public class ODatabaseDocumentDistributed extends ODatabaseDocumentEmbedded {
OLiveQueryHook.removePendingDatabaseOps(this);
OLiveQueryHookV2.removePendingDatabaseOps(this);
}
-
+ } else {
+ txContext.destroy();
+ localDistributedDatabase.popTxContext(transactionId);
+ Orient.instance().submit(() -> {
+ OLogManager.instance()
+ .warn(ODatabaseDocumentDistributed.this, "Reached limit of retry for commit tx:%s forcing database re-install",
+ transactionId);
+ distributedManager.installDatabase(false, ODatabaseDocumentDistributed.this.getName(), true, true);
+ });
+ return true;
+ }
}
}
return false;
