Skip to content

Commit

Permalink
catch exception of LocalAdmissionController::stop() (#8942)
Browse files Browse the repository at this point in the history
close #8860
  • Loading branch information
guo-shaoge authored Apr 12, 2024
1 parent 08c3ea1 commit 0b0cc45
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
26 changes: 14 additions & 12 deletions dbms/src/Flash/ResourceControl/LocalAdmissionController.h
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,9 @@ class LocalAdmissionController final : private boost::noncopyable
background_threads.emplace_back([this] { this->watchGAC(); });
}

~LocalAdmissionController()
~LocalAdmissionController() { safeStop(); }

void safeStop()
{
try
{
Expand Down Expand Up @@ -530,6 +532,17 @@ class LocalAdmissionController final : private boost::noncopyable
refill_token_callback = nullptr;
}

#ifdef DBMS_PUBLIC_GTEST
static std::unique_ptr<MockLocalAdmissionController> global_instance;
#else
static std::unique_ptr<LocalAdmissionController> global_instance;
#endif

// Interval of fetch from GAC periodically.
static constexpr auto DEFAULT_FETCH_GAC_INTERVAL = std::chrono::seconds(5);
static constexpr auto DEFAULT_FETCH_GAC_INTERVAL_MS = 5000;

private:
void stop()
{
if (stopped)
Expand Down Expand Up @@ -590,17 +603,6 @@ class LocalAdmissionController final : private boost::noncopyable
LOG_INFO(log, "LAC stopped done: final report size: {}", acquire_infos.size());
}

#ifdef DBMS_PUBLIC_GTEST
static std::unique_ptr<MockLocalAdmissionController> global_instance;
#else
static std::unique_ptr<LocalAdmissionController> global_instance;
#endif

// Interval of fetch from GAC periodically.
static constexpr auto DEFAULT_FETCH_GAC_INTERVAL = std::chrono::seconds(5);
static constexpr auto DEFAULT_FETCH_GAC_INTERVAL_MS = 5000;

private:
void consumeResource(const std::string & name, double ru, uint64_t cpu_time_in_ns)
{
if (unlikely(stopped))
Expand Down
6 changes: 3 additions & 3 deletions dbms/src/Server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1786,7 +1786,7 @@ int Server::main(const std::vector<std::string> & /*args*/)
// Workload will not be throttled when LAC is stopped.
// It's ok because flash service has already been destructed, so throllting is meaningless.
assert(LocalAdmissionController::global_instance);
LocalAdmissionController::global_instance->stop();
LocalAdmissionController::global_instance->safeStop();
}
});

Expand All @@ -1805,11 +1805,11 @@ int Server::main(const std::vector<std::string> & /*args*/)
// Stop LAC for AutoScaler managed CN before FlashGrpcServerHolder is destructed.
// Because AutoScaler it will kill tiflash process when port of flash_server_addr is down.
// And we want to make sure LAC is cleanedup.
// The effects are there will be no resource control during [lac.stop(), FlashGrpcServer destruct done],
// The effects are there will be no resource control during [lac.safeStop(), FlashGrpcServer destruct done],
// but it's basically ok, that duration is small(normally 100-200ms).
if (global_context->getSharedContextDisagg()->isDisaggregatedComputeMode() && use_autoscaler
&& LocalAdmissionController::global_instance)
LocalAdmissionController::global_instance->stop();
LocalAdmissionController::global_instance->safeStop();
});

tmt_context.setStatusRunning();
Expand Down

0 comments on commit 0b0cc45

Please sign in to comment.