right_support 2.6.3 → 2.6.4
Sign up to get free protection for your applications and to get access to all the features.
@@ -104,6 +104,7 @@ module RightSupport::DB
|
|
104
104
|
# Used to access data persisted in Cassandra
|
105
105
|
# Provides wrappers for Cassandra client methods
|
106
106
|
class CassandraModel
|
107
|
+
include RightSupport::Log::Mixin
|
107
108
|
|
108
109
|
# Default timeout for client connection to Cassandra server
|
109
110
|
DEFAULT_TIMEOUT = 10
|
@@ -114,8 +115,6 @@ module RightSupport::DB
|
|
114
115
|
# Wrappers for Cassandra client
|
115
116
|
class << self
|
116
117
|
|
117
|
-
@@logger = nil
|
118
|
-
|
119
118
|
attr_reader :default_keyspace
|
120
119
|
attr_accessor :column_family
|
121
120
|
|
@@ -123,6 +122,8 @@ module RightSupport::DB
|
|
123
122
|
|
124
123
|
@@connections = {}
|
125
124
|
|
125
|
+
METHODS_TO_LOG = [:multi_get, :get, :get_indexed_slices, :get_columns, :insert, :remove, 'multi_get', 'get', 'get_indexed_slices', 'get_columns', 'insert', 'remove']
|
126
|
+
|
126
127
|
# Depricate usage of CassandraModel under Ruby < 1.9
|
127
128
|
def inherited(base)
|
128
129
|
raise UnsupportedRubyVersion, "Support only Ruby >= 1.9" unless RUBY_VERSION >= "1.9"
|
@@ -143,14 +144,6 @@ module RightSupport::DB
|
|
143
144
|
@@config = normalize_config(value) unless value.nil?
|
144
145
|
end
|
145
146
|
|
146
|
-
def logger=(l)
|
147
|
-
@@logger = l
|
148
|
-
end
|
149
|
-
|
150
|
-
def logger
|
151
|
-
@@logger
|
152
|
-
end
|
153
|
-
|
154
147
|
# Return current keyspaces name as Array of String
|
155
148
|
#
|
156
149
|
# === Return
|
@@ -321,13 +314,13 @@ module RightSupport::DB
|
|
321
314
|
end
|
322
315
|
|
323
316
|
# This method is an attempt to circumvent the Cassandra gem limitation of returning only 100 columns for wide rows
|
324
|
-
# This method returns only columns that are within the result set specified by a secondary index equality query
|
325
|
-
# This method will iterate through chunks of rows of the resultset and it will yield to the caller all of the
|
317
|
+
# This method returns only columns that are within the result set specified by a secondary index equality query
|
318
|
+
# This method will iterate through chunks of rows of the resultset and it will yield to the caller all of the
|
326
319
|
# columns in chunks of 1,000 until all of the columns have been retrieved
|
327
320
|
#
|
328
321
|
# == Parameters:
|
329
322
|
# @param [String] index column name
|
330
|
-
# @param [String] index column value
|
323
|
+
# @param [String] index column value
|
331
324
|
#
|
332
325
|
# == Yields:
|
333
326
|
# @yield [Array<String, Array<CassandraThrift::ColumnOrSuperColumn>>] irray containing ndex column value passed in and an array of columns matching the index query
|
@@ -482,12 +475,12 @@ module RightSupport::DB
|
|
482
475
|
do_op(:batch, *args, &block)
|
483
476
|
end
|
484
477
|
|
485
|
-
#
|
486
|
-
#
|
478
|
+
# Perform a Cassandra operation on the connection object.
|
479
|
+
# Rescue IOError by automatically reconnecting and retrying the operation.
|
487
480
|
#
|
488
481
|
# === Parameters
|
489
482
|
# meth(Symbol):: Method to be executed
|
490
|
-
# args(Array):: Method arguments
|
483
|
+
# *args(Array):: Method arguments to forward to the Cassandra connection
|
491
484
|
#
|
492
485
|
# === Block
|
493
486
|
# Block if any to be executed by method
|
@@ -495,12 +488,45 @@ module RightSupport::DB
|
|
495
488
|
# === Return
|
496
489
|
# (Object):: Value returned by executed method
|
497
490
|
def do_op(meth, *args, &block)
|
498
|
-
|
491
|
+
first_started_at ||= Time.now
|
492
|
+
retries ||= 0
|
493
|
+
started_at = Time.now
|
494
|
+
|
495
|
+
# cassandra functionality
|
496
|
+
result = conn.send(meth, *args, &block)
|
497
|
+
|
498
|
+
# log functionality
|
499
|
+
do_op_log(first_started_at, started_at, retries, meth, args[0], args[1])
|
500
|
+
|
501
|
+
return result
|
499
502
|
rescue IOError
|
500
503
|
reconnect
|
504
|
+
retries += 1
|
501
505
|
retry
|
502
506
|
end
|
503
507
|
|
508
|
+
def do_op_log(first_started_at, started_at, retries, meth, cf, key)
|
509
|
+
now = Time.now
|
510
|
+
attempt_time = now - started_at
|
511
|
+
|
512
|
+
if METHODS_TO_LOG.include?(meth)
|
513
|
+
if key.is_a?(Array)
|
514
|
+
key_count = key.size
|
515
|
+
else
|
516
|
+
key_count = 1
|
517
|
+
end
|
518
|
+
|
519
|
+
log_string = sprintf("CassandraModel %s, cf=%s, keys=%d, time=%.1fms", meth, cf, key_count, attempt_time)
|
520
|
+
|
521
|
+
if retries && retries > 0
|
522
|
+
total_time = now - first_started_at
|
523
|
+
log_string += sprintf(", retries=%d, total_time=%.1fms", retries, total_time)
|
524
|
+
end
|
525
|
+
|
526
|
+
logger.debug(log_string)
|
527
|
+
end
|
528
|
+
end
|
529
|
+
|
504
530
|
# Reconnect to Cassandra server
|
505
531
|
# Use BinaryProtocolAccelerated if it available
|
506
532
|
#
|
@@ -256,15 +256,16 @@ module RightSupport::Net
|
|
256
256
|
return result if complete
|
257
257
|
|
258
258
|
# Produce a summary message for the exception that gives a bit of detail
|
259
|
-
|
260
|
-
exceptions.each_pair do |
|
259
|
+
msg = []
|
260
|
+
exceptions.each_pair do |endpoint, list|
|
261
|
+
summary = []
|
261
262
|
list.each { |e| summary << e.class }
|
263
|
+
msg << "'#{endpoint}' => [#{summary.uniq.join(', ')}]"
|
262
264
|
end
|
263
|
-
|
264
|
-
msg = "Request failed after #{n} tries to #{exceptions.keys.size} endpoints. Exceptions: #{summary}"
|
265
|
+
message = "Request failed after #{n} tries to #{exceptions.keys.size} endpoints: (#{msg.join(', ')})"
|
265
266
|
|
266
|
-
logger.error "RequestBalancer: #{
|
267
|
-
raise NoResult.new(
|
267
|
+
logger.error "RequestBalancer: #{message}"
|
268
|
+
raise NoResult.new(message, exceptions)
|
268
269
|
end
|
269
270
|
|
270
271
|
# Provide an interface so one can query the RequestBalancer for statistics on
|
data/right_support.gemspec
CHANGED
@@ -7,8 +7,8 @@ spec = Gem::Specification.new do |s|
|
|
7
7
|
s.required_ruby_version = Gem::Requirement.new(">= 1.8.7")
|
8
8
|
|
9
9
|
s.name = 'right_support'
|
10
|
-
s.version = '2.6.
|
11
|
-
s.date = '2012-11-
|
10
|
+
s.version = '2.6.4'
|
11
|
+
s.date = '2012-11-11'
|
12
12
|
|
13
13
|
s.authors = ['Tony Spataro', 'Sergey Sergyenko', 'Ryan Williamson', 'Lee Kirchhoff', 'Sergey Enin', 'Alexey Karpik']
|
14
14
|
s.email = 'support@rightscale.com'
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: right_support
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 6
|
9
|
-
-
|
10
|
-
version: 2.6.
|
9
|
+
- 4
|
10
|
+
version: 2.6.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tony Spataro
|
@@ -20,7 +20,7 @@ autorequire:
|
|
20
20
|
bindir: bin
|
21
21
|
cert_chain: []
|
22
22
|
|
23
|
-
date: 2012-11-
|
23
|
+
date: 2012-11-11 00:00:00 -08:00
|
24
24
|
default_executable:
|
25
25
|
dependencies: []
|
26
26
|
|