How to force moped to read from Mongo secondary replica set member running with a delay

726 Views Asked by At

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

1

There are 1 best solutions below

0
Vladimir Carballo On

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.