Connecting Mongodb BI connector to slave in replica set

398 views
Skip to first unread message

BSR

unread,
Aug 18, 2017, 8:16:19 PM8/18/17
to mongodb-user
Hi,

I have 3 node replica set setup , with one of the node purpose is reporting 
I have recently installed mongodb Bi connector on server zzzzz which is a replica(priority zero)
when i execute queries by connecting to mysqld , the queries are being directed to primary server of replica set instead of using the read replica copy

please suggest on how to make queries coming through mysqld hit only read replica copy 

rs.conf() output below

{
    "_id" : "s1-rs1",
    "version" : 9,
    "protocolVersion" : NumberLong(1),
    "members" : [ 
        {
            "_id" : 1,
            "host" : "xxxxx",
            "arbiterOnly" : false,
            "buildIndexes" : true,
            "hidden" : false,
            "priority" : 1.0,
            "tags" : {
                "use" : "production"
            },
            "slaveDelay" : NumberLong(0),
            "votes" : 1
        }, 
        {
            "_id" : 2,
            "host" : "yyy",
            "arbiterOnly" : false,
            "buildIndexes" : true,
            "hidden" : false,
            "priority" : 1.0,
            "tags" : {
                "use" : "production"
            },
            "slaveDelay" : NumberLong(0),
            "votes" : 1
        }, 
        {
            "_id" : 3,
            "host" : "zzzzz",
            "arbiterOnly" : false,
            "buildIndexes" : true,
            "hidden" : false,
            "priority" : 0.0,
            "tags" : {
                "use" : "reporting"
            },
            "slaveDelay" : NumberLong(0),
            "votes" : 1
        }
    ],
    "settings" : {
        "chainingAllowed" : true,
        "heartbeatIntervalMillis" : 2000,
        "heartbeatTimeoutSecs" : 10,
        "electionTimeoutMillis" : 10000,
        "catchUpTimeoutMillis" : 2000,
        "getLastErrorModes" : {},
        "getLastErrorDefaults" : {
            "w" : 1,
            "wtimeout" : 0
        },
        "replicaSetId" : ObjectId("58742e1ed639ab53a840ba48")
    }
}

Wan Bachtiar

unread,
Aug 23, 2017, 8:04:08 PM8/23/17
to mongodb-user

please suggest on how to make queries coming through mysqld hit only read replica copy

Hi,

MongoDB Connector for BI mongosqld provides an option —mongo-uri to specify connection URI which supports Read Preference Options for readPreference and/or readPreferenceTags

Worth mentioning that MongoDB Connector for BI is available with MongoDB Enterprise v3.2+. If your company or organisation already has a commercial support subscription and you have further questions I would recommend to open a case in the Commercial Support Portal including with the following information:

  • MongoDB Connector for BI version that you’re using
  • The options that you specify to execute mongosqld

Alternatively, if you are evaluating MongoDB Enterprise please feel free to send me a private message with your contact details, I can request a MongoDB Account Executive to contact you.

Regards,
Wan.

BSR

unread,
Aug 24, 2017, 5:11:04 PM8/24/17
to mongodb-user
we are evaluating  mongodb BI connector in our Dev enviroment ,and facing the below issue , it would be great if you can help us 

 I am using below URI option in mongosqld.conf file so that all reads point to mong02 which has tags "use:reporting"  (mentioned rs.conf() output below):
mongodb:
 net:

when i try connecting to mongosqld using mysql client i am getting below error: 

"ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0"

but if use primaryPreferred like below i am able to connect from mysql client, but the queries are not being directed to mong02(secondary) instead they are running on primary machine (mong04) so some how read preference tags is not playing a role here

mongodb:
 net:

If i totally remove readPreferenceTags option , i am having no issues in connecting but my requirement is to point all reads from BI connector to only Mong02 machine (which is  a secondary with priority 0)


/* 1 */
{
    "_id" : "s1-rs1",
    "version" : 23,
    "protocolVersion" : NumberLong(1),
    "members" : [ 
        {
            "_id" : 1,
            "host" : "mong03.sub.biz:27017",
            "arbiterOnly" : false,
            "buildIndexes" : true,
            "hidden" : false,
            "priority" : 1.0,
            "tags" : {
                "use" : "production"
            },
            "slaveDelay" : NumberLong(0),
            "votes" : 1
        }, 
        {
            "_id" : 2,
            "host" : "mong04.sub.biz:27017",
            "arbiterOnly" : false,
            "buildIndexes" : true,
            "hidden" : false,
            "priority" : 1.0,
            "tags" : {
                "use" : "secondary2"
            },
            "slaveDelay" : NumberLong(0),
            "votes" : 1
        }, 
        {
            "_id" : 3,
            "host" : "mong02.sub.biz:27017",
            "arbiterOnly" : false,
            "buildIndexes" : true,
            "hidden" : false,
            "priority" : 0.0,
            "tags" : {
                "use" : "reporting"
            },
            "slaveDelay" : NumberLong(0),
            "votes" : 1
        }
    ],
    "settings" : {
        "chainingAllowed" : true,
        "heartbeatIntervalMillis" : 2000,
        "heartbeatTimeoutSecs" : 10,
        "electionTimeoutMillis" : 10000,
        "catchUpTimeoutMillis" : 2000,
        "getLastErrorModes" : {},
        "getLastErrorDefaults" : {
            "w" : 1,
            "wtimeout" : 0
        },
        "replicaSetId" : ObjectId("58742e1ed639ab53a840ba48")
    }
}

Craig Wilson

unread,
Aug 24, 2017, 8:03:55 PM8/24/17
to mongodb-user
Hi BSR,

We had a bug related to readPreferenceTags. It has been fixed as of yesterday and will be in a 2.2.1 patch release. I don't have an ETA on that. In the meantime, continue testing without tags and we should have 2.2.1 out before you need it for production. If you still must only connect to the single box during testing, then just connect directly to it. 

Sorry 'bout the bug,
Craig

BSR

unread,
Aug 25, 2017, 12:48:27 AM8/25/17
to mongodb-user
Hi,

thanks for the quick response, how should i connect it to it directly?

when i use uri as below  the queries are still going to primary(mong04) instead of hitting mong02

Craig Wilson

unread,
Aug 25, 2017, 10:56:27 AM8/25/17
to mongodb-user
Right... we'll detect that it's a replica set and discover all the other members. Try this:

mongodb://mong02.sub.biz:27017/?connect=single


Also looks like we will be releasing a 2.2.1 patch sometime next week provided our testing goes ok.

B.S.Reddy

unread,
Aug 25, 2017, 12:00:00 PM8/25/17
to mongodb-user
thanks craig  for your quick responses 
Reply all
Reply to author
Forward
0 new messages