moped 1.1.6 → 1.2.0

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.

@@ -1,6 +1,25 @@
1
1
  # Overview
2
2
 
3
- ## 1.1.6 (branch: 1.1.0-stable)
3
+ ## 1.2.0
4
+
5
+ ### New Features
6
+
7
+ * mongoid/mongoid\#2251 Allow `continue_on_error` option to be provided to
8
+ inserts.
9
+
10
+ * mongoid/mongoid\#2210 Added `Session#disconnect` which will disconnect all
11
+ nodes in the cluster from their respective database servers. Useful for cases
12
+ where a large number of database connections are being created on separate
13
+ threads and need to be explicitly closed after their work is completed.
14
+
15
+ * \#33 Added `Session#databases` and `Session#database_names` as a convenience
16
+ for getting all database information for the server.
17
+
18
+ session = Moped::Session.new([ "localhost:27017" ])
19
+ session.database_names #=> [ "moped_test" ]
20
+ session.databases #=> { "databases" => [{ "name" => "moped_test" }]}
21
+
22
+ ## 1.1.6
4
23
 
5
24
  ### Resolved Issues
6
25
 
@@ -10,8 +29,6 @@
10
29
  * \#41 `ObjectId.from_time` now only includes the timestamp, no machine or
11
30
  process information.
12
31
 
13
- ### Resolved Issues
14
-
15
32
  ## 1.1.5
16
33
 
17
34
  ### Resolved Issues
@@ -28,6 +45,8 @@
28
45
 
29
46
  ## 1.1.2
30
47
 
48
+ ### Resolved Issues
49
+
31
50
  * \#37 Use `TCP_NODELAY` for socket options. (Nicolas Viennot)
32
51
 
33
52
  ## 1.1.1
@@ -47,6 +66,8 @@
47
66
 
48
67
  ## 1.0.1
49
68
 
69
+ * mongoid/mongoid\#2175 Fixed sorting by object ids.
70
+
50
71
  * \#28 `BSON::Binary` and `BSON::ObjectId` now have readable `to_s` and
51
72
  `inspect` methods. (Ara Howard)
52
73
 
data/README.md CHANGED
@@ -9,6 +9,7 @@ Project Tracking
9
9
 
