Skip to content

Commit cbddc48

Browse files
committed
add deadline for grpc shutdown
Signed-off-by: gengliqi <gengliqiii@gmail.com>
1 parent bf0e3a5 commit cbddc48

File tree

6 files changed

+20
-8
lines changed

6 files changed

+20
-8
lines changed

dbms/src/Flash/Mpp/MPPTaskManager.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,7 @@ MPPGatherTaskSetPtr MPPQuery::addMPPGatherTaskSet(const MPPGatherId & gather_id)
8686

8787
void MPPTaskMonitor::waitAllMPPTasksFinish(const std::unique_ptr<Context> & global_context)
8888
{
89-
// The maximum seconds TiFlash will wait for all current MPP tasks to finish before shutting down
90-
static constexpr const char * GRACEFUL_WIAT_BEFORE_SHUTDOWN = "flash.graceful_wait_before_shutdown";
91-
// The default value of flash.graceful_wait_before_shutdown
92-
static constexpr UInt64 DEFAULT_GRACEFUL_WAIT_BEFORE_SHUTDOWN = 600;
93-
auto graceful_wait_before_shutdown = global_context->getUsersConfig()->getUInt64(
94-
GRACEFUL_WIAT_BEFORE_SHUTDOWN,
95-
DEFAULT_GRACEFUL_WAIT_BEFORE_SHUTDOWN);
89+
auto graceful_wait_before_shutdown = global_context->getGracefulWaitBeforeShutdown();
9690
LOG_INFO(log, "Start to wait all MPPTasks to finish, timeout={}s", graceful_wait_before_shutdown);
9791
Stopwatch watch;
9892
// The first sleep before checking to reduce the chance of missing MPP tasks that are still in the process of being dispatched

dbms/src/Interpreters/Context.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,6 +2055,17 @@ const std::unordered_set<uint64_t> * Context::getStoreIdBlockList() const
20552055
return &shared->store_id_blocklist;
20562056
}
20572057

2058+
UInt64 Context::getGracefulWaitBeforeShutdown()
2059+
{
2060+
// The maximum seconds TiFlash will wait for all current MPP tasks to finish before shutting down
2061+
static constexpr const char * GRACEFUL_WIAT_BEFORE_SHUTDOWN = "flash.graceful_wait_before_shutdown";
2062+
// The default value of flash.graceful_wait_before_shutdown
2063+
static constexpr UInt64 DEFAULT_GRACEFUL_WAIT_BEFORE_SHUTDOWN = 600;
2064+
return global_context->getUsersConfig()->getUInt64(
2065+
GRACEFUL_WIAT_BEFORE_SHUTDOWN,
2066+
DEFAULT_GRACEFUL_WAIT_BEFORE_SHUTDOWN);
2067+
}
2068+
20582069
// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
20592070
bool Context::initializeStoreIdBlockList(const String & comma_sep_string)
20602071
{

dbms/src/Interpreters/Context.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,8 @@ class Context
536536
bool initializeStoreIdBlockList(const String &);
537537
const std::unordered_set<uint64_t> * getStoreIdBlockList() const;
538538

539+
UInt64 getGracefulWaitBeforeShutdown();
540+
539541
private:
540542
/** Check if the current client has access to the specified database.
541543
* If access is denied, throw an exception.

dbms/src/Server/FlashGrpcServerHolder.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ FlashGrpcServerHolder::~FlashGrpcServerHolder()
220220
{
221221
/// Shut down grpc server.
222222
LOG_INFO(log, "Begin to shut down flash grpc server");
223-
flash_grpc_server->Shutdown();
223+
auto deadline = std::chrono::system_clock::now() + std::chrono::seconds(grpc_shutdown_max_wait);
224+
flash_grpc_server->Shutdown(deadline);
224225
*is_shutdown = true;
225226

226227
for (auto & cq : cqs)

dbms/src/Server/FlashGrpcServerHolder.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ class FlashGrpcServerHolder
4444

4545
std::unique_ptr<FlashService> & flashService();
4646

47+
void setMaxWaitDuringGRPCShutdown(UInt64 max_wait) { grpc_shutdown_max_wait = max_wait; }
48+
4749
private:
4850
const LoggerPtr & log;
4951
std::shared_ptr<std::atomic<bool>> is_shutdown;
@@ -56,6 +58,7 @@ class FlashGrpcServerHolder
5658
std::vector<std::thread> cq_workers;
5759
std::vector<std::thread> notify_cq_workers;
5860
CollectProcInfoBackgroundTask background_task;
61+
UInt64 grpc_shutdown_max_wait = 600;
5962
};
6063

6164
} // namespace DB

dbms/src/Server/Server.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,7 @@ try
12571257
LOG_INFO(log, "Set unavailable for MPPTask");
12581258
tmt_context.getMPPTaskManager()->setUnavailable();
12591259
tmt_context.getMPPTaskManager()->getMPPTaskMonitor()->waitAllMPPTasksFinish(global_context);
1260+
flash_grpc_server_holder.setMaxWaitDuringGRPCShutdown(global_context->getGracefulWaitBeforeShutdown());
12601261

12611262
{
12621263
// Set limiters stopping and wakeup threads in waitting queue.

0 commit comments

Comments
 (0)