| 535 | } |
| 536 | |
| 537 | void TransactionLog::rollbackTransaction(const MergeTreeTransactionPtr & txn) noexcept |
| 538 | { |
| 539 | LockMemoryExceptionInThread memory_tracker_lock(VariableContext::Global); |
| 540 | LOG_TRACE(log, "Rolling back transaction {}{}", txn->tid, |
| 541 | std::uncaught_exceptions() ? fmt::format(" due to uncaught exception (code: {})", getCurrentExceptionCode()) : ""); |
| 542 | |
| 543 | if (!txn->rollback()) |
| 544 | { |
| 545 | /// Transaction was cancelled or committed concurrently |
| 546 | chassert(txn->csn != Tx::UnknownCSN); |
| 547 | return; |
| 548 | } |
| 549 | |
| 550 | { |
| 551 | auto requests = txn->getRequestsOnRollback(); |
| 552 | if (!requests.empty()) |
| 553 | { |
| 554 | Coordination::Responses responses; |
| 555 | auto code = getZooKeeper()->tryMulti(requests, responses); |
| 556 | if (code == Coordination::Error::ZOK) |
| 557 | { |
| 558 | LOG_INFO(log, "Processed requests on rollback {}", requests.size()); |
| 559 | } |
| 560 | else |
| 561 | { |
| 562 | zkutil::KeeperMultiException exception(code, requests, responses); |
| 563 | if (Coordination::isHardwareError(code)) |
| 564 | LOG_WARNING( |
| 565 | log, "Failed to process requests on rollback {} because of {}", requests.size(), Coordination::toString(code)); |
| 566 | else |
| 567 | LOG_WARNING( |
| 568 | log, |
| 569 | "Failed to process requests on rollback {} because of {} on path {}", |
| 570 | requests.size(), |
| 571 | Coordination::toString(code), |
| 572 | exception.getPathForFirstFailedOp()); |
| 573 | } |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | { |
| 578 | std::lock_guard lock{running_list_mutex}; |
| 579 | bool removed = running_list.erase(txn->tid.getHash()); |
| 580 | if (!removed) |
| 581 | abort(); |
| 582 | snapshots_in_use.erase(txn->snapshot_in_use_it); |
| 583 | } |
| 584 | |
| 585 | tryWriteEventToSystemLog(log, global_context, TransactionsInfoLogElement::ROLLBACK, txn->tid); |
| 586 | txn->afterFinalize(); |
| 587 | } |
| 588 | |
| 589 | MergeTreeTransactionPtr TransactionLog::tryGetRunningTransaction(const TIDHash & tid) |
| 590 | { |
no test coverage detected