From 1c477f62bc34cc6c5ea42f48aac40148cd778441 Mon Sep 17 00:00:00 2001 From: Matt Stancliff Date: Thu, 8 Jan 2015 13:28:35 -0500 Subject: [PATCH 1/2] Fix redis-trib cluster create Under certain conditions the node list wasn't being fully populated and 'create' would fail trying to call methods on nil objects. --- src/redis-trib.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/redis-trib.rb b/src/redis-trib.rb index e5e7f2da..6b395b0d 100755 --- a/src/redis-trib.rb +++ b/src/redis-trib.rb @@ -563,8 +563,17 @@ class RedisTrib # Take one node from each IP until we run out of nodes # across every IP. ips.each do |ip,nodes| - stop = nodes.empty? and next - interleaved.push nodes.shift + if nodes.empty? + # if this IP has no remaining nodes, check for termination + if interleaved.length == nodes_count + # stop when 'interleaved' has accumulated all nodes + stop = true + next + end + else + # else, move one node from this IP to 'interleaved' + interleaved.push nodes.shift + end end end From bf58f8b513b95134e6122f97884046afe41de7d4 Mon Sep 17 00:00:00 2001 From: Matt Stancliff Date: Thu, 8 Jan 2015 13:31:03 -0500 Subject: [PATCH 2/2] Remove end of line whitespace from redis-trib --- src/redis-trib.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/redis-trib.rb b/src/redis-trib.rb index 6b395b0d..6002e4ca 100755 --- a/src/redis-trib.rb +++ b/src/redis-trib.rb @@ -72,7 +72,7 @@ class ClusterNode @friends end - def slots + def slots @info[:slots] end @@ -154,7 +154,7 @@ class ClusterNode end } if slots @dirty = false - @r.cluster("info").split("\n").each{|e| + @r.cluster("info").split("\n").each{|e| k,v=e.split(":") k = k.to_sym v.chop! @@ -213,7 +213,7 @@ class ClusterNode # # Note: this could be easily written without side effects, # we use 'slots' just to split the computation into steps. - + # First step: we want an increasing array of integers # for instance: [1,2,3,4,5,8,9,20,21,22,23,24,25,30] slots = @info[:slots].keys.sort @@ -273,7 +273,7 @@ class ClusterNode def info @info end - + def is_dirty? @dirty end @@ -789,7 +789,7 @@ class RedisTrib # Move slots between source and target nodes using MIGRATE. # - # Options: + # Options: # :verbose -- Print a dot for every moved key. # :fix -- We are moving in the context of a fix. Use REPLACE. # :cold -- Move keys without opening / reconfiguring the nodes. @@ -1232,7 +1232,7 @@ end ################################################################################# # Libraries -# +# # We try to don't depend on external libs since this is a critical part # of Redis Cluster. #################################################################################