| 187 | } |
| 188 | |
| 189 | void CnchServerTransaction::precommit() |
| 190 | { |
| 191 | LOG_DEBUG(log, "Transaction {} starts pre commit\n", txn_record.txnID().toUInt64()); |
| 192 | Stopwatch watch(CLOCK_MONOTONIC_COARSE); |
| 193 | SCOPE_EXIT({ ProfileEvents::increment(ProfileEvents::CnchTxnPrecommitElapsedMilliseconds, watch.elapsedMilliseconds()); }); |
| 194 | |
| 195 | { |
| 196 | auto lock = getLock(); |
| 197 | if (auto status = getStatus(); status != CnchTransactionStatus::Running) |
| 198 | throw Exception("Transaction is not in running status, but in " + String(txnStatusToString(status)), ErrorCodes::LOGICAL_ERROR); |
| 199 | |
| 200 | for (auto & action : actions) |
| 201 | action->executeV2(); |
| 202 | |
| 203 | txn_record.prepared = true; |
| 204 | action_size_before_dedup = actions.size(); |
| 205 | } |
| 206 | |
| 207 | auto retry_time = getContext()->getSettingsRef().max_dedup_retry_time.value; |
| 208 | do |
| 209 | { |
| 210 | try |
| 211 | { |
| 212 | executeDedupStage(); |
| 213 | assertLockAcquired(); |
| 214 | } |
| 215 | catch (...) |
| 216 | { |
| 217 | if (retry_time == 0) |
| 218 | throw; |
| 219 | else if (action_size_before_dedup < actions.size()) |
| 220 | { |
| 221 | /// TODO: Impl retry in this case, especially handle undo buffer |
| 222 | LOG_WARNING( |
| 223 | log, |
| 224 | "Dedup stage failed, but result is not empty({}/{}), unable to retry, retry time: {}", |
| 225 | actions.size(), |
| 226 | action_size_before_dedup, |
| 227 | retry_time); |
| 228 | throw; |
| 229 | } |
| 230 | else |
| 231 | { |
| 232 | LOG_WARNING(log, "Dedup stage failed, retry time: {}, reason: {}", retry_time, getCurrentExceptionMessage(false)); |
| 233 | retry_time--; |
| 234 | dedup_stage_flag = false; |
| 235 | continue; |
| 236 | } |
| 237 | } |
| 238 | break; |
| 239 | } while (true); |
| 240 | } |
| 241 | |
| 242 | void CnchServerTransaction::executeDedupStage() |
| 243 | { |
nothing calls this directly
no test coverage detected