aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHuabingZhao <zhao.huabing@zte.com.cn>2018-03-07 10:43:42 +0800
committerHuabingZhao <zhao.huabing@zte.com.cn>2018-03-07 10:43:47 +0800
commit243e817e999324ac8d5b23037876aee7a5720100 (patch)
tree5e24efee705565306462807607ce6fdd319510fa
parentdecc4a36e208e38c9944481908652435aaa51ca7 (diff)
Solve IP-Hash issue
Use deepcopy to avoid the side effect, which cause the client request is forward to wrong service instance occassionally. Issue-ID: MSB-154 Change-Id: I51e04fb273c2ca13c43b1e66fab44424e6af837e Signed-off-by: HuabingZhao <zhao.huabing@zte.com.cn>
-rw-r--r--openresty-ext/src/assembly/resources/openresty/nginx/luaext/loadbalance/policy/consistent_hash.lua6
1 files changed, 3 insertions, 3 deletions
diff --git a/openresty-ext/src/assembly/resources/openresty/nginx/luaext/loadbalance/policy/consistent_hash.lua b/openresty-ext/src/assembly/resources/openresty/nginx/luaext/loadbalance/policy/consistent_hash.lua
index b3cd46e..344b261 100644
--- a/openresty-ext/src/assembly/resources/openresty/nginx/luaext/loadbalance/policy/consistent_hash.lua
+++ b/openresty-ext/src/assembly/resources/openresty/nginx/luaext/loadbalance/policy/consistent_hash.lua
@@ -31,7 +31,7 @@ local LUCKY_NUM = 13
local tbl_util = require('lib.utils.table_util')
local tbl_isempty = tbl_util.isempty
-local tbl_isequal = require('pl.tablex')
+local tablex = require('pl.tablex')
local peerwatcher = require "core.peerwatcher"
local ngx_var = ngx.var
local hash_data = {}
@@ -73,10 +73,10 @@ end
local function update_consistent_hash_state(hash_data,servers,svckey)
-- compare servers in ctx with servers in cache
-- update the hash data if changes occur
- local serverscache = hash_data[svckey].servers
+ local serverscache = tablex.deepcopy(hash_data[svckey].servers)
tab_sort(serverscache, function(a, b) return a.ip < b.ip end)
tab_sort(servers, function(a, b) return a.ip < b.ip end)
- if not tbl_isequal.deepcompare(serverscache, servers, false) then
+ if not tablex.deepcompare(serverscache, servers, false) then
local tmp_chash = init_consistent_hash_state(servers)
hash_data[svckey].servers =servers
hash_data[svckey].chash = tmp_chash