| 1780 | } |
| 1781 | |
| 1782 | void InterpreterSystemQuery::lockMemoryLock(const ASTSystemQuery & query, const StorageID & table_id, ContextPtr local_context) |
| 1783 | { |
| 1784 | /// SYSTEM LOCK MEMORY LOCK db.tb PARTITON '2012-01-01' FOR 4 SECONDS TASK_DOMAIN |
| 1785 | |
| 1786 | auto & txn_coordinator = local_context->getCnchTransactionCoordinator(); |
| 1787 | auto transaction = txn_coordinator.createTransaction( |
| 1788 | CreateTransactionOption().setInitiator(CnchTransactionInitiator::Merge).setPriority(CnchTransactionPriority::low)); |
| 1789 | |
| 1790 | SCOPE_EXIT({ |
| 1791 | try |
| 1792 | { |
| 1793 | txn_coordinator.finishTransaction(transaction); |
| 1794 | } |
| 1795 | catch (...) |
| 1796 | { |
| 1797 | tryLogCurrentException(log, __PRETTY_FUNCTION__); |
| 1798 | } |
| 1799 | }); |
| 1800 | |
| 1801 | StoragePtr storage = local_context->getCnchCatalog()->tryGetTable(*local_context, table_id.database_name, table_id.table_name); |
| 1802 | if (!storage) |
| 1803 | throw Exception("Failed to get StoragePtr for table", ErrorCodes::BAD_ARGUMENTS); |
| 1804 | |
| 1805 | auto * merge_tree = dynamic_cast<StorageCnchMergeTree *>(storage.get()); |
| 1806 | if (!merge_tree) |
| 1807 | throw Exception("storage is not merge tree table", ErrorCodes::LOGICAL_ERROR); |
| 1808 | |
| 1809 | String partition_id = merge_tree->getPartitionIDFromQuery(query.partition, local_context); |
| 1810 | LOG_DEBUG(log, "execute lock Memory lock on partition_id {} on table {} for {} s with string data {}", partition_id, table_id.getFullTableName(), query.seconds, query.string_data); |
| 1811 | |
| 1812 | TxnTimestamp txn_id = transaction->getTransactionID(); |
| 1813 | LockInfoPtr partition_lock = std::make_shared<LockInfo>(txn_id); |
| 1814 | partition_lock->setMode(LockMode::X); |
| 1815 | partition_lock->setTimeout(1000); //1 seconds |
| 1816 | partition_lock->setPartition(partition_id); |
| 1817 | partition_lock->setUUIDAndPrefix(storage->getStorageUUID(), query.string_data.empty() ? LockInfo::default_domain : LockInfo::task_domain); |
| 1818 | |
| 1819 | Stopwatch lock_watch; |
| 1820 | |
| 1821 | auto cnch_lock = std::make_shared<CnchLockHolder>(local_context, std::move(partition_lock)); |
| 1822 | cnch_lock->lock(); |
| 1823 | LOG_DEBUG(log, "Acquired lock in {} ms", lock_watch.elapsedMilliseconds()); |
| 1824 | sleepForSeconds(query.seconds); |
| 1825 | } |
| 1826 | |
| 1827 | void InterpreterSystemQuery::releaseMemoryLock(const ASTSystemQuery & query, const StorageID & table_id, ContextPtr local_context) |
| 1828 | { |
nothing calls this directly
no test coverage detected