mongo 1.8.6 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/Rakefile +13 -1
  5. data/VERSION +1 -1
  6. data/bin/mongo_console +15 -0
  7. data/lib/mongo.rb +14 -0
  8. data/lib/mongo/collection.rb +80 -42
  9. data/lib/mongo/cursor.rb +15 -1
  10. data/lib/mongo/db.rb +56 -19
  11. data/lib/mongo/exceptions.rb +14 -0
  12. data/lib/mongo/gridfs/grid.rb +16 -3
  13. data/lib/mongo/gridfs/grid_ext.rb +14 -0
  14. data/lib/mongo/gridfs/grid_file_system.rb +16 -3
  15. data/lib/mongo/gridfs/grid_io.rb +17 -3
  16. data/lib/mongo/legacy.rb +14 -0
  17. data/lib/mongo/mongo_client.rb +93 -40
  18. data/lib/mongo/mongo_replica_set_client.rb +21 -0
  19. data/lib/mongo/mongo_sharded_client.rb +15 -1
  20. data/lib/mongo/networking.rb +14 -0
  21. data/lib/mongo/util/conversions.rb +16 -2
  22. data/lib/mongo/util/core_ext.rb +14 -31
  23. data/lib/mongo/util/logging.rb +23 -7
  24. data/lib/mongo/util/node.rb +17 -2
  25. data/lib/mongo/util/pool.rb +17 -1
  26. data/lib/mongo/util/pool_manager.rb +15 -2
  27. data/lib/mongo/util/read_preference.rb +14 -0
  28. data/lib/mongo/util/server_version.rb +15 -0
  29. data/lib/mongo/util/sharding_pool_manager.rb +13 -0
  30. data/lib/mongo/util/socket_util.rb +14 -0
  31. data/lib/mongo/util/ssl_socket.rb +48 -7
  32. data/lib/mongo/util/support.rb +14 -0
  33. data/lib/mongo/util/tcp_socket.rb +18 -4
  34. data/lib/mongo/util/thread_local_variable_manager.rb +14 -0
  35. data/lib/mongo/util/unix_socket.rb +20 -6
  36. data/lib/mongo/util/uri_parser.rb +16 -8
  37. data/lib/mongo/util/write_concern.rb +16 -2
  38. data/test/functional/authentication_test.rb +26 -1
  39. data/test/functional/collection_test.rb +140 -41
  40. data/test/functional/connection_test.rb +19 -6
  41. data/test/functional/conversions_test.rb +14 -0
  42. data/test/functional/cursor_fail_test.rb +14 -0
  43. data/test/functional/cursor_message_test.rb +14 -0
  44. data/test/functional/cursor_test.rb +15 -1
  45. data/test/functional/db_api_test.rb +15 -1
  46. data/test/functional/db_connection_test.rb +14 -0
  47. data/test/functional/db_test.rb +14 -0
  48. data/test/functional/grid_file_system_test.rb +16 -4
  49. data/test/functional/grid_io_test.rb +14 -0
  50. data/test/functional/grid_test.rb +14 -0
  51. data/test/functional/pool_test.rb +22 -6
  52. data/test/functional/safe_test.rb +14 -0
  53. data/test/functional/ssl_test.rb +109 -0
  54. data/test/functional/support_test.rb +14 -0
  55. data/test/functional/threading_test.rb +22 -8
  56. data/test/functional/timeout_test.rb +20 -6
  57. data/test/functional/uri_test.rb +14 -14
  58. data/test/functional/write_concern_test.rb +14 -0
  59. data/test/replica_set/authentication_test.rb +28 -2
  60. data/test/replica_set/basic_test.rb +14 -0
  61. data/test/replica_set/client_test.rb +14 -0
  62. data/test/replica_set/complex_connect_test.rb +14 -0
  63. data/test/replica_set/connection_test.rb +14 -0
  64. data/test/replica_set/count_test.rb +14 -0
  65. data/test/replica_set/cursor_test.rb +14 -0
  66. data/test/replica_set/insert_test.rb +14 -0
  67. data/test/replica_set/max_values_test.rb +14 -0
  68. data/test/replica_set/pinning_test.rb +14 -0
  69. data/test/replica_set/query_test.rb +14 -0
  70. data/test/replica_set/read_preference_test.rb +14 -0
  71. data/test/replica_set/refresh_test.rb +14 -0
  72. data/test/replica_set/replication_ack_test.rb +14 -0
  73. data/test/replica_set/ssl_test.rb +114 -0
  74. data/test/sharded_cluster/basic_test.rb +14 -0
  75. data/test/shared/authentication.rb +55 -0
  76. data/test/test_helper.rb +15 -1
  77. data/test/threading/basic_test.rb +14 -0
  78. data/test/tools/mongo_config.rb +16 -1
  79. data/test/tools/mongo_config_test.rb +15 -1
  80. data/test/unit/client_test.rb +14 -0
  81. data/test/unit/collection_test.rb +14 -0
  82. data/test/unit/connection_test.rb +14 -0
  83. data/test/unit/cursor_test.rb +14 -0
  84. data/test/unit/db_test.rb +15 -1
  85. data/test/unit/grid_test.rb +14 -0
  86. data/test/unit/mongo_sharded_client_test.rb +14 -0
  87. data/test/unit/node_test.rb +15 -0
  88. data/test/unit/pool_manager_test.rb +15 -0
  89. data/test/unit/pool_test.rb +14 -0
  90. data/test/unit/read_pref_test.rb +14 -0
  91. data/test/unit/read_test.rb +14 -0
  92. data/test/unit/safe_test.rb +14 -0
  93. data/test/unit/sharding_pool_manager_test.rb +15 -0
  94. data/test/unit/util_test.rb +14 -0
  95. data/test/unit/write_concern_test.rb +15 -1
  96. metadata +8 -4
  97. metadata.gz.sig +0 -0
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  #:nodoc:
2
16
  class Object
