From 510c45d0c2640c38bbc591241461b96c34d3f3de Mon Sep 17 00:00:00 2001 From: Robin Geuze Date: Mon, 5 Nov 2018 13:12:47 +0100 Subject: [PATCH] No longer keep a local copy of pools, and remove unneeded lua side effect --- pdns/dnsdist-lua-rules.cc | 4 +--- pdns/dnsdistdist/dnsdist-rules.hh | 7 +++---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/pdns/dnsdist-lua-rules.cc b/pdns/dnsdist-lua-rules.cc index 8fc84d4940..c209d10a50 100644 --- a/pdns/dnsdist-lua-rules.cc +++ b/pdns/dnsdist-lua-rules.cc @@ -441,9 +441,7 @@ void setupLuaRules() }); g_lua.writeFunction("PoolAvailableRule", [](std::string poolname) { - setLuaSideEffect(); - auto localPools = g_pools.getCopy(); - return std::shared_ptr(new PoolAvailableRule(localPools, poolname)); + return std::shared_ptr(new PoolAvailableRule(poolname)); }); g_lua.registerFunction::*)()>("clear", [](std::shared_ptr tisr) { diff --git a/pdns/dnsdistdist/dnsdist-rules.hh b/pdns/dnsdistdist/dnsdist-rules.hh index 10a40b6014..f343f4f5db 100644 --- a/pdns/dnsdistdist/dnsdist-rules.hh +++ b/pdns/dnsdistdist/dnsdist-rules.hh @@ -995,14 +995,13 @@ private: class PoolAvailableRule : public DNSRule { public: - PoolAvailableRule(pools_t& pools, const std::string& poolname) : d_poolname(poolname) + PoolAvailableRule(const std::string& poolname) : d_pools(&g_pools), d_poolname(poolname) { - d_pool = getPool(pools, poolname); } bool matches(const DNSQuestion* dq) const override { - return (d_pool->countServers(true) > 0); + return (getPool(*d_pools, d_poolname)->countServers(true) > 0); } string toString() const override @@ -1010,6 +1009,6 @@ public: return "pool '" + d_poolname + "' is available"; } private: + mutable LocalStateHolder d_pools; std::string d_poolname; - std::shared_ptr d_pool; }; -- 2.47.2