|
I tried using replica sets with tagging and then to redirect reads from client to appropriate secondary with given tags.
I followed instructions given http://docs.mongodb.org/manual/tutorial/configure-replica-set-tag-sets/ and http://docs.mongodb.org/ecosystem/drivers/java-replica-set-semantics/
I have tag secondary:0 and secondary:1 - and want my clients to load-balance between those two secondary nodes when reading data (query + aggregations)
but I always get following error
com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=secondary: [TagSet{[Tag{name='secondary', value='0'}]}]}. Client view of cluster state is {type=REPLICA_SET, servers=[{address=host3:27019, type=REPLICA_SET_SECONDARY, TagSet{[Tag{name='test', value='BsonString{value='a'}'}, Tag{name='secondary', value='BsonString{value='0'}'}]}, roundTripTime=1.8 ms, state=CONNECTED}, {address=host2:27019, type=REPLICA_SET_SECONDARY, TagSet{[Tag{name='test', value='BsonString{value='b'}'}, Tag{name='secondary', value='BsonString{value='0'}'}]}, roundTripTime=1.8 ms, state=CONNECTED}, {address=host1:27019, type=REPLICA_SET_PRIMARY, TagSet{[Tag{name='secondary', value='BsonString{value='a'}'}]}, roundTripTime=1.7 ms, state=CONNECTED}]
|
Here is my rs.conf and rs.status
rs0:PRIMARY> rs.status()
|
{
|
"set" : "rs0",
|
"date" : ISODate("2015-03-04T19:28:57.182Z"),
|
"myState" : 1,
|
"members" : [
|
{
|
"_id" : 0,
|
"name" : "host1:27019",
|
"health" : 1,
|
"state" : 1,
|
"stateStr" : "PRIMARY",
|
"uptime" : 42569,
|
"optime" : Timestamp(1425485080, 1),
|
"optimeDate" : ISODate("2015-03-04T16:04:40Z"),
|
"electionTime" : Timestamp(1425454776, 1),
|
"electionDate" : ISODate("2015-03-04T07:39:36Z"),
|
"configVersion" : 8,
|
"self" : true
|
},
|
{
|
"_id" : 1,
|
"name" : "host2:27019",
|
"health" : 1,
|
"state" : 2,
|
"stateStr" : "SECONDARY",
|
"uptime" : 42560,
|
"optime" : Timestamp(1425485080, 1),
|
"optimeDate" : ISODate("2015-03-04T16:04:40Z"),
|
"lastHeartbeat" : ISODate("2015-03-04T19:28:55.471Z"),
|
"lastHeartbeatRecv" : ISODate("2015-03-04T19:28:56.631Z"),
|
"pingMs" : 0,
|
"syncingTo" : "host1:27019",
|
"configVersion" : 8
|
},
|
{
|
"_id" : 2,
|
"name" : "host3:27019",
|
"health" : 1,
|
"state" : 2,
|
"stateStr" : "SECONDARY",
|
"uptime" : 42552,
|
"optime" : Timestamp(1425485080, 1),
|
"optimeDate" : ISODate("2015-03-04T16:04:40Z"),
|
"lastHeartbeat" : ISODate("2015-03-04T19:28:55.661Z"),
|
"lastHeartbeatRecv" : ISODate("2015-03-04T19:28:55.343Z"),
|
"pingMs" : 0,
|
"syncingTo" : "host2:27019",
|
"configVersion" : 8
|
}
|
],
|
"ok" : 1
|
}
|
rs0:PRIMARY> rs.conf();
|
{
|
"_id" : "rs0",
|
"version" : 8,
|
"members" : [
|
{
|
"_id" : 0,
|
"host" : "host1:27019",
|
"arbiterOnly" : false,
|
"buildIndexes" : true,
|
"hidden" : false,
|
"priority" : 1,
|
"tags" : {
|
"secondary" : "a"
|
},
|
"slaveDelay" : 0,
|
"votes" : 1
|
},
|
{
|
"_id" : 1,
|
"host" : "host2:27019",
|
"arbiterOnly" : false,
|
"buildIndexes" : true,
|
"hidden" : false,
|
"priority" : 1,
|
"tags" : {
|
"secondary" : "0",
|
"test" : "a"
|
},
|
"slaveDelay" : 0,
|
"votes" : 1
|
},
|
{
|
"_id" : 2,
|
"host" : "host3:27019",
|
"arbiterOnly" : false,
|
"buildIndexes" : true,
|
"hidden" : false,
|
"priority" : 1,
|
"tags" : {
|
"secondary" : "0",
|
"test" : "b"rs0:PRIMARY> rs.status()
|
{
|
"set" : "rs0",
|
"date" : ISODate("2015-03-04T19:28:57.182Z"),
|
"myState" : 1,
|
"members" : [
|
{
|
"_id" : 0,
|
"name" : "host1:27019",
|
"health" : 1,
|
"state" : 1,
|
"stateStr" : "PRIMARY",
|
"uptime" : 42569,
|
"optime" : Timestamp(1425485080, 1),
|
"optimeDate" : ISODate("2015-03-04T16:04:40Z"),
|
"electionTime" : Timestamp(1425454776, 1),
|
"electionDate" : ISODate("2015-03-04T07:39:36Z"),
|
"configVersion" : 8,
|
"self" : true
|
},
|
{
|
"_id" : 1,
|
"name" : "host2:27019",
|
"health" : 1,
|
"state" : 2,
|
"stateStr" : "SECONDARY",
|
"uptime" : 42560,
|
"optime" : Timestamp(1425485080, 1),
|
"optimeDate" : ISODate("2015-03-04T16:04:40Z"),
|
"lastHeartbeat" : ISODate("2015-03-04T19:28:55.471Z"),
|
"lastHeartbeatRecv" : ISODate("2015-03-04T19:28:56.631Z"),
|
"pingMs" : 0,
|
"syncingTo" : "host1:27019",
|
"configVersion" : 8
|
},
|
{
|
"_id" : 2,
|
"name" : "host3:27019",
|
"health" : 1,
|
"state" : 2,
|
"stateStr" : "SECONDARY",
|
"uptime" : 42552,
|
"optime" : Timestamp(1425485080, 1),
|
"optimeDate" : ISODate("2015-03-04T16:04:40Z"),
|
"lastHeartbeat" : ISODate("2015-03-04T19:28:55.661Z"),
|
"lastHeartbeatRecv" : ISODate("2015-03-04T19:28:55.343Z"),
|
"pingMs" : 0,
|
"syncingTo" : "host2:27019",
|
"configVersion" : 8
|
}
|
],
|
"ok" : 1
|
}
|
rs0:PRIMARY> rs.conf();
|
{
|
"_id" : "rs0",
|
"version" : 8,
|
"members" : [
|
{
|
"_id" : 0,
|
"host" : "host1:27019",
|
"arbiterOnly" : false,
|
"buildIndexes" : true,
|
"hidden" : false,
|
"priority" : 1,
|
"tags" : {
|
"secondary" : "a"
|
},
|
"slaveDelay" : 0,
|
"votes" : 1
|
},
|
{
|
"_id" : 1,
|
"host" : "host2:27019",
|
"arbiterOnly" : false,
|
"buildIndexes" : true,
|
"hidden" : false,
|
"priority" : 1,
|
"tags" : {
|
"secondary" : "0",
|
"test" : "a"
|
},
|
"slaveDelay" : 0,
|
"votes" : 1
|
},
|
{
|
"_id" : 2,
|
"host" : "host3:27019",
|
"arbiterOnly" : false,
|
"buildIndexes" : true,
|
"hidden" : false,
|
"priority" : 1,
|
"tags" : {
|
"secondary" : "0",
|
"test" : "b"
|
},
|
"slaveDelay" : 0,
|
"votes" : 1
|
}
|
],
|
"settings" : {
|
"chainingAllowed" : true,
|
"heartbeatTimeoutSecs" : 10,
|
"getLastErrorModes" : {
|
|
},
|
"getLastErrorDefaults" : {
|
"w" : 1,
|
"wtimeout" : 0
|
}
|
}
|
}
|
rs0:PRIMARY>
|
|
},
|
"slaveDelay" : 0,
|
"votes" : 1
|
}
|
],
|
"settings" : {
|
"chainingAllowed" : true,
|
"heartbeatTimeoutSecs" : 10,
|
"getLastErrorModes" : {
|
|
},
|
"getLastErrorDefaults" : {
|
"w" : 1,
|
"wtimeout" : 0
|
}
|
}
|
}
|
rs0:PRIMARY>
|
|