moped 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of moped might be problematic. Click here for more details.

data/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Overview
2
2
 
3
+ ## 1.3.2
4
+
5
+ ### Resolved Issues
6
+
7
+ * \#131 Give better error messages when assertion and assertionCode are
8
+ present in the result.
9
+
10
+ * \#130 Flag down as down in refresh when not primary or secondary.
11
+ (Nilson Santos Figueiredo Jr)
12
+
13
+ * \#128 Fix refresh check to only check nodes that have been down longer
14
+ than the refresh boundary using the proper interval.
15
+
16
+ * \#125 Batch size and no timeout are now respected by queries.
17
+ (Derek Buttineau)
18
+
19
+ * \#124 Fix packing of bytes in core messages for big endian systems.
20
+
3
21
  ## 1.3.1
4
22
 
5
23
  ### Resolved Issues
data/lib/moped/cluster.rb CHANGED
@@ -127,7 +127,7 @@ module Moped
127
127
  # Find the nodes that were down but are ready to be refreshed, or those
128
128
  # with stale connection information.
129
129
  needs_refresh, available = @nodes.partition do |node|
130
- (node.down? && node.down_at < down_boundary) || node.needs_refresh?(refresh_boundary)
130
+ node.down? ? (node.down_at < down_boundary) : node.needs_refresh?(refresh_boundary)
131
131
  end
132
132
 
133
133
  # Refresh those nodes.
data/lib/moped/cursor.rb CHANGED
@@ -41,12 +41,29 @@ module Moped
41
41
  #
42
42
  # @since 1.0.0
43
43
  def get_more
44
- reply = @node.get_more @database, @collection, @cursor_id, @limit
44
+ reply = @node.get_more @database, @collection, @cursor_id, request_limit
45
45
  @limit -= reply.count if limited?
46
46
  @cursor_id = reply.cursor_id
47
47
  reply.documents
48
48
  end
49
49
 
50
+ # Determine the request limit for the query
51
+ #
52
+ # @example What is the cursor request_limit
53
+ # cursor.request_limit
54
+ #
55
+ # @return [ Integer ]
56
+ #
57
+ # @since 1.0.0
58
+
59
+ def request_limit
60
+ if limited?
61
+ @batch_size < @limit ? @batch_size : @limit
62
+ else
63
+ @batch_size
64
+ end
65
+ end
66
+
50
67
  # Initialize the new cursor.
51
68
  #
52
69
  # @example Create the new cursor.
@@ -66,13 +83,14 @@ module Moped
66
83
  @cursor_id = 0
67
84
  @limit = query_operation.limit
68
85
  @limited = @limit > 0
86
+ @batch_size = query_operation.batch_size || @limit
69
87
 
70
88
  @options = {
71
89
  request_id: query_operation.request_id,
72
90
  flags: query_operation.flags,
73
91
  limit: query_operation.limit,
74
92
  skip: query_operation.skip,
75
- fields: query_operation.fields
93
+ fields: query_operation.fields,
76
94
  }
77
95
  end
78
96
 
@@ -111,9 +129,13 @@ module Moped
111
129
  def load_docs
112
130
  consistency = session.consistency
113
131
  @options[:flags] |= [:slave_ok] if consistency == :eventual
132
+ @options[:flags] |= [:no_cursor_timeout] if @options[:no_timeout]
133
+
134
+ options = @options.clone
135
+ options[:limit] = @options[:batch_size] if @options[:batch_size]
114
136
 
115
137
  reply, @node = session.context.with_node do |node|
116
- [ node.query(@database, @collection, @selector, @options), node ]
138
+ [ node.query(@database, @collection, @selector, options), node ]
117
139
  end
118
140
 
119
141
  @limit -= reply.count if limited?
data/lib/moped/errors.rb CHANGED
@@ -80,10 +80,13 @@ module Moped
80
80
  # @since 1.0.0
81
81
  def error_message
82
82
  err = details["err"] || details["errmsg"] || details["$err"]
83
-
84
83
  if code = details["code"]
85
84
  "failed with error #{code}: #{err.inspect}\n\n" <<
86
85
  "See #{ERROR_REFERENCE}\nfor details about this error."
86
+ elsif code = details["assertionCode"]
87
+ assertion = details["assertion"]
88
+ "failed with error #{code}: #{assertion.inspect}\n\n" <<
89
+ "See #{ERROR_REFERENCE}\nfor details about this error."
87
90
  else
88
91
  "failed with error #{err.inspect}"
89
92
  end
data/lib/moped/node.rb CHANGED
@@ -142,7 +142,7 @@ module Moped
142
142
  # We might have a replica set change with:
143
143
  # MongoDB uses 3 different error codes for "not master", [10054, 10056, 10058]
144
144
  # thus it is easier to capture the "err"
145
- if e.details["err"] == "not master"
145
+ if e.details["err"] == "not master"
146
146
  raise Errors::ReplicaSetReconfigured
147
147
  end
148
148
  raise
@@ -416,6 +416,10 @@ module Moped
416
416
 
