]> granicus.if.org Git - pdns/commitdiff
dnsdist: Sort the servers based on their 'order' after it has been set
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 4 Dec 2017 11:22:19 +0000 (12:22 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 4 Dec 2017 11:22:19 +0000 (12:22 +0100)
We keep the servers ordered inside their pools because it's easier
for the policies that way, so we sort them whenever a new one is
added. However we were doing the sorting _before_ the order of the
new server had been set, resulting in the last added server to be
sorted based on an order of 0, regardless of its actual order.
Reported by Frank Even (thanks!).

pdns/dnsdist-lua.cc

index 571c78a089f69d1cd9807db8e573d01de2df85f5..d6a2b294f8009e88da9a9752ceba78afd4514222 100644 (file)
@@ -400,24 +400,6 @@ vector<std::function<void(void)>> setupLua(bool client, const std::string& confi
                          ret->qps=QPSLimiter(qpsVal, qpsVal);
                        }
 
-                       auto localPools = g_pools.getCopy();
-                       if(vars.count("pool")) {
-                         if(auto* pool = boost::get<string>(&vars["pool"]))
-                           ret->pools.insert(*pool);
-                         else {
-                           auto pools = boost::get<vector<pair<int, string> > >(vars["pool"]);
-                           for(auto& p : pools)
-                             ret->pools.insert(p.second);
-                         }
-                         for(const auto& poolName: ret->pools) {
-                           addServerToPool(localPools, poolName, ret);
-                         }
-                       }
-                       else {
-                         addServerToPool(localPools, "", ret);
-                       }
-                       g_pools.setState(localPools);
-
                        if(vars.count("order")) {
                          ret->order=std::stoi(boost::get<string>(vars["order"]));
                        }
@@ -491,6 +473,28 @@ vector<std::function<void(void)>> setupLua(bool client, const std::string& confi
                           }
                        }
 
+                        /* this needs to be done _AFTER_ the order has been set,
+                           since the server are kept ordered inside the pool */
+                        auto localPools = g_pools.getCopy();
+                        if(vars.count("pool")) {
+                          if(auto* pool = boost::get<string>(&vars["pool"])) {
+                            ret->pools.insert(*pool);
+                          }
+                          else {
+                            auto pools = boost::get<vector<pair<int, string> > >(vars["pool"]);
+                            for(auto& p : pools) {
+                             ret->pools.insert(p.second);
+                            }
+                          }
+                          for(const auto& poolName: ret->pools) {
+                            addServerToPool(localPools, poolName, ret);
+                          }
+                        }
+                        else {
+                          addServerToPool(localPools, "", ret);
+                        }
+                        g_pools.setState(localPools);
+
                        if (ret->connected) {
                          if(g_launchWork) {
                            g_launchWork->push_back([ret,cpus]() {