MCPcopy Create free account
hub / github.com/apache/kvrocks / decreaseWorkerThreads

Method decreaseWorkerThreads

src/server/server.cc:2079–2100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2077}
2078
2079void Server::decreaseWorkerThreads(size_t delta) {
2080 auto current_worker_threads = worker_threads_.size();
2081 CHECK(current_worker_threads > delta);
2082 auto remain_worker_threads = current_worker_threads - delta;
2083 for (size_t i = remain_worker_threads; i < current_worker_threads; i++) {
2084 // Unix socket will be listening on the first worker,
2085 // so it MUST remove workers from the end of the vector.
2086 // Otherwise, the unix socket will be closed.
2087 auto worker_thread = std::move(worker_threads_.back());
2088 worker_threads_.pop_back();
2089 // Migrate connections to other workers before stopping the worker,
2090 // we use round-robin to choose the target worker here.
2091 auto connections = worker_thread->GetWorker()->GetConnections();
2092 for (const auto &iter : connections) {
2093 auto target_worker = worker_threads_[iter.first % remain_worker_threads]->GetWorker();
2094 worker_thread->GetWorker()->MigrateConnection(target_worker, iter.second);
2095 }
2096 worker_thread->Stop(10 /* graceful timeout */);
2097 // Don't join the worker thread here, because it may join itself.
2098 recycle_worker_threads_.push(std::move(worker_thread));
2099 }
2100}
2101
2102void Server::cleanupExitedWorkerThreads(bool force) {
2103 std::unique_ptr<WorkerThread> worker_thread = nullptr;

Callers

nothing calls this directly

Calls 5

GetConnectionsMethod · 0.80
GetWorkerMethod · 0.80
MigrateConnectionMethod · 0.80
pushMethod · 0.80
StopMethod · 0.45

Tested by

no test coverage detected