sdbcli 1.1.3 → 1.1.4
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.
- data/bin/sdbcli +42 -41
- metadata +1 -1
data/bin/sdbcli
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
|
3
3
|
|
4
|
-
Version = '1.1.
|
4
|
+
Version = '1.1.4'
|
5
5
|
HISTORY_FILE = File.join((ENV['HOME'] || ENV['USERPROFILE'] || '.'), '.sdbcli_history')
|
6
6
|
HISTSIZE = 500
|
7
7
|
SELECT_LIMIT = 2500
|
8
|
+
BATCH_ATTRS_LIMIT = 25
|
8
9
|
|
9
10
|
require 'rubygems'
|
10
11
|
require 'sdbcli'
|
@@ -24,8 +25,8 @@ $format = :yaml
|
|
24
25
|
$consistent = false
|
25
26
|
import = nil
|
26
27
|
export = nil
|
27
|
-
import_export_retry = 3
|
28
|
-
retry_interval =
|
28
|
+
$import_export_retry = 3
|
29
|
+
$retry_interval = 3
|
29
30
|
timeout = 60
|
30
31
|
|
31
32
|
ARGV.options do |opt|
|
@@ -39,8 +40,8 @@ ARGV.options do |opt|
|
|
39
40
|
opt.on('' , '--import=DOMAIN,FILE') {|v| import = v.split(/\s*,\s*/, 2) + [false] }
|
40
41
|
opt.on('' , '--import-replace=DOMAIN,FILE') {|v| import = v.split(/\s*,\s*/, 2) + [true] }
|
41
42
|
opt.on('' , '--export=DOMAIN,FILE') {|v| export = v.split(/\s*,\s*/, 2) }
|
42
|
-
opt.on('' , '--retry=NUM', Integer) {|v| import_export_retry = v.to_i }
|
43
|
-
opt.on('' , '--retry-interval=SECOND', Integer) {|v| retry_interval = v.to_i }
|
43
|
+
opt.on('' , '--retry=NUM', Integer) {|v| $import_export_retry = v.to_i }
|
44
|
+
opt.on('' , '--retry-interval=SECOND', Integer) {|v| $retry_interval = v.to_i }
|
44
45
|
opt.parse!
|
45
46
|
|
46
47
|
unless access_key_id and secret_access_key and sdb_endpoint
|
@@ -101,7 +102,11 @@ def execute(src, show_rows = false)
|
|
101
102
|
next
|
102
103
|
end
|
103
104
|
|
104
|
-
out =
|
105
|
+
out = nil
|
106
|
+
|
107
|
+
retry_api_call do
|
108
|
+
out = $runner.execute(query, inline, $consistent)
|
109
|
+
end
|
105
110
|
|
106
111
|
if out.kind_of?(Integer)
|
107
112
|
puts case $format
|
@@ -163,6 +168,29 @@ def execute(src, show_rows = false)
|
|
163
168
|
buf
|
164
169
|
end
|
165
170
|
|
171
|
+
def retry_api_call
|
172
|
+
($import_export_retry + 1).times do |i|
|
173
|
+
begin
|
174
|
+
yield
|
175
|
+
break
|
176
|
+
rescue Errno::ETIMEDOUT => e
|
177
|
+
raise e if i >= $import_export_retry
|
178
|
+
rescue SimpleDB::Error => e
|
179
|
+
if /\AServiceUnavailable:/ =~ e.message
|
180
|
+
raise e if i >= $import_export_retry
|
181
|
+
else
|
182
|
+
raise e
|
183
|
+
end
|
184
|
+
rescue Timeout::Error => e
|
185
|
+
raise e if i >= $import_export_retry
|
186
|
+
end
|
187
|
+
|
188
|
+
wait_sec = $retry_interval * (i + 1)
|
189
|
+
output_error("Retry... (wait %d seconds)" % wait_sec, true)
|
190
|
+
sleep wait_sec
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
166
194
|
# export mode
|
167
195
|
if export
|
168
196
|
export_domain, export_file = export
|
@@ -186,22 +214,8 @@ if export
|
|
186
214
|
loop do
|
187
215
|
items = nil
|
188
216
|
|
189
|
-
|
190
|
-
|
191
|
-
items = $runner.execute(query + query_expr, true, $consistent)
|
192
|
-
break
|
193
|
-
rescue SimpleDB::Error => e
|
194
|
-
if /\AServiceUnavailable:/ =~ e.message
|
195
|
-
raise e if i >= import_export_retry
|
196
|
-
else
|
197
|
-
raise e
|
198
|
-
end
|
199
|
-
rescue Timeout::Error => e
|
200
|
-
raise e if i >= import_export_retry
|
201
|
-
end
|
202
|
-
|
203
|
-
output_error("Retry... (wait %d seconds)" % retry_interval, true)
|
204
|
-
sleep retry_interval
|
217
|
+
retry_api_call do
|
218
|
+
items = $runner.execute(query + query_expr, true, $consistent)
|
205
219
|
end
|
206
220
|
|
207
221
|
break if items.empty?
|
@@ -226,8 +240,6 @@ if export
|
|
226
240
|
|
227
241
|
output_error("#{rownum} #{rownum > 1 ? 'rows' : 'row'} was outputted...", true)
|
228
242
|
end
|
229
|
-
|
230
|
-
output_error("#{rownum} #{rownum > 1 ? 'rows' : 'row'} was processed", true)
|
231
243
|
rescue => e
|
232
244
|
output_error e.message.strip
|
233
245
|
exit 1
|
@@ -241,6 +253,8 @@ if export
|
|
241
253
|
raise 'must not happen'
|
242
254
|
end
|
243
255
|
|
256
|
+
output_error("#{rownum} #{rownum > 1 ? 'rows' : 'row'} was processed", true)
|
257
|
+
|
244
258
|
begin
|
245
259
|
if export_file.kind_of?(IO) and export_file != $stdout and not export_file.closed?
|
246
260
|
export_file.close
|
@@ -290,27 +304,14 @@ if import
|
|
290
304
|
until (chunk = items.slice!(0, SELECT_LIMIT)).empty?
|
291
305
|
rownum += chunk.length
|
292
306
|
|
293
|
-
(
|
294
|
-
|
307
|
+
until (batch_chunk = chunk.slice!(0, BATCH_ATTRS_LIMIT)).empty?
|
308
|
+
retry_api_call do
|
295
309
|
if import_as_replace
|
296
|
-
$runner.driver.update(import_domain,
|
310
|
+
$runner.driver.update(import_domain, batch_chunk)
|
297
311
|
else
|
298
|
-
$runner.driver.insert(import_domain,
|
312
|
+
$runner.driver.insert(import_domain, batch_chunk)
|
299
313
|
end
|
300
|
-
|
301
|
-
break
|
302
|
-
rescue SimpleDB::Error => e
|
303
|
-
if /\AServiceUnavailable:/ =~ e.message
|
304
|
-
raise e if i >= import_export_retry
|
305
|
-
else
|
306
|
-
raise e
|
307
|
-
end
|
308
|
-
rescue Timeout::Error => e
|
309
|
-
raise e if i >= import_export_retry
|
310
314
|
end
|
311
|
-
|
312
|
-
output_error("Retry... (wait %d seconds)" % retry_interval, true)
|
313
|
-
sleep retry_interval
|
314
315
|
end
|
315
316
|
|
316
317
|
output_error("#{rownum} #{rownum > 1 ? 'rows' : 'row'} was inputted...", true)
|