Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug at @get_connection_by_slot: fix node[2] nil error (this the p… #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

iKuiki
Copy link

@iKuiki iKuiki commented Oct 13, 2017

在我的环境中运行此代码会碰到这个问题:
get_connection_by_slot方法获取当前槽对应连接时,表示端口的node表元素2(node[2])为nil导致错误

经过检查代码,发现node[3]中可以正常获取到host:port@adminPort,所以做了个临时解决方案

  • 如果node2为nil,则从node3中解析端口值并赋值给node2

附上调试代码与log:

330 function _M.get_connection_by_slot(self, slot)
331     ngx.log(ngx.DEBUG, "self.cluster_id: ", self.cluster_id)
332     local cluster = clusters[self.cluster_id]
333     ngx.log(ngx.DEBUG, "slot: ", slot)
334     local node = cluster.slots[slot]
335
336     if node == nil then
337         return self:get_random_connection()
338     end
339
340     ngx.log(ngx.DEBUG, "#node: ", #node)
341     for k,v in pairs(node) do
342         ngx.log(ngx.DEBUG, "k: ", k, ", v: ", v)
343     end
344     if node[2] == nil then
345         ngx.log(ngx.DEBUG, "node[2] is nil, try to get form node[3]: ", node[3])
346         local addr = Split(node[3], ':')
347         ngx.log(ngx.DEBUG, "addr[1]: ", addr[1], " , addr[2]: ", addr[2])
348         local ports = Split(addr[2], '@')
349         ngx.log(ngx.DEBUG, "ports[1]: ", ports[1], " , ports[2]: ", ports[2])
350         node[2] = ports[1]
351     end
352
353     ngx.log(ngx.DEBUG, "node[2]: ", node[2])
354     return get_redis_link(node[1], node[2], cluster.timeout)
355 end
[debug] redis_cluster.lua:331: get_connection_by_slot(): self.cluster_id: redis_cluster
[debug] redis_cluster.lua:333: get_connection_by_slot(): slot: 10440
[debug] redis_cluster.lua:340: get_connection_by_slot(): #node: 3
[debug] redis_cluster.lua:342: get_connection_by_slot(): k: 1, v: 10.0.20.202
[debug] redis_cluster.lua:342: get_connection_by_slot(): k: 3, v: 10.0.20.202:7001@17001
[debug] redis_cluster.lua:345: get_connection_by_slot(): node[2] is nil, try to get form node[3]: 10.0.20.202:7001@17001
[debug] redis_cluster.lua:347: get_connection_by_slot(): addr[1]: 10.0.20.202 , addr[2]: 7001@17001
[debug] redis_cluster.lua:349: get_connection_by_slot(): ports[1]: 7001 , ports[2]: 17001
[debug] redis_cluster.lua:353: get_connection_by_slot(): node[2]: 7001

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant