| 128 | } |
| 129 | |
| 130 | void CnchRefreshMaterializedViewThread::runImpl() |
| 131 | { |
| 132 | UInt64 next_delay_seconds = 10; |
| 133 | |
| 134 | try |
| 135 | { |
| 136 | runHeartbeatTask(); |
| 137 | |
| 138 | auto istorage = getStorageFromCatalog(); |
| 139 | auto & storage = checkAndGetMaterializedViewTable(istorage); |
| 140 | auto target_istorage = storage.getTargetTable(); |
| 141 | auto & target = checkAndGetCnchTable(target_istorage); |
| 142 | auto storage_settings = target.getSettings(); |
| 143 | |
| 144 | if (istorage->is_dropped) |
| 145 | { |
| 146 | LOG_DEBUG(log, "Table was dropped, wait for removing..."); |
| 147 | scheduled_task->scheduleAfter(10 * 1000); |
| 148 | return; |
| 149 | } |
| 150 | |
| 151 | { |
| 152 | std::lock_guard lock(worker_pool_mutex); |
| 153 | vw_name = storage_settings->cnch_vw_write; |
| 154 | vm_handle = getContext()->getVirtualWarehousePool().get(vw_name); |
| 155 | } |
| 156 | |
| 157 | bool success = false; |
| 158 | |
| 159 | try |
| 160 | { |
| 161 | int max_bg_task_num = storage_settings->max_refresh_materialized_view_task_num; |
| 162 | if (running_tasks < max_bg_task_num) |
| 163 | { |
| 164 | success = startRefreshTask(istorage, storage); |
| 165 | } |
| 166 | else |
| 167 | { |
| 168 | LOG_DEBUG(log, "Too many cnch materialized view refresh tasks (current: {}, max: {})", running_tasks, max_bg_task_num); |
| 169 | } |
| 170 | } |
| 171 | catch (...) |
| 172 | { |
| 173 | tryLogCurrentException(__PRETTY_FUNCTION__); |
| 174 | } |
| 175 | |
| 176 | next_delay_seconds = checkAndGetRefreshInterval(storage); |
| 177 | scheduled_task->scheduleAfter(next_delay_seconds * 1000); |
| 178 | } |
| 179 | catch (...) |
| 180 | { |
| 181 | tryLogCurrentException(__PRETTY_FUNCTION__); |
| 182 | |
| 183 | scheduled_task->scheduleAfter(next_delay_seconds * 1000); |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | bool CnchRefreshMaterializedViewThread::constructAndScheduleRefreshTasks(StoragePtr & istorage, StorageMaterializedView & storage) |
nothing calls this directly
no test coverage detected