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

Method KillClient

src/server/server.cc:1823–1856  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1821}
1822
1823void Server::KillClient(int64_t *killed, const std::string &addr, uint64_t id, uint64_t type, bool skipme,
1824 redis::Connection *conn) {
1825 *killed = 0;
1826
1827 // Normal clients and pubsub clients
1828 for (const auto &t : worker_threads_) {
1829 int64_t killed_in_worker = 0;
1830 t->GetWorker()->KillClient(conn, id, addr, type, skipme, &killed_in_worker);
1831 *killed += killed_in_worker;
1832 }
1833
1834 // Slave clients
1835 {
1836 std::unique_lock<std::shared_mutex> guard(slave_threads_mu_);
1837 for (const auto &st : slave_threads_) {
1838 if ((type & kTypeSlave) ||
1839 (!addr.empty() && (st->GetConn()->GetAddr() == addr || st->GetConn()->GetAnnounceAddr() == addr)) ||
1840 (id != 0 && st->GetConn()->GetID() == id)) {
1841 st->Stop();
1842 (*killed)++;
1843 }
1844 }
1845 }
1846
1847 // Master client
1848 if (IsSlave() &&
1849 (type & kTypeMaster || (!addr.empty() && addr == master_host_ + ":" + std::to_string(master_port_)))) {
1850 // Stop replication thread and start a new one to replicate
1851 if (auto s = AddMaster(master_host_, master_port_, true); !s.IsOK()) {
1852 ERROR("[server] Failed to add master {}:{} with error: {}", master_host_, master_port_, s.Msg());
1853 }
1854 (*killed)++;
1855 }
1856}
1857
1858ReplState Server::GetReplicationState() {
1859 std::lock_guard<std::mutex> guard(slaveof_mu_);

Callers 1

ExecuteMethod · 0.45

Calls 8

GetWorkerMethod · 0.80
GetAddrMethod · 0.80
GetConnMethod · 0.80
GetAnnounceAddrMethod · 0.80
GetIDMethod · 0.80
StopMethod · 0.45
IsOKMethod · 0.45
MsgMethod · 0.45

Tested by

no test coverage detected