3
17
 
@@ -9,17 +23,6 @@ class Object
9
23
 
10
24
  end
11
25
 
12
- #:nodoc:
13
- module Enumerable
14
-
15
- #:nodoc:
16
- def each_with_object(memo)
17
- each { |element| yield(element, memo) }
18
- memo
19
- end unless [].respond_to?(:each_with_object)
20
-
21
- end
22
-
23
26
  #:nodoc:
24
27
  class Hash
25
28
 
@@ -65,23 +68,3 @@ class Class
65
68
  end
66
69
  end
67
70
  end
68
-
69
- # Fix a bug in the interaction of
70
- # mutexes and timeouts in Ruby 1.9.
71
- # See https://jira.mongodb.org/browse/RUBY-364 for details.
72
- if RUBY_VERSION > '1.9'
73
- class Mutex
74
- def lock_with_hack
75
- lock_without_hack
76
- rescue ThreadError => e
77
- if e.message != "deadlock; recursive locking"
78
- raise
79
- else
80
- unlock
81
- lock_without_hack
82
- end
83
- end
84
- alias_method :lock_without_hack, :lock
85
- alias_method :lock, :lock_with_hack
86
- end
87
- end
@@ -1,6 +1,28 @@
1
+ # Copyright (C) 2013 10gen Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  module Mongo
2
16
  module Logging
3
17
 
18
+ module Instrumenter
19
+ def self.instrument(name, payload = {})
20
+ yield
21
+ end
22
+ end
23
+
24
+ @instrumenter = Instrumenter
25
+
4
26
  def write_logging_startup_message
5
27
  log(:debug, "Logging level is currently :debug which could negatively impact " +
6
28
  "client-side performance. You should set your logging level no lower than " +
@@ -38,7 +60,7 @@ module Mongo
38
60
  end
39
61
 
40
62
  def self.instrumenter
41
- @instrumenter || Instrumenter
63
+ @instrumenter
42
64
  end
43
65
 
44
66
  def self.instrumenter=(instrumenter)
@@ -59,11 +81,5 @@ module Mongo
59
81
  msg
60
82
  end
61
83
  end
62
-
63
- module Instrumenter
64
- def self.instrument(name, payload = {})
65
- yield
66
- end
67
- end
68
84
  end
69
85
  end
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  module Mongo
2
16
  class Node
3
17
 
@@ -48,8 +62,9 @@ module Mongo
48
62
  @node_mutex.synchronize do
49
63
  begin
50
64
  @socket = @client.socket_class.new(@host, @port,
51
- @client.op_timeout, @client.connect_timeout
52
- )
65
+ @client.op_timeout,
66
+ @client.connect_timeout,
67
+ @client.socket_opts)
53
68
  rescue OperationTimeout, ConnectionFailure, OperationFailure, SocketError, SystemCallError, IOError => ex
54
69
  @client.log(:debug, "Failed connection to #{host_string} with #{ex.class}, #{ex.message}.")
55
70
  close
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  module Mongo
2
16
  class Pool
3
17
  PING_ATTEMPTS = 6
@@ -161,7 +175,9 @@ module Mongo
161
175
  # therefore, it runs within a mutex.
162
176
  def checkout_new_socket
163
177
  begin
164
- socket = @client.socket_class.new(@host, @port, @client.op_timeout)
178
+ socket = @client.socket_class.new(@host, @port, @client.op_timeout,
179
+ @client.connect_timeout,
180
+ @client.socket_opts)
165
181
  socket.pool = self
166
182
  rescue => ex
167
183
  socket.close if socket
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  module Mongo
2
16
  class PoolManager
3
17
  include ThreadLocalVariableManager
@@ -264,7 +278,6 @@ module Mongo
264
278
  end
265
279
  end
266
280
  members
267
- end
268
-
281
+ end
269
282
  end
270
283
  end
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  module Mongo
2
16
  module ReadPreference
