| 2005 | } |
| 2006 | |
| 2007 | bool InterpreterSystemQuery::trySyncReplica(StoragePtr table, SyncReplicaMode sync_replica_mode, const std::unordered_set<String> & src_replicas, ContextPtr context_) |
| 2008 | { |
| 2009 | auto table_id_ = table->getStorageID(); |
| 2010 | |
| 2011 | /// If materialized view, sync its target table. |
| 2012 | for (int i = 0;; ++i) |
| 2013 | { |
| 2014 | if (i >= 100) |
| 2015 | throw Exception(ErrorCodes::TOO_DEEP_RECURSION, "Materialized view targets form a cycle or a very long chain"); |
| 2016 | |
| 2017 | if (auto * storage_mv = dynamic_cast<StorageMaterializedView *>(table.get())) |
| 2018 | table = storage_mv->getTargetTable(); |
| 2019 | else |
| 2020 | break; |
| 2021 | } |
| 2022 | |
| 2023 | if (auto * storage_replicated = dynamic_cast<StorageReplicatedMergeTree *>(table.get())) |
| 2024 | { |
| 2025 | auto log = getLogger("InterpreterSystemQuery"); |
| 2026 | LOG_TRACE(log, "Synchronizing entries in replica's queue with table's log and waiting for current last entry to be processed"); |
| 2027 | auto sync_timeout = context_->getSettingsRef()[Setting::receive_timeout].totalMilliseconds(); |
| 2028 | if (!storage_replicated->waitForProcessingQueue(sync_timeout, sync_replica_mode, src_replicas)) |
| 2029 | { |
| 2030 | LOG_ERROR(log, "SYNC REPLICA {}: Timed out.", table_id_.getNameForLogs()); |
| 2031 | throw Exception( |
| 2032 | ErrorCodes::TIMEOUT_EXCEEDED, |
| 2033 | "SYNC REPLICA {}: command timed out. " |
| 2034 | "See the 'receive_timeout' setting", |
| 2035 | table_id_.getNameForLogs()); |
| 2036 | } |
| 2037 | LOG_TRACE(log, "SYNC REPLICA {}: OK", table_id_.getNameForLogs()); |
| 2038 | } |
| 2039 | else |
| 2040 | return false; |
| 2041 | |
| 2042 | return true; |
| 2043 | } |
| 2044 | |
| 2045 | void InterpreterSystemQuery::syncReplica(ASTSystemQuery & query) |
| 2046 | { |
nothing calls this directly
no test coverage detected