10
10
  * [Mongoid Google Group](http://groups.google.com/group/mongoid)
11
11
  * [Moped Website and Documentation](http://mongoid.org/en/moped/)
12
+ * [Moped Code Climate](https://codeclimate.com/github/mongoid/moped)
12
13
 
13
14
  Compatibility
14
15
  -------------
@@ -19,6 +19,17 @@ module Moped
19
19
  @auth ||= {}
20
20
  end
21
21
 
22
+ # Disconnects all nodes in the cluster. This should only be used in cases
23
+ # where you know you're not going to use the cluster on the thread anymore
24
+ # and need to force the connections to close.
25
+ #
26
+ # @return [ true ] True if the disconnect succeeded.
27
+ #
28
+ # @since 1.2.0
29
+ def disconnect
30
+ nodes.each { |node| node.disconnect } and true
31
+ end
32
+
22
33
  # Initialize the new cluster.
23
34
  #
24
35
  # @example Initialize the cluster.
@@ -78,14 +78,17 @@ module Moped
78
78
  # db[:people].insert([{name: "John"}, {name: "Joe"}])
79
79
  #
80
80
  # @param [ Hash, Array<Hash> ] documents The document(s) to insert.
81
+ # @param [ Array ] flags The flags, valid values are :continue_on_error.
82
+ #
83
+ # @option options [Array] :continue_on_error Whether to continue on error.
81
84
  #
82
85
  # @return [ nil ] nil.
83
86
  #
84
87
  # @since 1.0.0
85
- def insert(documents)
88
+ def insert(documents, flags = nil)
86
89
  documents = [documents] unless documents.is_a?(Array)
87
90
  database.session.with(consistency: :strong) do |session|
88
- session.context.insert(database.name, name, documents)
91
+ session.context.insert(database.name, name, documents, flags: flags || [])
89
92
  end
90
93
  end
91
94
  end
@@ -141,6 +141,7 @@ module Moped
141
141
 
142
142
  # This is a wrapper around a tcp socket.
143
143
  class TCPSocket < ::TCPSocket
144
+ attr_reader :host, :port
144
145
 
145
146
  # Is the socket connection alive?
146
147
  #
@@ -158,6 +159,31 @@ module Moped
158
159
  end
159
160
  end
160
161
 
162
+ # Initialize the new TCPSocket.
163
+ #
164
+ # @example Initialize the socket.
165
+ # TCPSocket.new("127.0.0.1", 27017)
166
+ #
167
+ # @param [ String ] host The host.
168
+ # @param [ Integer ] port The port.
169
+ #
170
+ # @since 1.2.0
171
+ def initialize(host, port, *args)
172
+ @host, @port = host, port
173
+ handle_socket_errors { super }
174
+ end
175
+
176
+ # Read from the TCP socket.
177
+ #
178
+ # @param [ Integer ] length The length to read.
179
+ #
180
+ # @return [ Object ] The data.
181
+ #
182
+ # @since 1.2.0
183
+ def read(length)
184
+ handle_socket_errors { super }
185
+ end
186
+
161
187
  # Write to the socket.
162
188
  #
163
189
  # @example Write to the socket.
@@ -170,7 +196,19 @@ module Moped
170
196
  # @since 1.0.0
171
197
  def write(*args)
172
198
  raise Errors::ConnectionFailure, "Socket connection was closed by remote host" unless alive?
173
- super
199
+ handle_socket_errors { super }
200
+ end
201
+
202
+ private
203
+
204
+ def handle_socket_errors
205
+ yield
206
+ rescue Timeout::Error
207
+ raise Errors::ConnectionFailure, "Timed out connection to Mongo on #{host}:#{port}"
208
+ rescue Errno::ECONNREFUSED
209
+ raise Errors::ConnectionFailure, "Could not connect to Mongo on #{host}:#{port}"
210
+ rescue Errno::ECONNRESET
211
+ raise Errors::ConnectionFailure, "Connection reset to Mongo on #{host}:#{port}"
174
212
  end
175
213
 
176
214
  class << self
@@ -76,6 +76,16 @@ module Moped
76
76
  end
77
77
  end
78
78
 
79
+ # Force the node to disconnect from the server.
80
+ #
81
+ # @return [ nil ] nil.
82
+ #
83
+ # @since 1.2.0
84
+ def disconnect
85
+ auth.clear
86
+ connection.disconnect
87
+ end
88
+
79
89
  # Is the node down?
80
90
  #
81
91
  # @example Is the node down?
@@ -224,8 +234,8 @@ module Moped
224
234
  # @return [ Message ] The result of the operation.
225
235
  #
226
236
  # @since 1.0.0
227
- def insert(database, collection, documents)
228
- process(Protocol::Insert.new(database, collection, documents))
237
+ def insert(database, collection, documents, options = {})
238
+ process(Protocol::Insert.new(database, collection, documents, options))
229
239
  end
230
240
 
231
241
  # Kill all provided cursors on the node.
@@ -464,11 +474,6 @@ module Moped
464
474
  @connection ||= Connection.new
465
475
  end
466
476
 
467
- def disconnect
468
- auth.clear
469
- connection.disconnect
470
- end
471
-
472
477
  def connected?
473
478
  connection.connected?
474
479
  end
@@ -490,12 +495,6 @@ module Moped
490
495
  def connect
491
496
  connection.connect ip_address, port, timeout
492
497
  @down_at = nil
493
- rescue Timeout::Error
494
- raise Errors::ConnectionFailure, "Timed out connection to Mongo on #{address}"
495
- rescue Errno::ECONNREFUSED
496
- raise Errors::ConnectionFailure, "Could not connect to Mongo on #{address}"
497
- rescue Errno::ECONNRESET
498
- raise Errors::ConnectionFailure, "Connection reset to Mongo on #{address}"
499
498
  end
500
499
 
501
500
  def process(operation, &callback)
@@ -78,6 +78,47 @@ module Moped
78
78
  current_database.command(op)
79
79
  end
80
80
 
81
+ # Get a list of all the database names for the session.
82
+ #
83
+ # @example Get all the database names.
84
+ # session.database_names
85
+ #
86
+ # @note This requires admin access on your server.
87
+ #
88
+ # @return [ Array<String>] All the database names.
89
+ #
90
+ # @since 1.2.0
91
+ def database_names
92
+ databases["databases"].map { |database| database["name"] }
93
+ end
94
+
95
+ # Get information on all databases for the session. This includes the name,
96
+ # size on disk, and if it is empty or not.
97
+ #
98
+ # @example Get all the database information.
99
+ # session.databases
100
+ #
101
+ # @note This requires admin access on your server.
102
+ #
103
+ # @return [ Hash ] The hash of database information, under the "databases"
104
+ # key.
105
+ #
106
+ # @since 1.2.0
107
+ def databases
108
+ with(database: :admin).command(listDatabases: 1)
109
+ end
110
+
111
+ # Disconnects all nodes in the session's cluster. This should only be used
112
+ # in cases # where you know you're not going to use the cluster on the
113
+ # thread anymore and need to force the connections to close.
114
+ #
115
+ # @return [ true ] True if the disconnect succeeded.
116
+ #
117
+ # @since 1.2.0
118
+ def disconnect
119
+ cluster.disconnect
120
+ end
121
+
81
122
  # Drop the current database.
82
123
  #
83
124
  # @param (see Moped::Database#drop)
@@ -52,15 +52,15 @@ module Moped
52
52
  end
53
53
  end
54
54
 
55
- def insert(database, collection, documents)
55
+ def insert(database, collection, documents, options = {})
56
56
  with_node do |node|
57
57
  if safe?
58
58
  node.pipeline do
59
- node.insert(database, collection, documents)
59
+ node.insert(database, collection, documents, options)
60
60
  node.command("admin", { getlasterror: 1 }.merge(safety))
61
61
  end
62
62
  else
63
- node.insert(database, collection, documents)
63
+ node.insert(database, collection, documents, options)
64
64
  end
65
65
  end
66
66
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Moped
3
- VERSION = "1.1.6"
3
+ VERSION = "1.2.0"
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.1.6
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -85,7 +85,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
85
  version: '0'
86
86
  segments:
87
87
  - 0
88
- hash: -760618037812365492
88
+ hash: 338711224338156996
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: -760618037812365492
97
+ hash: 338711224338156996
98
98
  requirements: []
99
99
  rubyforge_project:
100
100
  rubygems_version: 1.8.24