Support read preference for a bunch of commands #139

Merged
merged 6 commits into from Dec 5, 2012

Conversation

Projects
None yet
2 participants
Contributor

nelhage commented Dec 5, 2012

This branch enables read preference in a consistent manner for a number of commands where it makes sense, notably: count, distinct, group, and mapreduce.

The wrappers for those commands, as well as DB#command all accept a :read flag in their options hashes, which is treated consistently as with Collection#find. Calling DB#command with a non-:primary read preference and a primary-only command is an error.

All named commands will also respect Collection- level read preferences.

@nelhage nelhage Revert "RUBY-514 Specify a socket when making a count query"
This doesn't work properly, since without setting a read preference on
the cursor, we won't set OP_QUERY_SLAVE_OK, and the server will refuse
the command.

This reverts commit 12186bb05873148f8aead79d341834c4b28ffef7.
2efb87f
Contributor

TylerBrock commented Dec 5, 2012

Hey Nelson. Thank you for this work. Unfortunately, as you probably know, this doesn't pass the test suite under any ruby version (see Travis for more details).

Please test before issuing these pull requests.

I'll take a look if you get it passing under all supported rubies.

nelhage added some commits Dec 5, 2012

@nelhage nelhage Support read preference on commands in a replset.
Many commands (such as count) are safe on a secondary. Support read
preferences with the same semantics as normal queries for those.
6086264
@nelhage nelhage Support read preferences for Collection#count().
Also, make Cursor#count inherit the read preference of the cursor.

Add a test case for secondary counts.
090cd7e
@nelhage nelhage Support read preferences for Collection#map_reduce. 735a0a0
@nelhage nelhage Support read preferences for Collection#group and Collection#distinct. 0a7ac58
@nelhage nelhage Support read preferences for Collection#aggregate. a183d42
Contributor

nelhage commented Dec 5, 2012

I'm sorry about that -- I (obviously) failed to run the full test suite. Fixed, and it looks green on Travis now.

Contributor

TylerBrock commented Dec 5, 2012

Cool thanks.

@TylerBrock TylerBrock added a commit that referenced this pull request Dec 5, 2012

@TylerBrock TylerBrock Merge pull request #139 from nelhage/read-preference
Support read preference for a bunch of commands
72d071c

@TylerBrock TylerBrock merged commit 72d071c into mongodb:master Dec 5, 2012

1 check passed

default The Travis build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment