ruster 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +18 -1
  3. data/bin/ruster +56 -19
  4. data/ruster.gemspec +1 -1
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7f9a02c2de8ff2db1cb8be0199803ce1d45b3e1a
4
- data.tar.gz: d1781d3676d0c6a3d50de5ba720c7ce10fbae013
3
+ metadata.gz: c35baea7d1a295313170c4ef1345c6f22f872697
4
+ data.tar.gz: 76f8ba9ddf5ae1cf2cc5df865fe733770786fc21
5
5
  SHA512:
6
- metadata.gz: b0244b61e5992f70e752b034913f0d5881c30f0b7da3a82d5758b2098798799675ce4f0a0a9a537aebca6d8412015ec20da677115c7f488e3882d4eb3bfb76d8
7
- data.tar.gz: 5085f9a83289b4942f48e2ba8358b01de3f970abea481a8d007f48031415d39aa40070e33142301839727855ce642a553e1110830bd5d8125b0392aec82bc43e
6
+ metadata.gz: ef371dc30165f7284d3e0d1c1b250125320f675cc27391790195147f0ddd17d53b287ac130b10e23c1ffe48052fea74ca0cfebb641d4d0d0d86c5900ddf26609
7
+ data.tar.gz: d5c88f5c3cc8389231029ceea8a69153457056cc5c452eb1113b53a5c921d9d45d5df1b6dae60de1180b18fd0e0626aa78347a3f0ac765eb178f47010e6db5bf
data/README.md CHANGED
@@ -44,7 +44,7 @@ node.
44
44
  ### Execute a command in all nodes
45
45
 
46
46
  ```
47
- $ ruster call ip:port [CMD ...]
47
+ $ ruster each ip:port [CMD ...]
48
48
  ```
49
49
 
50
50
  Executes the [Redis command][redis-commands] in all nodes, displaying
@@ -59,6 +59,23 @@ $ ruster reshard cluster_ip:port slots target_ip:port source_ip:port [...]
59
59
  Reshards the cluster at `cluster_ip:port`, by moving `slots` slots
60
60
  from several `source_ip:port` to `target_ip:port`.
61
61
 
62
+ It accepts the following parameters:
63
+
64
+ * `-n` indicate destination DB (currently only `0` seem to be working)
65
+ * `-t` indicate timeout for [`MIGRATE`][migrate] keys
66
+
67
+ [migrate]: http://redis.io/commands/migrate
68
+
69
+ ### Global parameters
70
+
71
+ `ruster` accepts the following global parameters:
72
+
73
+ * `-v` verbose output. It could be used multiple times, to indicate
74
+ the level of verbosity.
75
+
76
+ 1. display log messages
77
+ 1. display Redis commands sent to the cluster
78
+
62
79
  ## TODO
63
80
 
64
81
  * documentation
data/bin/ruster CHANGED
@@ -4,14 +4,42 @@ require "redic"
4
4
  require "clap"
5
5
 
6
6
  $verbose = 0
7
- $timeout = 10_000_000
8
7
 
9
- action, *args = Clap.run ARGV, {
10
- "-v" => -> { $verbose += 1 },
11
- "-t" => ->(ms) { $timeout = ms }
12
- }
8
+ action, *args = Clap.run ARGV, "-v" => -> { $verbose += 1 }
13
9
 
14
- abort "Usage: #{File.basename($0)} <action> ip:port [...]" if action.nil? or args.nil? or args.empty?
10
+ USAGE = <<EOU
11
+ Usage: #{File.basename($0)} [-v] <action> ip:port [...]
12
+
13
+ Parameters
14
+
15
+ -v Increases verbosity level. Can be used more than once.
16
+
17
+ Actions
18
+
19
+ create ip:port [ip:port...]
20
+ Creates a cluster with all the passed nodes
21
+
22
+ add cluster_ip:port ip:port
23
+ Add node ip:port to the cluster at cluster_ip:port
24
+
25
+ remove cluster_ip:port ip:port
26
+ Remove node from the cluster at cluster_ip:port
27
+ Note that currently removing a node that has assigned
28
+ slots breaks the cluster state.
29
+
30
+ each cluster_ip:port CMD...
31
+ Execute Redis CMD in all nodes
32
+
33
+ reshard cluster_ip:port slots target_ip:port source_ip:port...
34
+ Reshards `slots` slots into target_ip:port, taking slots
35
+ proportionally from all the nodes in source_ip:port
36
+
37
+ Accepts `-n n` to indicate a destination DB
38
+ Accepts `-t ms` to indicate timeout for keys migration
39
+
40
+ EOU
41
+
42
+ abort USAGE if action.nil? or args.nil? or args.empty?
15
43
 
