Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add rs.slaveOk to run before the getDBs call #446

Merged
merged 1 commit into from
Sep 12, 2018

Conversation

TomRitserveldt
Copy link
Contributor

otherwise puppet runs fail on the slaves in a multi node replica mongo setup.
how this occurs from what I've been able to see:

provision 3 vm's:

  • on the first vm the puppet runs succeeds, installing and configuring a mongodb with a replicaset and defining and setting up the required databases on that node. this node becomes the master.
  • on the second vm during the puppet runs, puppet fetches a list of databases on the current mongo (replicaset),which returns the error:

Failed to apply catalog: Could not evaluate MongoDB shell command: printjson(db.getMongo().getDBs())

  • the same occurs on the 3rd node, since this is a slave as well.

to fix this we must pass the rs.slaveOk() command before the printjson(db.getMongo().getDBs()), in order to allow the current connection to allow read operations to run on secondary members.
which I hope to solve with this pull request, if there are cleaner/better ways to fix this issue, I'm open to suggestions.

@rnelson0
Copy link
Sponsor Member

rnelson0 commented Mar 6, 2018

Is it possible to add a test for the behavior you're seeing with the 2nd and 3rd replicas? Otherwise, the code itself looks ok, but I don't have experience with mongoDB to know if it's an appropriate solution.

@rnelson0
Copy link
Sponsor Member

rnelson0 commented Mar 6, 2018

A quick google shows that replica sets replace master-slave, and the latter is deprecated starting in MongoDB 3.6. Again, I don't have experience with MongoDB, but it seems like maybe there are other solutions here, perhaps dependent on the version in use.

@bastelfreak bastelfreak added the needs-feedback Further information is requested label Mar 6, 2018
@bastelfreak
Copy link
Member

Hoi @TomRitserveldt, thanks for the PR! Can you take a look at the comments from @rnelson0 ?

@TomRitserveldt
Copy link
Contributor Author

TomRitserveldt commented Mar 7, 2018

Yes, I'm currently looking into some alternative ways to get around or fix this issue.
Some extra info regarding @rnelson0 comments:
Yes, replica sets are the desired way to go, but that is also what I'm already using.
With a replicaset setup you still have the primary and secondary concept, which requires you to use rs.slaveOk() to do read operations on the secondary nodes.
rs.slaveOk() also seems to have no impact at all when used on the primary node from what I've seen / tested.

@Dharmender-Singh
Copy link

Dharmender-Singh commented Jun 6, 2018

@TomRitserveldt : Have you setup the replication with Auth Enabled or Disabled ? I am trying to setup with Auth enabled but getting following error :

Error: Failed to apply catalog: Could not evaluate MongoDB shell command: load('/root/.mongorc.js'); printjson(db.getMongo().getDBs())

@TomRitserveldt
Copy link
Contributor Author

@Dharmender-Singh Sorry no I am setting it up without auth enabled.

@TomRitserveldt TomRitserveldt force-pushed the feature/slaveok_replicaset branch 3 times, most recently from 5bc5a34 to b87a926 Compare June 8, 2018 05:49
…the slaves in a multi node replica mongo setup.
@TomRitserveldt
Copy link
Contributor Author

TomRitserveldt commented Sep 5, 2018

Any chance this could still get merged?
My earlier comment should have answered nelson's concern regarding if there's a better way to go about this, with the included link/reference to the mongodb docs there.

@vStone vStone merged commit c2066d5 into voxpupuli:master Sep 12, 2018
@ekohl ekohl removed the needs-feedback Further information is requested label Oct 5, 2018
guikcd added a commit to Oxalide/puppetlabs-mongodb that referenced this pull request Feb 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants