コード例 #1
0
    private void replayModificationsInTransaction(PrepareCommand command, boolean onePhaseCommit)
        throws Throwable {
      TransactionManager tm = txManager();
      boolean replaySuccessful = false;
      try {

        tm.begin();
        replayModifications(command);
        replaySuccessful = true;
      } finally {
        LocalTransaction localTx = txTable().getLocalTransaction(tm.getTransaction());
        if (localTx
            != null) { // possible for the tx to be null if we got an exception during applying
                       // modifications
          localTx.setFromRemoteSite(true);

          if (onePhaseCommit) {
            if (replaySuccessful) {
              log.tracef(
                  "Committing remotely originated tx %s as it is 1PC",
                  command.getGlobalTransaction());
              tm.commit();
            } else {
              log.tracef("Rolling back remotely originated tx %s", command.getGlobalTransaction());
              tm.rollback();
            }
          } else { // Wait for a remote commit/rollback.
            remote2localTx.put(command.getGlobalTransaction(), localTx.getGlobalTransaction());
            tm.suspend();
          }
        }
      }
    }
コード例 #2
0
 private void completeTransaction(GlobalTransaction globalTransaction, boolean commit)
     throws Throwable {
   TransactionTable txTable = txTable();
   GlobalTransaction localTxId = remote2localTx.remove(globalTransaction);
   if (localTxId == null) {
     throw new CacheException(
         "Couldn't find a local transaction corresponding to remote transaction "
             + globalTransaction);
   }
   LocalTransaction localTx = txTable.getLocalTransaction(localTxId);
   if (localTx == null) {
     throw new IllegalStateException("Local tx not found but present in the tx table!");
   }
   TransactionManager txManager = txManager();
   txManager.resume(localTx.getTransaction());
   if (commit) {
     txManager.commit();
   } else {
     txManager.rollback();
   }
 }
コード例 #3
0
 protected boolean isTxFromRemoteSite(GlobalTransaction gtx) {
   LocalTransaction remoteTx = txTable.getLocalTransaction(gtx);
   return remoteTx != null && remoteTx.isFromRemoteSite();
 }