16
44
  module UI
17
45
  def err msg
@@ -214,7 +242,7 @@ class Cluster
214
242
  end
215
243
  end
216
244
 
217
- def call(*args)
245
+ def each(*args)
218
246
  nodes!.each do |node|
219
247
  UI.info "#{node}: #{args.join(' ')}"
220
248
 
@@ -224,7 +252,9 @@ class Cluster
224
252
  end
225
253
  end
226
254
 
227
- def reshard(target_addr, slots, sources)
255
+ def reshard(target_addr, slots, sources, opts={})
256
+ options = { timeout: 1_000, db: 0 }.merge(opts)
257
+
228
258
  target = Node.new(target_addr)
229
259
 
230
260
  from = sources.map{ |addr| Node.new(addr) } \
@@ -234,6 +264,8 @@ class Cluster
234
264
  sum + source.slots[:slots].size
235
265
  end
236
266
 
267
+ UI.abort "No slots found to migrate" unless total_slots > 0
268
+
237
269
  from.each do |source|
238
270
  # Proportional number of slots, based on current assigned slots
239
271
  node_slots = (slots.to_f / total_slots * source.slots[:slots].size).to_i
@@ -241,7 +273,9 @@ class Cluster
241
273
  UI.info "Moving #{node_slots} slots from #{source} to #{target}"
242
274
 
243
275
  source.slots[:slots].take(node_slots).each do |slot|
244
- UI.log " Moving slot #{slot} from #{source} to #{target}"
276
+ count = source.call("CLUSTER", "COUNTKEYSINSLOT", slot)
277
+
278
+ UI.log " Moving slot #{slot} (#{count} keys)"
245
279
 
246
280
  target.call("CLUSTER", "SETSLOT", slot, "IMPORTING", source.id)
247
281
  source.call("CLUSTER", "SETSLOT", slot, "MIGRATING", target.id)
@@ -254,9 +288,11 @@ class Cluster
254
288
  done = keys.empty?
255
289
 
256
290
  keys.each do |key|
257
- res = source.call("MIGRATE", target.ip, target.port, key, 0, 5000)
291
+ res = source.call("MIGRATE", target.ip, target.port, key, options[:db], options[:timeout])
258
292
 
259
293
  UI.abort res.message if res.is_a?(RuntimeError)
294
+
295
+ $stdout.print '.' if $verbose > 2
260
296
  end
261
297
  end
262
298
 
@@ -287,22 +323,23 @@ begin
287
323
  args.each do |addr|
288
324
  cluster.remove_node(Node.new(addr))
289
325
  end
290
- when "call"
326
+ when "each"
291
327
  cluster = Cluster.new(args.shift)
292
328
 
293
- cluster.call(*args)
329
+ cluster.each(*args)
294
330
  when "reshard"
295
- cluster = Cluster.new(args.shift)
296
-
297
- slots = Integer(args.shift)
331
+ options = {}
298
332
 
299
- target = args.shift
333
+ cluster_addr, slots, target_addr, *sources = Clap.run args, {
334
+ "-t" => ->(ms) { options[:timeout] = Integer(ms) },
335
+ "-n" => ->(db) { options[:db] = db }
336
+ }
300
337
 
301
- sources = args
338
+ cluster = Cluster.new(cluster_addr)
302
339
 
303
- cluster.reshard(target, slots, sources)
340
+ cluster.reshard(target_addr, slots, sources, options)
304
341
  else
305
- UI.abort "Unrecognized action #{action}"
342
+ UI.abort "Unrecognized action `#{action}'\n#{USAGE}"
306
343
  end
307
344
  rescue => ex
308
345
  UI.abort ex.message, ex.backtrace
data/ruster.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "ruster"
5
- s.version = "0.0.2"
5
+ s.version = "0.0.3"
6
6
  s.summary = "A simple Redis Cluster Administration tool"
7
7
  s.description = "Control your Redis Cluster from the command line."
8
8
  s.authors = ["Leandro López"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruster
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leandro López