: count{cnt}
, proto{move(serv)}
{
- if (count < 4) {
- count = stoi(getenv_else("MEMCACHED_CLUSTER", "4"));
- }
if (!count) {
count = 1;
}
- reset();
+ for (int i = 0; i < count; ++i) {
+ cluster.push_back(proto);
+ }
}
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();
+}