monga 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.travis.yml +1 -0
- data/README.md +59 -3
- data/lib/monga/client.rb +51 -6
- data/lib/monga/clients/master_slave_client.rb +0 -5
- data/lib/monga/clients/replica_set_client.rb +32 -71
- data/lib/monga/clients/single_instance_client.rb +53 -0
- data/lib/monga/collection.rb +102 -41
- data/lib/monga/connection.rb +38 -13
- data/lib/monga/connection_pool.rb +6 -17
- data/lib/monga/connections/buffer.rb +33 -0
- data/lib/monga/connections/em_connection.rb +25 -56
- data/lib/monga/connections/em_proxy_connection.rb +80 -0
- data/lib/monga/connections/fibered_connection.rb +26 -0
- data/lib/monga/connections/fibered_proxy_connection.rb +23 -0
- data/lib/monga/connections/proxy_connection.rb +4 -0
- data/lib/monga/connections/tcp_connection.rb +57 -0
- data/lib/monga/cursor.rb +197 -95
- data/lib/monga/database.rb +175 -60
- data/lib/monga/{requests → protocol}/delete.rb +1 -2
- data/lib/monga/{requests → protocol}/get_more.rb +1 -1
- data/lib/monga/{requests → protocol}/insert.rb +1 -2
- data/lib/monga/{requests → protocol}/kill_cursors.rb +1 -1
- data/lib/monga/{requests → protocol}/query.rb +3 -3
- data/lib/monga/{requests → protocol}/update.rb +1 -1
- data/lib/monga/request.rb +27 -23
- data/lib/monga/utils/constants.rb +5 -0
- data/lib/monga/utils/exceptions.rb +11 -0
- data/lib/monga.rb +19 -11
- data/monga.gemspec +2 -2
- data/spec/helpers/mongodb.rb +115 -38
- data/spec/monga/block/collection_spec.rb +172 -0
- data/spec/monga/block/cursor_spec.rb +160 -0
- data/spec/monga/block/database_spec.rb +80 -0
- data/spec/monga/block/single_instance_client_spec.rb +31 -0
- data/spec/monga/em/collection_spec.rb +308 -0
- data/spec/monga/em/cursor_spec.rb +256 -0
- data/spec/monga/em/database_spec.rb +140 -0
- data/spec/monga/em/replica_set_client_spec.rb +86 -0
- data/spec/monga/em/single_instance_client_spec.rb +28 -0
- data/spec/monga/sync/collection_spec.rb +247 -0
- data/spec/monga/sync/cursor_spec.rb +211 -0
- data/spec/monga/sync/database_spec.rb +110 -0
- data/spec/monga/sync/replica_set_client_spec.rb +54 -0
- data/spec/monga/sync/single_instance_client_spec.rb +25 -0
- data/spec/spec_helper.rb +2 -20
- metadata +50 -38
- data/lib/monga/clients/client.rb +0 -24
- data/lib/monga/connections/primary.rb +0 -46
- data/lib/monga/connections/secondary.rb +0 -13
- data/lib/monga/exceptions.rb +0 -9
- data/lib/monga/miner.rb +0 -72
- data/lib/monga/response.rb +0 -11
- data/spec/helpers/truncate.rb +0 -15
- data/spec/monga/collection_spec.rb +0 -448
- data/spec/monga/connection_pool_spec.rb +0 -50
- data/spec/monga/connection_spec.rb +0 -64
- data/spec/monga/cursor_spec.rb +0 -186
- data/spec/monga/database_spec.rb +0 -67
- data/spec/monga/replica_set_client_spec.rb +0 -46
- data/spec/monga/requests/delete_spec.rb +0 -0
- data/spec/monga/requests/insert_spec.rb +0 -0
- data/spec/monga/requests/query_spec.rb +0 -28
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: monga
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
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: 2013-04-
|
12
|
+
date: 2013-04-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -50,7 +50,7 @@ dependencies:
|
|
50
50
|
- !ruby/object:Gem::Version
|
51
51
|
version: '0'
|
52
52
|
none: false
|
53
|
-
type: :
|
53
|
+
type: :development
|
54
54
|
version_requirements: !ruby/object:Gem::Requirement
|
55
55
|
requirements:
|
56
56
|
- - ! '>='
|
@@ -58,7 +58,7 @@ dependencies:
|
|
58
58
|
version: '0'
|
59
59
|
none: false
|
60
60
|
prerelease: false
|
61
|
-
name:
|
61
|
+
name: em-synchrony
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
@@ -99,45 +99,53 @@ extensions: []
|
|
99
99
|
extra_rdoc_files: []
|
100
100
|
files:
|
101
101
|
- .gitignore
|
102
|
+
- .travis.yml
|
102
103
|
- Gemfile
|
103
104
|
- LICENSE.txt
|
104
105
|
- README.md
|
105
106
|
- Rakefile
|
106
107
|
- lib/monga.rb
|
107
108
|
- lib/monga/client.rb
|
108
|
-
- lib/monga/clients/client.rb
|
109
109
|
- lib/monga/clients/master_slave_client.rb
|
110
110
|
- lib/monga/clients/replica_set_client.rb
|
111
|
+
- lib/monga/clients/single_instance_client.rb
|
111
112
|
- lib/monga/collection.rb
|
112
113
|
- lib/monga/connection.rb
|
113
114
|
- lib/monga/connection_pool.rb
|
115
|
+
- lib/monga/connections/buffer.rb
|
114
116
|
- lib/monga/connections/em_connection.rb
|
115
|
-
- lib/monga/connections/
|
116
|
-
- lib/monga/connections/
|
117
|
+
- lib/monga/connections/em_proxy_connection.rb
|
118
|
+
- lib/monga/connections/fibered_connection.rb
|
119
|
+
- lib/monga/connections/fibered_proxy_connection.rb
|
120
|
+
- lib/monga/connections/proxy_connection.rb
|
121
|
+
- lib/monga/connections/tcp_connection.rb
|
117
122
|
- lib/monga/cursor.rb
|
118
123
|
- lib/monga/database.rb
|
119
|
-
- lib/monga/
|
120
|
-
- lib/monga/
|
124
|
+
- lib/monga/protocol/delete.rb
|
125
|
+
- lib/monga/protocol/get_more.rb
|
126
|
+
- lib/monga/protocol/insert.rb
|
127
|
+
- lib/monga/protocol/kill_cursors.rb
|
128
|
+
- lib/monga/protocol/query.rb
|
129
|
+
- lib/monga/protocol/update.rb
|
121
130
|
- lib/monga/request.rb
|
122
|
-
- lib/monga/
|
123
|
-
- lib/monga/
|
124
|
-
- lib/monga/requests/insert.rb
|
125
|
-
- lib/monga/requests/kill_cursors.rb
|
126
|
-
- lib/monga/requests/query.rb
|
127
|
-
- lib/monga/requests/update.rb
|
128
|
-
- lib/monga/response.rb
|
131
|
+
- lib/monga/utils/constants.rb
|
132
|
+
- lib/monga/utils/exceptions.rb
|
129
133
|
- monga.gemspec
|
130
134
|
- spec/helpers/mongodb.rb
|
131
|
-
- spec/
|
132
|
-
- spec/monga/
|
133
|
-
- spec/monga/
|
134
|
-
- spec/monga/
|
135
|
-
- spec/monga/
|
136
|
-
- spec/monga/
|
137
|
-
- spec/monga/
|
138
|
-
- spec/monga/
|
139
|
-
- spec/monga/
|
140
|
-
- spec/monga/
|
135
|
+
- spec/monga/block/collection_spec.rb
|
136
|
+
- spec/monga/block/cursor_spec.rb
|
137
|
+
- spec/monga/block/database_spec.rb
|
138
|
+
- spec/monga/block/single_instance_client_spec.rb
|
139
|
+
- spec/monga/em/collection_spec.rb
|
140
|
+
- spec/monga/em/cursor_spec.rb
|
141
|
+
- spec/monga/em/database_spec.rb
|
142
|
+
- spec/monga/em/replica_set_client_spec.rb
|
143
|
+
- spec/monga/em/single_instance_client_spec.rb
|
144
|
+
- spec/monga/sync/collection_spec.rb
|
145
|
+
- spec/monga/sync/cursor_spec.rb
|
146
|
+
- spec/monga/sync/database_spec.rb
|
147
|
+
- spec/monga/sync/replica_set_client_spec.rb
|
148
|
+
- spec/monga/sync/single_instance_client_spec.rb
|
141
149
|
- spec/spec_helper.rb
|
142
150
|
homepage: ''
|
143
151
|
licenses:
|
@@ -150,7 +158,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
150
158
|
requirements:
|
151
159
|
- - ! '>='
|
152
160
|
- !ruby/object:Gem::Version
|
153
|
-
hash:
|
161
|
+
hash: -1506820029322651348
|
154
162
|
version: '0'
|
155
163
|
segments:
|
156
164
|
- 0
|
@@ -159,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
167
|
requirements:
|
160
168
|
- - ! '>='
|
161
169
|
- !ruby/object:Gem::Version
|
162
|
-
hash:
|
170
|
+
hash: -1506820029322651348
|
163
171
|
version: '0'
|
164
172
|
segments:
|
165
173
|
- 0
|
@@ -172,14 +180,18 @@ specification_version: 3
|
|
172
180
|
summary: MongoDB Ruby Evented Driver on EventMachine
|
173
181
|
test_files:
|
174
182
|
- spec/helpers/mongodb.rb
|
175
|
-
- spec/
|
176
|
-
- spec/monga/
|
177
|
-
- spec/monga/
|
178
|
-
- spec/monga/
|
179
|
-
- spec/monga/
|
180
|
-
- spec/monga/
|
181
|
-
- spec/monga/
|
182
|
-
- spec/monga/
|
183
|
-
- spec/monga/
|
184
|
-
- spec/monga/
|
183
|
+
- spec/monga/block/collection_spec.rb
|
184
|
+
- spec/monga/block/cursor_spec.rb
|
185
|
+
- spec/monga/block/database_spec.rb
|
186
|
+
- spec/monga/block/single_instance_client_spec.rb
|
187
|
+
- spec/monga/em/collection_spec.rb
|
188
|
+
- spec/monga/em/cursor_spec.rb
|
189
|
+
- spec/monga/em/database_spec.rb
|
190
|
+
- spec/monga/em/replica_set_client_spec.rb
|
191
|
+
- spec/monga/em/single_instance_client_spec.rb
|
192
|
+
- spec/monga/sync/collection_spec.rb
|
193
|
+
- spec/monga/sync/cursor_spec.rb
|
194
|
+
- spec/monga/sync/database_spec.rb
|
195
|
+
- spec/monga/sync/replica_set_client_spec.rb
|
196
|
+
- spec/monga/sync/single_instance_client_spec.rb
|
185
197
|
- spec/spec_helper.rb
|
data/lib/monga/clients/client.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
module Monga::Clients
|
2
|
-
class Client
|
3
|
-
extend Forwardable
|
4
|
-
|
5
|
-
def_delegators :@connection_pool, :aquire_connection, :send_command, :primary?, :connected?
|
6
|
-
|
7
|
-
attr_reader :connection_pool
|
8
|
-
|
9
|
-
def initialize(opts={})
|
10
|
-
opts[:pool_size] ||= 1
|
11
|
-
@connection_pool = Monga::ConnectionPool.new(opts)
|
12
|
-
end
|
13
|
-
|
14
|
-
def [](db_name)
|
15
|
-
Monga::Database.new(self, db_name)
|
16
|
-
end
|
17
|
-
|
18
|
-
def find_primary!
|
19
|
-
@connection_pool.connections.each do |conn|
|
20
|
-
conn.is_master?(self)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
module Monga::Connections
|
2
|
-
class Primary < Monga::Connections::EMConnection
|
3
|
-
def initialize(opts)
|
4
|
-
@client = opts.delete :client
|
5
|
-
@ser
|
6
|
-
super
|
7
|
-
end
|
8
|
-
|
9
|
-
def connection_completed
|
10
|
-
check_master do |master|
|
11
|
-
if master
|
12
|
-
super
|
13
|
-
else
|
14
|
-
reconnect
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def check_master
|
20
|
-
db = @client["admin"]
|
21
|
-
request = Monga::Request.new(db, "$cmd", query: { "isMaster" => 1 })
|
22
|
-
request_id = request.request_id
|
23
|
-
@responses[request_id] = proc do |data|
|
24
|
-
request.parse_response(data)
|
25
|
-
if Exception === data
|
26
|
-
Monga.logger.debug("Error on connecting Primary to #{@host}:#{@port}, #{data.class}, #{data.message}")
|
27
|
-
@host, @port = @client.next_addr(@host, @port)
|
28
|
-
yield false
|
29
|
-
else
|
30
|
-
doc = data.last.first
|
31
|
-
if doc["ismaster"]
|
32
|
-
Monga.logger.debug("Primary has connected to #{@host}:#{@port}")
|
33
|
-
@client.inform(:primary, @host, @port)
|
34
|
-
yield true
|
35
|
-
else
|
36
|
-
Monga.logger.debug("#{@host}:#{@port} is not a primary")
|
37
|
-
@host, @port = @client.select_addr(doc)
|
38
|
-
yield false
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
command = request.command
|
43
|
-
send_data(command)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
data/lib/monga/exceptions.rb
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
module Monga::Exceptions
|
2
|
-
class LostConnection < StandardError; end
|
3
|
-
class CursorNotFound < StandardError; end
|
4
|
-
class CursorIsClosed < StandardError; end
|
5
|
-
class CursorLimit < StandardError; end
|
6
|
-
class QueryFailure < StandardError; end
|
7
|
-
class UndefinedIndexVersion < StandardError; end
|
8
|
-
class NoAvailableServers < StandardError; end
|
9
|
-
end
|
data/lib/monga/miner.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
# Miner is a "proxy" object to Cursor.
|
2
|
-
# It dinamically stores Cursor options and at any moment can return cursor.
|
3
|
-
# Also it hides Deferrable that could return all objects that cursor do.
|
4
|
-
module Monga
|
5
|
-
class Miner < EM::DefaultDeferrable
|
6
|
-
attr_reader :options
|
7
|
-
|
8
|
-
def initialize(db, collection_name, options={})
|
9
|
-
@db = db
|
10
|
-
@collection_name = collection_name
|
11
|
-
@options = options
|
12
|
-
|
13
|
-
# Defaults
|
14
|
-
@options[:query] ||= {}
|
15
|
-
@options[:limit] ||= 0
|
16
|
-
@options[:skip] ||= 0
|
17
|
-
end
|
18
|
-
|
19
|
-
def cursor(flags = {})
|
20
|
-
@cursor = Monga::Cursor.new(@db, @collection_name, @options, flags)
|
21
|
-
end
|
22
|
-
|
23
|
-
def explain
|
24
|
-
@options[:explain] = true
|
25
|
-
end
|
26
|
-
|
27
|
-
def hint
|
28
|
-
@options[:hint] = true
|
29
|
-
end
|
30
|
-
|
31
|
-
def sort(val)
|
32
|
-
@options[:sort] = val
|
33
|
-
end
|
34
|
-
|
35
|
-
def limit(count)
|
36
|
-
@options[:limit] = count and self
|
37
|
-
end
|
38
|
-
|
39
|
-
def skip(count)
|
40
|
-
@options[:skip] = count and self
|
41
|
-
end
|
42
|
-
|
43
|
-
def batch_size(count)
|
44
|
-
@options[:batch_size] = count and self
|
45
|
-
end
|
46
|
-
|
47
|
-
# Lazy operation execution
|
48
|
-
[:callback, :errback, :timeout].each do |meth|
|
49
|
-
class_eval <<-EOS
|
50
|
-
def #{meth}(*args)
|
51
|
-
mine! && @deferred = true unless @deferred
|
52
|
-
super
|
53
|
-
end
|
54
|
-
EOS
|
55
|
-
end
|
56
|
-
|
57
|
-
private
|
58
|
-
|
59
|
-
def mine!
|
60
|
-
docs = []
|
61
|
-
itrator = cursor.each_doc do |doc|
|
62
|
-
docs << doc
|
63
|
-
end
|
64
|
-
itrator.callback do |resp|
|
65
|
-
succeed docs
|
66
|
-
end
|
67
|
-
itrator.errback do |err|
|
68
|
-
fail err
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
data/lib/monga/response.rb
DELETED
data/spec/helpers/truncate.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
module Helpers
|
2
|
-
module Truncate
|
3
|
-
def teardown
|
4
|
-
EM.run do
|
5
|
-
RS_COLLECTION.safe_delete.callback do
|
6
|
-
RS_COLLECTION.drop_indexes.callback do
|
7
|
-
COLLECTION.safe_delete.callback do |res|
|
8
|
-
COLLECTION.drop_indexes.callback{ EM.stop }
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|