diff --git a/src/ServerGroup.cpp b/src/ServerGroup.cpp index e5d088c..5e4cb74 100644 --- a/src/ServerGroup.cpp +++ b/src/ServerGroup.cpp @@ -49,14 +49,16 @@ Server* ServerGroup::getServer(Handler* h, Request* req) const Server* serv = nullptr; if (req->requireWrite()) { int cnt = mServs.size(); - for (int i = 0; i < cnt; ++i) { + for (int i = cnt-1; i >= 0; --i) { Server* s = mServs[i]; if (!s->online()) { continue; } if (s->role() == Server::Master) { serv = s; - break; + if (!s->fail()){ + break; + } } } } else if (auto dataCenter = mPool->proxy()->dataCenter()) {