| 103 | |
| 104 | |
| 105 | TxnTimestamp CnchServerTransaction::commitV1() |
| 106 | { |
| 107 | LOG_DEBUG(log, "Transaction {} starts commit (v1 api)\n", txn_record.txnID().toUInt64()); |
| 108 | |
| 109 | if (isReadOnly()) |
| 110 | throw Exception("Invalid commit operation for read only transaction", ErrorCodes::LOGICAL_ERROR); |
| 111 | |
| 112 | Stopwatch watch(CLOCK_MONOTONIC_COARSE); |
| 113 | SCOPE_EXIT({ |
| 114 | ProfileEvents::increment((getStatus() == CnchTransactionStatus::Finished ? ProfileEvents::CnchTxnCommitted : ProfileEvents::CnchTxnCommitV1Failed)); |
| 115 | ProfileEvents::increment(ProfileEvents::CnchTxnCommitV1ElapsedMilliseconds, watch.elapsedMilliseconds()); |
| 116 | }); |
| 117 | |
| 118 | auto commit_ts = global_context->getTimestamp(); |
| 119 | |
| 120 | try |
| 121 | { |
| 122 | auto lock = getLock(); |
| 123 | for (const auto & action : actions) |
| 124 | { |
| 125 | action->executeV1(commit_ts); |
| 126 | } |
| 127 | |
| 128 | setStatus(CnchTransactionStatus::Finished); |
| 129 | setCommitTime(commit_ts); |
| 130 | LOG_DEBUG(log, "Successfully committed transaction (v1 api): {}\n", txn_record.txnID().toUInt64()); |
| 131 | commitModifiedCount(this->modified_counter); |
| 132 | return commit_ts; |
| 133 | } |
| 134 | catch (...) |
| 135 | { |
| 136 | rollbackV1(commit_ts); |
| 137 | throw; |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | void CnchServerTransaction::rollbackV1(const TxnTimestamp & ts) |
| 142 | { |
no test coverage detected