Skip to content
This repository has been archived by the owner on Dec 2, 2020. It is now read-only.

Added support for replicaSet mongo setup #27

Merged
merged 1 commit into from Apr 2, 2013

Conversation

LemonCake
Copy link
Contributor

Add support for replicaSet mongo setups by passing in an array of server parameters in the form of [, , ] to the options hash key 'mongo-hosts'

eg.
[
['db1.domain.com', 27017, { auto_reconnect: true, slave_ok: true }
['db2.domain.com', 27017, { auto_reconnect: true, slave_ok: true }
...
]

…ver parameters in the form of [<hostname>, <port>, <options>]

eg.
[
	['db1.domain.com', 27017, { auto_reconnect: true, slave_ok: true }
	['db2.domain.com', 27017, { auto_reconnect: true, slave_ok: true }
	...
]
@jedsmallwood
Copy link

Is special handling for replica sets really needed if you just front your mongo setup with mongos? I know I have used cube out of the box with a mongo installation that I had setup with sharding and replica sets and it worked fine. With this setup I had to have mongos running, so I just pointed cube at mongos and all was well.

@LemonCake
Copy link
Contributor Author

No it's not, but it just so happens that the system I'm working with doesn't have a mongos process fronting the replicaSet. We only have one replicaSet at the moment, so we didn't feel the need to setup mongos quite yet. It's inevitable at some point we would, but I thought it'd be nice to allow for that flexibility.

@jplock
Copy link

jplock commented May 1, 2012

+1

2 similar comments
@databus23
Copy link

+1

@rookus
Copy link

rookus commented Oct 10, 2012

+1

@RandomEtc
Copy link
Collaborator

This looks pretty safe and has strong support, so I'll try to get it tidied up and merged in soon. Not sure why it won't auto-merge, so I might revise my statement when I check :)

Just as a style thing I think I'd prefer:

"mongo-hosts": [
  { "host": "xxx", "port": "xxx", "options": {} },
  { "host": "xxx", "port": "xxx", "options": {} },
  { "host": "xxx", "port": "xxx", "options": {} }
]

Rather than an array. Maybe the properties should have "mongo-" prefixes, so that the set up code for a mongodb.Server could be reused. What do folks think?

RandomEtc added a commit that referenced this pull request Apr 2, 2013
@RandomEtc RandomEtc merged commit 9ded104 into square:master Apr 2, 2013
@RandomEtc
Copy link
Collaborator

So... I finally got a chance to look at this. Thanks again for the pull request!

I dug around the mongodb driver, which we recently updated to use version 1.2.14. There's a mongodb.Db.connect(url,...) method which supports url configurations for replicasets, mongos, and more, as well as neatly encapsulates authentication and a couple of other optional steps.

Documentation of the connect function and connection string is good, so I defer to that for more explanation.

Cube 0.2.8 adds support for connection strings as "mongo-url", and addition options to Db.connect as "mongo-options" in Cube's config JSON support. This way we can defer to the mongo driver for handling all the various options and formats. I'll keep the old mongo config vars around for backwards compatibility, but you should prefer URLs from now on, they're much more convenient.

I don't have a replica set to test with - if you're still using this setup can you let me know if "mongo-url" works for you with comma separated host:port for your replica set?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
6 participants