mirror of
https://github.com/fluencelabs/redis
synced 2025-04-01 15:21:03 +00:00
redis-trib: allow to reshard in non-interactive way.
The introduction of --from --to --slots --yes options allow to reshard from cli in an automated way from scripts. The code is ugly and needs refactoring as soon as we get it in RC / stable release.
This commit is contained in:
parent
8d4ff87b26
commit
73a809b159
@ -821,11 +821,26 @@ class RedisTrib
|
|||||||
puts "*** Please fix your cluster problems before resharding"
|
puts "*** Please fix your cluster problems before resharding"
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Get number of slots
|
||||||
|
if opt['slots']
|
||||||
|
numslots = opt['slots'].to_i
|
||||||
|
else
|
||||||
numslots = 0
|
numslots = 0
|
||||||
while numslots <= 0 or numslots > ClusterHashSlots
|
while numslots <= 0 or numslots > ClusterHashSlots
|
||||||
print "How many slots do you want to move (from 1 to #{ClusterHashSlots})? "
|
print "How many slots do you want to move (from 1 to #{ClusterHashSlots})? "
|
||||||
numslots = STDIN.gets.to_i
|
numslots = STDIN.gets.to_i
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Get the target instance
|
||||||
|
if opt['to']
|
||||||
|
target = get_node_by_name(opt['to'])
|
||||||
|
if !target || target.has_flag?("slave")
|
||||||
|
xputs "*** The specified node is not known or not a master, please retry."
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
else
|
||||||
target = nil
|
target = nil
|
||||||
while not target
|
while not target
|
||||||
print "What is the receiving node ID? "
|
print "What is the receiving node ID? "
|
||||||
@ -835,7 +850,20 @@ class RedisTrib
|
|||||||
target = nil
|
target = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Get the source instances
|
||||||
sources = []
|
sources = []
|
||||||
|
if opt['from']
|
||||||
|
opt['from'].split(',').each{|node_id|
|
||||||
|
src = get_node_by_name(node_id)
|
||||||
|
if !src || src.has_flag?("slave")
|
||||||
|
xputs "*** The specified node is not known or is not a master, please retry."
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
sources << src
|
||||||
|
}
|
||||||
|
else
|
||||||
xputs "Please enter all the source node IDs."
|
xputs "Please enter all the source node IDs."
|
||||||
xputs " Type 'all' to use all the nodes as source nodes for the hash slots."
|
xputs " Type 'all' to use all the nodes as source nodes for the hash slots."
|
||||||
xputs " Type 'done' once you entered all the source nodes IDs."
|
xputs " Type 'done' once you entered all the source nodes IDs."
|
||||||
@ -844,18 +872,9 @@ class RedisTrib
|
|||||||
line = STDIN.gets.chop
|
line = STDIN.gets.chop
|
||||||
src = get_node_by_name(line)
|
src = get_node_by_name(line)
|
||||||
if line == "done"
|
if line == "done"
|
||||||
if sources.length == 0
|
|
||||||
puts "No source nodes given, operation aborted"
|
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
break
|
break
|
||||||
end
|
|
||||||
elsif line == "all"
|
elsif line == "all"
|
||||||
@nodes.each{|n|
|
sources = "all"
|
||||||
next if n.info[:name] == target.info[:name]
|
|
||||||
next if n.has_flag?("slave")
|
|
||||||
sources << n
|
|
||||||
}
|
|
||||||
break
|
break
|
||||||
elsif !src || src.has_flag?("slave")
|
elsif !src || src.has_flag?("slave")
|
||||||
xputs "*** The specified node is not known or is not a master, please retry."
|
xputs "*** The specified node is not known or is not a master, please retry."
|
||||||
@ -865,6 +884,29 @@ class RedisTrib
|
|||||||
sources << src
|
sources << src
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if sources.length == 0
|
||||||
|
puts "*** No source nodes given, operation aborted"
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
|
||||||
|
# Handle soures == all.
|
||||||
|
if sources == "all"
|
||||||
|
sources = []
|
||||||
|
@nodes.each{|n|
|
||||||
|
next if n.info[:name] == target.info[:name]
|
||||||
|
next if n.has_flag?("slave")
|
||||||
|
sources << n
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
# Check if the destination node is the same of any source nodes.
|
||||||
|
if sources.index(target)
|
||||||
|
xputs "*** Target node is also listed among the source nodes!"
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
|
||||||
puts "\nReady to move #{numslots} slots."
|
puts "\nReady to move #{numslots} slots."
|
||||||
puts " Source nodes:"
|
puts " Source nodes:"
|
||||||
sources.each{|s| puts " "+s.info_string}
|
sources.each{|s| puts " "+s.info_string}
|
||||||
@ -873,9 +915,11 @@ class RedisTrib
|
|||||||
reshard_table = compute_reshard_table(sources,numslots)
|
reshard_table = compute_reshard_table(sources,numslots)
|
||||||
puts " Resharding plan:"
|
puts " Resharding plan:"
|
||||||
show_reshard_table(reshard_table)
|
show_reshard_table(reshard_table)
|
||||||
|
if !opt['yes']
|
||||||
print "Do you want to proceed with the proposed reshard plan (yes/no)? "
|
print "Do you want to proceed with the proposed reshard plan (yes/no)? "
|
||||||
yesno = STDIN.gets.chop
|
yesno = STDIN.gets.chop
|
||||||
exit(1) if (yesno != "yes")
|
exit(1) if (yesno != "yes")
|
||||||
|
end
|
||||||
reshard_table.each{|e|
|
reshard_table.each{|e|
|
||||||
move_slot(e[:source],target,e[:slot],:verbose=>true)
|
move_slot(e[:source],target,e[:slot],:verbose=>true)
|
||||||
}
|
}
|
||||||
@ -1253,7 +1297,8 @@ COMMANDS={
|
|||||||
ALLOWED_OPTIONS={
|
ALLOWED_OPTIONS={
|
||||||
"create" => {"replicas" => true},
|
"create" => {"replicas" => true},
|
||||||
"add-node" => {"slave" => false, "master-id" => true},
|
"add-node" => {"slave" => false, "master-id" => true},
|
||||||
"import" => {"from" => :required}
|
"import" => {"from" => :required},
|
||||||
|
"reshard" => {"from" => true, "to" => true, "slots" => true, "yes" => false}
|
||||||
}
|
}
|
||||||
|
|
||||||
def show_help
|
def show_help
|
||||||
|
Loading…
x
Reference in New Issue
Block a user