moped 1.2.7 → 1.2.8

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,26 @@
1
1
  # Overview
2
2
 
3
+ ## 1.2.8 (branch: 1.2.0-stable)
4
+
5
+ ### Resolved Issues
6
+
7
+ * \#108 Connection drops that would result in a `nil` response on socket read or
8
+ a `SocketError` now re-raise a `ConnectionFailure` error which causes the
9
+ replica set to go through it's failover behavor with node refreshing.
10
+
11
+ * \#104 `Query#explain` now respects limit.
12
+
13
+ * \#103 Port defaults to 27017 instead of zero if not provided. (Chris Winslett)
14
+
15
+ * \#100 Fix duplicate object id potential issue for JRuby. (Tim Olsen)
16
+
17
+ * \#97 Propagate node options to newly discovered nodes. (Adam Lebsack)
18
+
19
+ * \#91 Added more graceful replica set handling when safe mode is enabled
20
+ and replica sets were reconfigured. (Nicolas Viennot)
21
+
22
+ * \#90 Include arbiters in the list of nodes to disconnect. (Matt Parlane)
23
+
3
24
  ## 1.2.7
4
25
 
5
26
  ### Resolved Issues
@@ -111,7 +111,8 @@ module Moped
111
111
 
112
112
  # Generate object id data for a given time using the provided +counter+.
113
113
  def generate(time, counter = 0)
114
- [time, @machine_id, Process.pid, counter << 8].pack("N NX lXX NX")
114
+ process_thread_id = "#{Process.pid}#{Thread.current.object_id}".hash % 0xFFFF
115
+ [time, @machine_id, process_thread_id, counter << 8].pack("N NX lXX NX")
115
116
  end
116
117
  end
117
118
 
data/lib/moped/cluster.rb CHANGED
@@ -28,7 +28,7 @@ module Moped
28
28
  #
29
29
  # @since 1.2.0
30
30
  def disconnect
31
- nodes.each { |node| node.disconnect } and true
31
+ nodes(include_arbiters: true).each { |node| node.disconnect } and true
32
32
  end
33
33
 
34
34
  # Get the interval at which a node should be flagged as down before
@@ -117,7 +117,7 @@ module Moped
117
117
  # @return [ Array<Node> ] the list of available nodes.
118
118
  #
119
119
  # @since 1.0.0
120
- def nodes
120
+ def nodes(opts = {})
121
121
  current_time = Time.new
122
122
  down_boundary = current_time - down_interval
123
123
  refresh_boundary = current_time - refresh_interval
@@ -133,7 +133,7 @@ module Moped
133
133
 
134
134
  # Now return all the nodes that are available and participating in the
135
135
  # replica set.
136
- available.reject { |node| node.down? || node.arbiter? }
136
+ available.reject { |node| node.down? || (!opts[:include_arbiters] && node.arbiter?) }
137
137
  end
138
138
 
139
139
  # Refreshes information for each of the nodes provided. The node list
@@ -85,7 +85,11 @@ module Moped
85
85
  def read
86
86
  with_connection do |socket|
87
87
  reply = Protocol::Reply.allocate
88
- response = socket.read(36).unpack('l<5q<l<2')
88
+ data = socket.read(36)
89
+ unless data
90
+ raise Errors::ConnectionFailure, "Attempted read from socket which returned no data."
91
+ end
92
+ response = data.unpack('l<5q<l<2')
89
93
  reply.length,
90
94
  reply.request_id,
91
95
  reply.response_to,
data/lib/moped/node.rb CHANGED
@@ -125,7 +125,21 @@ module Moped
125
125
  # Someone else wrapped this in an #ensure_primary block, so let the
126
126
  # reconfiguration exception bubble up.
127
127
  raise
128
- rescue Errors::OperationFailure, Errors::AuthenticationFailure, Errors::QueryFailure, Errors::CursorNotFound
128
+ rescue Errors::QueryFailure => e
129
+ # We might have a replica set change with:
130
+ # "failed with error 13435: "not master and slaveOk=false"
131
+ if e.details['code'] == 13435
132
+ raise Errors::ReplicaSetReconfigured
133
+ end
134
+ raise
135
+ rescue Errors::OperationFailure => e
136
+ # We might have a replica set change with:
137
+ # "failed with error 10054: "not master"
138
+ if e.details['code'] == 10054
139
+ raise Errors::ReplicaSetReconfigured
140
+ end
141
+ raise
142
+ rescue Errors::AuthenticationFailure, Errors::CursorNotFound
129
143
  # These exceptions are "expected" in the normal course of events, and
130
144
  # don't necessitate disconnecting.
131
145
  raise
@@ -578,7 +592,7 @@ module Moped
578
592
 
579
593
  def parse_address
580
594
  host, port = address.split(":")
581
- @port = port.to_i
595
+ @port = (port || 27017).to_i
582
596
  @ip_address = ::Socket.getaddrinfo(host, nil, ::Socket::AF_INET, ::Socket::SOCK_STREAM).first[3]
583
597
  @resolved_address = "#{@ip_address}:#{@port}"
584
598
  end
data/lib/moped/query.rb CHANGED
@@ -89,15 +89,16 @@ module Moped
89
89
  #
90
90
  # @since 1.0.0
91
91
  def explain
92
- hint, sort = operation.selector["$hint"], operation.selector["$orderby"]
93
- operation.selector = {
92
+ explanation = operation.selector.dup
93
+ hint = explanation["$hint"]
94
+ sort = explanation["$orderby"]
95
+ explanation = {
94
96
  "$query" => selector,
95
97
  "$explain" => true,
96
- "$limit" => operation.selector.fetch("$limit", 1).abs * -1
97
98
  }
98
- operation.selector["$orderby"] = sort if sort
99
- operation.selector["$hint"] = hint if hint
100
- each { |doc| return doc }
99
+ explanation["$orderby"] = sort if sort
100
+ explanation["$hint"] = hint if hint
101
+ Query.new(collection, explanation).limit(-(operation.limit.abs)).each { |doc| return doc }
101
102
  end
102
103
 
103
104
  # Get the first matching document.
data/lib/moped/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Moped
3
- VERSION = "1.2.7"
3
+ VERSION = "1.2.8"
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.2.7
4
+ version: 1.2.8
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-10-06 00:00:00.000000000 Z
12
+ date: 2012-11-04 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A MongoDB driver for Ruby.
15
15
  email:
@@ -85,7 +85,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
85
  version: '0'
86
86
  segments:
87
87
  - 0
88
- hash: -1523010636318133543
88
+ hash: 2810220741565392289
89
89
  required_rubygems_version: !ruby/object:Gem::Requirement
90
90
  none: false
91
91
  requirements:
@@ -94,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  version: '0'
95
95
  segments:
96
96
  - 0
97
- hash: -1523010636318133543
97
+ hash: 2810220741565392289
98
98
  requirements: []
99
99
  rubyforge_project:
100
100
  rubygems_version: 1.8.24