417
417
  if !primary && Threaded.executing?(:ensure_primary)
418
418
  raise Errors::ReplicaSetReconfigured, "#{inspect} is no longer the primary node."
419
+ elsif !primary && !secondary
420
+ # not primary or secondary so mark it as down, since it's probably
421
+ # a recovering node withing the replica set
422
+ down!
419
423
  end
420
424
  rescue Timeout::Error
421
425
  @peers = []
@@ -245,7 +245,7 @@ module Moped
245
245
  end
246
246
 
247
247
  def serialize_#{name}(buffer)
248
- buffer << #{name}.pack('q*<')
248
+ buffer << #{name}.pack('q<*')
249
249
  end
250
250
 
251
251
  def deserialize_#{name}(buffer)
@@ -78,6 +78,12 @@ module Moped
78
78
  # @return [String, Symbol] the collection to query
79
79
  attr_reader :collection
80
80
 
81
+ attr_accessor :batch_size
82
+
83
+ def no_timeout=(enable)
84
+ @flags |= [:no_cursor_timeout] if enable
85
+ end
86
+
81
87
  # Create a new query command.
82
88
  #
83
89
  # @example
@@ -105,10 +111,11 @@ module Moped
105
111
  @full_collection_name = "#{database}.#{collection}"
106
112
  @selector = selector
107
113
  @request_id = options[:request_id]
108
- @flags = options[:flags]
114
+ @flags = options[:flags] || []
109
115
  @limit = options[:limit]
110
116
  @skip = options[:skip]
111
117
  @fields = options[:fields]
118
+ @batch_size = options[:batch_size]
112
119
  end
113
120
 
114
121
  def log_inspect
@@ -121,6 +128,7 @@ module Moped
121
128
  fields << ["flags=%s", flags.inspect]
122
129
  fields << ["limit=%s", limit.inspect]
123
130
  fields << ["skip=%s", skip.inspect]
131
+ fields << ["batch_size=%s", batch_size.inspect]
124
132
  fields << ["fields=%s", self.fields.inspect]
125
133
  f, v = fields.transpose
126
134
  f.join(" ") % v
data/lib/moped/query.rb CHANGED
@@ -173,6 +173,34 @@ module Moped
173
173
  self
174
174
  end
175
175
 
176
+ # Set the query's batch size.
177
+ #
178
+ # @example Set the batch size.
179
+ # db[:people].find.batch_size(20)
180
+ #
181
+ # @param [ Integer ] limit The number of documents per batch.
182
+ #
183
+ # @return [ Query ] self
184
+ #
185
+ # @since 1.0.0
186
+ def batch_size(batch_size)
187
+ operation.batch_size = batch_size
188
+ self
189
+ end
190
+
191
+ # Disable cursor timeout
192
+ #
193
+ # @example Disable cursor timeout.
194
+ # db[:people].find.no_timeout
195
+ #
196
+ # @return [ Query ] self
197
+ #
198
+ # @since 1.0.0
199
+ def no_timeout
200
+ operation.no_timeout = true
201
+ self
202
+ end
203
+
176
204
  # Execute a $findAndModify on the query.
177
205
  #
178
206
  # @example Find and modify a document, returning the original.
@@ -76,8 +76,6 @@ module Moped
76
76
  # @since 1.0.0
77
77
  def handle_socket_errors
78
78
  yield
79
- rescue Timeout::Error
80
- raise Errors::ConnectionFailure, "Timed out connection to Mongo on #{host}:#{port}"
81
79
  rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::EPIPE
82
80
  raise Errors::ConnectionFailure, "Could not connect to Mongo on #{host}:#{port}"
83
81
  rescue Errno::ECONNRESET
@@ -101,11 +99,15 @@ module Moped
101
99
  #
102
100
  # @since 1.0.0
103
101
  def connect(host, port, timeout)
104
- Timeout::timeout(timeout) do
105
- sock = new(host, port)
106
- sock.set_encoding('binary')
107
- sock.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
108
- sock
102
+ begin
103
+ Timeout::timeout(timeout) do
104
+ sock = new(host, port)
105
+ sock.set_encoding('binary')
106
+ sock.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
107
+ sock
108
+ end
109
+ rescue Timeout::Error
110
+ raise Errors::ConnectionFailure, "Timed out connection to Mongo on #{host}:#{port}"
109
111
  end
110
112
  end
111
113
  end
data/lib/moped/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Moped
3
- VERSION = "1.3.1"
3
+ VERSION = "1.3.2"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moped
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-02 00:00:00.000000000 Z
12
+ date: 2012-12-24 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A MongoDB driver for Ruby.
15
15
  email:
@@ -89,7 +89,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
89
  version: '0'
90
90
  segments:
91
91
  - 0
92
- hash: 3571351846230510378
92
+ hash: 1373323481754772077
93
93
  required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  version: '0'
99
99
  segments:
100
100
  - 0
101
- hash: 3571351846230510378
101
+ hash: 1373323481754772077
102
102
  requirements: []
103
103
  rubyforge_project:
104
104
  rubygems_version: 1.8.24