Skip to content

Commit 9d8ed10

Browse files
committed
History. RS Doc updates. Write concern docs.
1 parent 1a14156 commit 9d8ed10

File tree

4 files changed

+48
-8
lines changed

4 files changed

+48
-8
lines changed

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ task :ydoc do
169169
require File.join(File.dirname(__FILE__), 'lib', 'mongo')
170170
out = File.join('ydoc', Mongo::VERSION)
171171
FileUtils.rm_rf('ydoc')
172-
system "yardoc lib/**/*.rb lib/mongo/**/*.rb lib/bson/**/*.rb -e yard/yard_ext.rb -p yard/templates -o #{out} --title MongoRuby-#{Mongo::VERSION} --files docs/TUTORIAL.md,docs/GridFS.md,docs/FAQ.md,docs/REPLICA_SETS.md,docs/HISTORY.md,docs/CREDITS.md,docs/1.0_UPGRADE.md"
172+
system "yardoc lib/**/*.rb lib/mongo/**/*.rb lib/bson/**/*.rb -e yard/yard_ext.rb -p yard/templates -o #{out} --title MongoRuby-#{Mongo::VERSION} --files docs/TUTORIAL.md,docs/GridFS.md,docs/FAQ.md,docs/REPLICA_SETS.md,docs/WRITE_CONCERN.md,docs/HISTORY.md,docs/CREDITS.md,docs/1.0_UPGRADE.md"
173173
end
174174

175175
namespace :gem do

docs/HISTORY.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# MongoDB Ruby Driver History
22

3+
### 1.1.3
4+
2010-11-29
5+
6+
* Distributed reads for replica set secondaries. See /docs/examples/replica_set.rb and
7+
http://api.mongodb.org/ruby/current/file.REPLICA_SETS.html for details.
8+
* Note: when connecting to a replica set, you must use Connection#multi.
9+
* Cursor#count takes optional skip and limit
10+
* Collection#ensure_index for caching index creation calls
11+
* Collection#update and Collection#remove now return error object when using safe mode
12+
* Important fix for int/long serialization on bug introduced in 1.0.9
13+
* Numerous tweaks and bug fixes.
14+
315
### 1.1.2
416
2010-11-4
517

docs/REPLICA_SETS.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The driver will attempt to connect to a master node and, when found, will replac
1414

1515
### Read slaves
1616

17-
If you want to read from a seconday node, you can pass :read_secondary => true.
17+
If you want to read from a seconday node, you can pass :read_secondary => true to Connection#multi.
1818

1919
@connection = Connection.multi([['n1.mydb.net', 27017], ['n2.mydb.net', 27017], ['n3.mydb.net', 27017]],
2020
:read_secondary => true)
@@ -23,20 +23,21 @@ A random secondary will be chosen to be read from. In a typical multi-process Ru
2323

2424
### Connection Failures
2525

26-
Imagine that our master node goes offline. How will the driver respond?
26+
Imagine that either the master node or one of the read nodes goes offline. How will the driver respond?
2727

28-
At first, the driver will try to send operations to what was the master node. These operations will fail, and the driver will raise a *ConnectionFailure* exception. It then becomes the client's responsibility to decide how to handle this.
28+
If any read operation fails, the driver will raise a *ConnectionFailure* exception. It then becomes the client's responsibility to decide how to handle this.
2929

3030
If the client decides to retry, it's not guaranteed that another member of the replica set will have been promoted to master right away, so it's still possible that the driver will raise another *ConnectionFailure*. However, once a member has been promoted to master, typically within a few seconds, subsequent operations will succeed.
3131

3232
The driver will essentially cycle through all known seed addresses until a node identifies itself as master.
3333

3434
### Recovery
3535

36-
Driver users may wish to wrap their database calls with failure recovery code. Here's one possibility:
36+
Driver users may wish to wrap their database calls with failure recovery code. Here's one possibility, which will attempt to connection
37+
every half second and time out after thirty seconds.
3738

3839
# Ensure retry upon failure
39-
def rescue_connection_failure(max_retries=5)
40+
def rescue_connection_failure(max_retries=60)
4041
success = false
4142
retries = 0
4243
while !success
@@ -46,7 +47,7 @@ Driver users may wish to wrap their database calls with failure recovery code. H
4647
rescue Mongo::ConnectionFailure => ex
4748
retries += 1
4849
raise ex if retries >= max_retries
49-
sleep(1)
50+
sleep(0.5)
5051
end
5152
end
5253
end
@@ -74,4 +75,3 @@ Make sure you have a replica set running on localhost before trying to run these
7475

7576
* [Replica Sets](http://www.mongodb.org/display/DOCS/Replica+Set+Configuration)
7677
* [Replics Set Configuration](http://www.mongodb.org/display/DOCS/Replica+Set+Configuration)
77-

docs/WRITE_CONCERN.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Write Concern in Ruby
2+
3+
## Setting the write concern
4+
5+
Write concern is set using the `:safe` option. There are several possible options:
6+
7+
@collection.save({:doc => 'foo'}, :safe => true)
8+
@collection.save({:doc => 'foo'}, :safe => {:w => 2})
9+
@collection.save({:doc => 'foo'}, :safe => {:w => 2, :wtimeout => 200})
10+
@collection.save({:doc => 'foo'}, :safe => {:w => 2, :wtimeout => 200, :fsync => true})
11+
12+
The first, `true`, simply indicates that we should request a response from the server to ensure that to errors have occurred. The second, `{:w => 2}`forces the server to wait until at least two servers have recorded the write. The third does the same but will time out if the replication can't be completed in 200 milliseconds. The fourth forces an fsync on each server being written to (note: this option is rarely necessary and will have a dramaticly negative effect on performance).
13+
14+
## Write concern inheritance
15+
16+
The Ruby driver allows you to set write concern on each of four levels: the connection, database, collection, and write operation.
17+
Objects will inherit the default write concern from their parents. Thus, if you set a write concern of `{:w => 1}` when creating
18+
a new connection, then all databases and collections created from that connection will inherit the same setting. See this code example:
19+
20+
@con = Mongo::Connection.new('localhost', 27017, :safe => {:w => 2})
21+
@db = @con['test']
22+
@collection = @db['foo']
23+
@collection.save({:name => 'foo'})
24+
25+
@collection.save({:name => 'bar'}, :safe => false)
26+
27+
Here, the first call to Collection#save will use the inherited write concern, `{:w => 2}`. But notice that the second call
28+
to Collection#save overrides this setting.

0 commit comments

Comments
 (0)