2

I have a ruby on rails based application. Objective is to read from a mongo replica set member that is:

  1. secondary
  2. delayed by x seconds
  3. priority: 0
  4. Placed in a separate data center.

DETAILS: I have a production cluster running that uses mongo replica set.

Previously, It was noticed that sometimes Moped reads from other secondaries with high latency(remotely present in other data centers) and not from the secondary desired. To resolve the same problem, we have added a delay on remote secondaries.

Now I have a fresh analytics application that uses mongoid. Is there a way I could FORCE read from SPECIFIC secondary using mongoid or any other gem? i.e. Is there a way to override the Auto Discovery feature in Mongoid / Moped / MongoDB ? Please suggest

Swapnil jaiswal
  • 154
  • 1
  • 10
wayne
  • 393
  • 2
  • 13
  • 1
    I also faced a similar issue. We had a production cluster in mongo replicaset. We also had a DR cluster linked to the same replicaset. One of the members of DR was delayed member but other was in sync. In the production cluster we were using Ruby / Mongo id config. Here we specifically mentioned the hostnames in mongoid.yml. But after some days we noticed Moped was sending queries to the secondary that was NOT mentioned in the mongoid.yml. We introduced the delay in secondary to recitify the issue. Mongoid version 4.x – Swapnil jaiswal Apr 01 '16 at 12:17

1 Answers1

2

You can use tag_sets. In the Mongoid config documentation you can see that, under the 'read' setting, you can specify the tag_set assigned to the secondary node you want to explicitly read from:

# Change the default read preference. Valid options for mode are: :secondary,
# :secondary_preferred, :primary, :primary_preferred, :nearest
# (default: primary)
    read: 
        mode: :secondary_preferred
        tag_sets:
            - use: web

The way you configure tag_sets in a Replica set is documented here

I hope this can help you. This is a very advanced and powerful feature not everybody know how to use.