3
17
  READ_PREFERENCES = [
@@ -1,4 +1,19 @@
1
+ # Copyright (C) 2013 10gen Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  module Mongo
16
+
2
17
  # Simple class for comparing server versions.
3
18
  class ServerVersion
4
19
  include Comparable
@@ -1,3 +1,16 @@
1
+ # Copyright (C) 2013 10gen Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
1
14
 
2
15
  module Mongo
3
16
  class ShardingPoolManager < PoolManager
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  module SocketUtil
2
16
 
3
17
  attr_accessor :pool, :pid
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  require 'socket'
2
16
  require 'openssl'
3
17
  require 'timeout'
@@ -10,18 +24,45 @@ module Mongo
10
24
  class SSLSocket
11
25
  include SocketUtil
12
26
 
13
- def initialize(host, port, op_timeout=nil, connect_timeout=nil)
14
- @op_timeout = op_timeout
27
+ def initialize(host, port, op_timeout=nil, connect_timeout=nil, opts={})
28
+ @pid = Process.pid
29
+ @op_timeout = op_timeout
15
30
  @connect_timeout = connect_timeout
16
- @pid = Process.pid
17
31
 
18
32
  @tcp_socket = ::TCPSocket.new(host, port)
19
33
  @tcp_socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
20
34
 
21
- @socket = OpenSSL::SSL::SSLSocket.new(@tcp_socket)
22
- @socket.sync_close = true
35
+ @context = OpenSSL::SSL::SSLContext.new
36
+
37
+ if opts[:cert]
38
+ @context.cert = OpenSSL::X509::Certificate.new(File.open(opts[:cert]))
39
+ end
40
+
41
+ if opts[:key]
42
+ @context.key = OpenSSL::PKey::RSA.new(File.open(opts[:key]))
43
+ end
44
+
45
+ if opts[:verify]
46
+ @context.ca_file = opts[:ca_cert]
47
+ @context.verify_mode = OpenSSL::SSL::VERIFY_PEER
48
+ end
23
49
 
24
- connect
50
+ begin
51
+ @socket = OpenSSL::SSL::SSLSocket.new(@tcp_socket, @context)
52
+ @socket.sync_close = true
53
+ connect
54
+ rescue SSLError
55
+ raise ConnectionFailure, "SSL handshake failed. MongoDB may " +
56
+ "not be configured with SSL support."
57
+ end
58
+
59
+ if opts[:verify]
60
+ unless OpenSSL::SSL.verify_certificate_identity(@socket.peer_cert, host)
61
+ raise ConnectionFailure, "SSL handshake failed. Hostname mismatch."
62
+ end
63
+ end
64
+
65
+ self
25
66
  end
26
67
 
27
68
  def connect
@@ -45,7 +86,7 @@ module Mongo
45
86
  end
46
87
  else
47
88
  @socket.sysread(length, buffer)
48
- end
89
+ end
49
90
  end
50
91
  end
51
92
  end
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  require 'digest/md5'
2
16
 
3
17
  module Mongo
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  require 'socket'
2
16
  require 'timeout'
3
17
 
@@ -10,14 +24,14 @@ module Mongo
10
24
  class TCPSocket
11
25
  include SocketUtil
12
26
 
13
- def initialize(host, port, op_timeout=nil, connect_timeout=nil)
14
- @op_timeout = op_timeout
27
+ def initialize(host, port, op_timeout=nil, connect_timeout=nil, opts={})
28
+ @op_timeout = op_timeout
15
29
  @connect_timeout = connect_timeout
16
- @pid = Process.pid
30
+ @pid = Process.pid
17
31
 
18
32
  # TODO: Prefer ipv6 if server is ipv6 enabled
19
33
  @address = Socket.getaddrinfo(host, nil, Socket::AF_INET).first[3]
20
- @port = port
34
+ @port = port
21
35
 
22
36
  @socket_address = Socket.pack_sockaddr_in(@port, @address)
23
37
  @socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  #:nodoc:
2
16
  module Mongo
3
17
  module ThreadLocalVariableManager
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
1
15
  require 'socket'
2
16
 
3
17
  module Mongo
@@ -7,15 +21,15 @@ module Mongo
7
21
  # sans Timeout::timeout
8
22
  #
9
23
  class UNIXSocket < TCPSocket
10
- def initialize(socket_path, port=:socket, op_timeout=nil, connect_timeout=nil)
11
- @op_timeout = op_timeout
24
+ def initialize(socket_path, port=:socket, op_timeout=nil, connect_timeout=nil, opts={})
25
+ @op_timeout = op_timeout
12
26
  @connect_timeout = connect_timeout
13
27
 
14
- @address = socket_path
15
- @port = :socket # purposely override input
28
+ @address = socket_path
29
+ @port = :socket # purposely override input
16
30
 
17
- @socket_address = Socket.pack_sockaddr_un(@address)
18
- @socket = Socket.new(Socket::AF_UNIX, Socket::SOCK_STREAM, 0)
31
+ @socket_address = Socket.pack_sockaddr_un(@address)
32
+ @socket = Socket.new(Socket::AF_UNIX, Socket::SOCK_STREAM, 0)
19
33
  connect
20
34
  end
21
35
  end