: count{cnt}
, proto{move(serv)}
{
- if (!cnt) {
- count = thread::hardware_concurrency()/2 ?: 4;
+ if (count < 4) {
+ count = stoi(getenv_else("MEMCACHED_CLUSTER", "4"));
+ }
+ if (!count) {
+ count = 1;
+ }
+ for (int i = 0; i < count; ++i) {
+ cluster.push_back(proto);
}
- reset();
+}
+
+Cluster::Cluster(vector<Server> servers)
+: count{servers.size()}
+, cluster{move(servers)}
+{
+
}
Cluster::~Cluster() {
return cluster;
}
-void Cluster::reset() {
- pids.clear();
- cluster.clear();
- for (int i = 0; i < count; ++i) {
- cluster.push_back(proto);
- }
-}
-
bool Cluster::start() {
bool started = true;
return started;
}
-void Cluster::stop() {
+void Cluster::stop(bool graceful) {
for (auto &server : cluster) {
server.drain();
- // no cookies for memcached; TERM is just too slow
- server.signal(SIGKILL);
+ if (graceful) {
+ server.stop();
+ } else {
+ // no cookies for memcached; TERM is just too slow
+ server.signal(SIGKILL);
+ }
}
}
}
}
}
+
+bool Cluster::restart() {
+ stop();
+ wait();
+ return start();
+}