|
22 | 22 | #include <Flash/Mpp/MPPTaskManager.h> |
23 | 23 | #include <Interpreters/Context.h> |
24 | 24 | #include <Interpreters/ProcessList.h> |
| 25 | +#include <Interpreters/SharedContexts/Disagg.h> |
25 | 26 | #include <Interpreters/executeQuery.h> |
| 27 | +#include <Storages/DeltaMerge/Remote/WNDisaggSnapshotManager.h> |
26 | 28 | #include <fmt/core.h> |
27 | 29 |
|
28 | 30 | #include <magic_enum.hpp> |
@@ -86,39 +88,58 @@ MPPGatherTaskSetPtr MPPQuery::addMPPGatherTaskSet(const MPPGatherId & gather_id) |
86 | 88 |
|
87 | 89 | void MPPTaskMonitor::waitAllMPPTasksFinish(const std::unique_ptr<Context> & context) |
88 | 90 | { |
89 | | - // The maximum seconds TiFlash will wait for all current MPP tasks to finish before shutting down |
| 91 | + // The maximum seconds TiFlash will wait for all current MPP tasks or disagg snapshots to finish before shutting down |
90 | 92 | static constexpr const char * GRACEFUL_WAIT_SHUTDOWN_TIMEOUT = "flash.graceful_wait_shutdown_timeout"; |
91 | 93 | // The default value of flash.graceful_wait_shutdown_timeout |
92 | 94 | static constexpr UInt64 DEFAULT_GRACEFUL_WAIT_SHUTDOWN_TIMEOUT = 600; |
93 | 95 | auto graceful_wait_shutdown_timeout |
94 | 96 | = context->getUsersConfig()->getUInt64(GRACEFUL_WAIT_SHUTDOWN_TIMEOUT, DEFAULT_GRACEFUL_WAIT_SHUTDOWN_TIMEOUT); |
95 | | - LOG_INFO(log, "Start to wait all MPP tasks to finish, timeout={}s", graceful_wait_shutdown_timeout); |
| 97 | + |
| 98 | + bool is_disagg_storage_mode = context->getSharedContextDisagg()->isDisaggregatedStorageMode(); |
| 99 | + const String & wait_target = is_disagg_storage_mode ? "disagg snapshots" : "MPP tasks"; |
| 100 | + LOG_INFO(log, "Start to wait all {} to finish, timeout={}s", wait_target, graceful_wait_shutdown_timeout); |
| 101 | + |
96 | 102 | UInt64 graceful_wait_shutdown_timeout_ms = graceful_wait_shutdown_timeout * 1000; |
97 | 103 | Stopwatch watch; |
98 | 104 | // The first sleep before checking to reduce the chance of missing MPP tasks that are still in the process of being dispatched |
99 | | - std::this_thread::sleep_for(std::chrono::seconds(1)); |
| 105 | + std::this_thread::sleep_for(std::chrono::seconds(2)); |
100 | 106 | bool all_tasks_finished = false; |
101 | 107 | while (true) |
102 | 108 | { |
103 | 109 | auto elapsed_ms = watch.elapsedMilliseconds(); |
104 | | - if (!all_tasks_finished) |
| 110 | + if (is_disagg_storage_mode) |
105 | 111 | { |
106 | | - std::unique_lock lock(mu); |
107 | | - if (monitored_tasks.empty()) |
108 | | - all_tasks_finished = true; |
| 112 | + // For write node under disagg arch, should wait for all disagg establish task rpc being finished |
| 113 | + // and all snapshot being released. |
| 114 | + // Otherwise compute nodes may meet error when calling `FetchDisaggPages` on write nodes. |
| 115 | + if (GET_METRIC(tiflash_coprocessor_handling_request_count, type_disagg_establish_task).Value() == 0 |
| 116 | + && context->getSharedContextDisagg()->wn_snapshot_manager->getActiveSnapshotCount() == 0) |
| 117 | + { |
| 118 | + LOG_INFO(log, "All disagg snapshots have finished after {}ms", elapsed_ms); |
| 119 | + break; |
| 120 | + } |
109 | 121 | } |
110 | | - if (all_tasks_finished) |
| 122 | + else |
111 | 123 | { |
112 | | - // Also needs to check if all MPP gRPC connections are finished |
113 | | - if (GET_METRIC(tiflash_coprocessor_handling_request_count, type_mpp_establish_conn).Value() == 0) |
| 124 | + if (!all_tasks_finished) |
114 | 125 | { |
115 | | - LOG_INFO(log, "All MPP tasks have finished after {}ms", elapsed_ms); |
116 | | - break; |
| 126 | + std::unique_lock lock(mu); |
| 127 | + if (monitored_tasks.empty()) |
| 128 | + all_tasks_finished = true; |
| 129 | + } |
| 130 | + if (all_tasks_finished) |
| 131 | + { |
| 132 | + // Also needs to check if all MPP gRPC connections are finished |
| 133 | + if (GET_METRIC(tiflash_coprocessor_handling_request_count, type_mpp_establish_conn).Value() == 0) |
| 134 | + { |
| 135 | + LOG_INFO(log, "All MPP tasks have finished after {}ms", elapsed_ms); |
| 136 | + break; |
| 137 | + } |
117 | 138 | } |
118 | 139 | } |
119 | 140 | if (elapsed_ms >= graceful_wait_shutdown_timeout_ms) |
120 | 141 | { |
121 | | - LOG_WARNING(log, "Timed out waiting for all MPP tasks to finish after {}ms", elapsed_ms); |
| 142 | + LOG_WARNING(log, "Timed out waiting for all {} to finish after {}ms", wait_target, elapsed_ms); |
122 | 143 | break; |
123 | 144 | } |
124 | 145 | std::this_thread::sleep_for(std::chrono::milliseconds(200)); |
|
0 commit comments