コード例 #1
0
  @Override
  public void prepare(final TransactionId txid) throws IOException {
    Tx tx = null;
    synchronized (this.inflightTransactions) {
      tx = this.inflightTransactions.remove(txid);
    }
    if (tx == null) {
      return;
    }
    final TransactionOperation to =
        TransactionOperation.newBuilder()
            .setType(TransactionType.XA_PREPARE)
            .setTransactionId(txid.getTransactionKey())
            .setWasPrepared(false)
            .build();
    // prepare,必须force
    final TxCommand msg =
        TxCommand.newBuilder()
            .setCmdType(TxCommandType.TX_OP)
            .setCmdContent(to.toByteString())
            .setForce(true)
            .build();
    this.journalStore.write(msg, null, tx.location, false);

    synchronized (this.preparedTransactions) {
      this.preparedTransactions.put(txid, tx);
    }
  }
コード例 #2
0
 @Override
 public void rollback(final TransactionId txid) throws IOException {
   Tx tx = null;
   synchronized (this.inflightTransactions) {
     tx = this.inflightTransactions.remove(txid);
   }
   if (tx == null) {
     synchronized (this.preparedTransactions) {
       tx = this.preparedTransactions.remove(txid);
     }
   }
   if (tx != null) {
     if (txid.isXATransaction()) {
       final TransactionOperation to =
           TransactionOperation.newBuilder() //
               .setType(TransactionType.XA_ROLLBACK) //
               .setTransactionId(txid.getTransactionKey()) //
               .setWasPrepared(false) //
               .build();
       final TxCommand msg =
           TxCommand.newBuilder()
               .setCmdType(TxCommandType.TX_OP)
               .setCmdContent(to.toByteString())
               .build();
       this.journalStore.write(msg, null, tx.location, true);
     } else {
       final TransactionOperation to =
           TransactionOperation.newBuilder() //
               .setType(TransactionType.LOCAL_ROLLBACK) //
               .setTransactionId(txid.getTransactionKey()) //
               .setWasPrepared(false) //
               .build();
       final TxCommand msg =
           TxCommand.newBuilder()
               .setCmdType(TxCommandType.TX_OP)
               .setCmdContent(to.toByteString())
               .build();
       this.journalStore.write(msg, null, tx.location, true);
     }
   }
 }