]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: consistent hash - also check for individual pool's policies before pre-compu... 6737/head
authorCharles-Henri Bruyand <charles-henri.bruyand@open-xchange.com>
Thu, 16 Aug 2018 15:43:18 +0000 (17:43 +0200)
committerCharles-Henri Bruyand <charles-henri.bruyand@open-xchange.com>
Thu, 16 Aug 2018 15:50:00 +0000 (17:50 +0200)
pdns/dnsdist.cc

index d839f4043d81cea28bbcec8c9b6995b2e880e46e..3b21adc532c0e6948d23d3e34cefced55348b616 100644 (file)
@@ -2336,12 +2336,26 @@ try
 
   auto todo=setupLua(false, g_cmdLine.config);
 
-  if (g_policy.getLocal()->name == "chashed") {
-    vinfolog("Pre-computing hashes for consistent hash load-balancing policy");
-    // pre compute hashes
-    auto backends = g_dstates.getLocal();
-    for (auto& backend: *backends) {
-      backend->hash();
+  auto localPools = g_pools.getCopy();
+  {
+    bool precompute = false;
+    if (g_policy.getLocal()->name == "chashed") {
+      precompute = true;
+    } else {
+      for (const auto& entry: localPools) {
+        if (entry.second->policy != nullptr && entry.second->policy->name == "chashed") {
+          precompute = true;
+          break ;
+        }
+      }
+    }
+    if (precompute) {
+      vinfolog("Pre-computing hashes for consistent hash load-balancing policy");
+      // pre compute hashes
+      auto backends = g_dstates.getLocal();
+      for (auto& backend: *backends) {
+        backend->hash();
+      }
     }
   }
 
@@ -2680,7 +2694,7 @@ try
   for(auto& t : todo)
     t();
 
-  auto localPools = g_pools.getCopy();
+  localPools = g_pools.getCopy();
   /* create the default pool no matter what */
   createPoolIfNotExists(localPools, "");
   if(g_cmdLine.remotes.size()) {