We have a cluster built with 3 shards.
We got different query results between using primary and secondary.
mongos> db.getMongo().setReadPref('primary') mongos> db.stats_ads.find({ "start_time": ISODate("2017-10-17T15:00:00Z"), "campaign_id": 1502, "creative_id": "Gh5BZVRZ", "placement_id": "6sbp2O-2" }) { "_id" : ObjectId("59e61b4da332ce97955561a4"), "adgroup_id" : "6sGebf9Y", "creative_id" : "Gh5BZVRZ", "granularity" : "DAY", "placement_id" : "6sbp2O-2", "start_time" : ISODate("2017-10-17T15:00:00Z"), "advertiser_account_id" : 1694, "advertiser_id" : 7, "campaign_id" : 1502, "publisher_account_id" : 66790, "publisher_id" : 1969, "media_id" : 122787, "metrics" : { "view" : 37 } }
mongos> db.getMongo().setReadPref('secondaryPreferred') mongos> db.stats_ads.find({ "start_time": ISODate("2017-10-17T15:00:00Z"), "campaign_id": 1502, "creative_id": "Gh5BZVRZ", "placement_id": "6sbp2O-2" }) { "_id" : ObjectId("59e61b4da332ce97955561a4"), "adgroup_id" : "6sGebf9Y", "creative_id" : "Gh5BZVRZ", "granularity" : "DAY", "placement_id" : "6sbp2O-2", "start_time" : ISODate("2017-10-17T15:00:00Z"), "advertiser_account_id" : 1694, "advertiser_id" : 7, "campaign_id" : 1502, "publisher_account_id" : 66790, "publisher_id" : 1969, "media_id" : 122787, "metrics" : { "view" : 17 } } { "_id" : ObjectId("59e61b4da332ce97955561a4"), "adgroup_id" : "6sGebf9Y", "creative_id" : "Gh5BZVRZ", "granularity" : "DAY", "placement_id" : "6sbp2O-2", "start_time" : ISODate("2017-10-17T15:00:00Z"), "advertiser_account_id" : 1694, "advertiser_id" : 7, "campaign_id" : 1502, "publisher_account_id" : 66790, "publisher_id" : 1969, "media_id" : 122787, "metrics" : { "view" : 37 } }
It's very weird, 2 documents with the same ObjectId. So I queried every single replica set.
rs0:PRIMARY> db.stats_ads.find({ "start_time": ISODate("2017-10-17T15:00:00Z"), "campaign_id": 1502, "creative_id": "Gh5BZVRZ", "placement_id": "6sbp2O-2" }) (no results)
rs1:PRIMARY> db.stats_ads.find({ "start_time": ISODate("2017-10-17T15:00:00Z"), "campaign_id": 1502, "creative_id": "Gh5BZVRZ", "placement_id": "6sbp2O-2" }) { "_id" : ObjectId("59e61b4da332ce97955561a4"), "adgroup_id" : "6sGebf9Y", "creative_id" : "Gh5BZVRZ", "granularity" : "DAY", "placement_id" : "6sbp2O-2", "start_time" : ISODate("2017-10-17T15:00:00Z"), "advertiser_account_id" : 1694, "advertiser_id" : 7, "campaign_id" : 1502, "publisher_account_id" : 66790, "publisher_id" : 1969, "media_id" : 122787, "metrics" : { "view" : 17 } }
rs2:PRIMARY> db.stats_ads.find({ "start_time": ISODate("2017-10-17T15:00:00Z"), "campaign_id": 1502, "creative_id": "Gh5BZVRZ", "placement_id": "6sbp2O-2" }) { "_id" : ObjectId("59e61b4da332ce97955561a4"), "adgroup_id" : "6sGebf9Y", "creative_id" : "Gh5BZVRZ", "granularity" : "DAY", "placement_id" : "6sbp2O-2", "start_time" : ISODate("2017-10-17T15:00:00Z"), "advertiser_account_id" : 1694, "advertiser_id" : 7, "campaign_id" : 1502, "publisher_account_id" : 66790, "publisher_id" : 1969, "media_id" : 122787, "metrics" : { "view" : 37 } }
Both rs1 and rs2 have the same (I mean the same ObjectId) document, but have different non-key attributes values.
I guess it is a result of chunk migration. The new one has been moved/created, but the old one has not been deleted. Or, they have their own version number, which not work under secondaryPreferred read preference.
Inconsistent query results between primary and secondary is a critical issue for us. Any suggestion?
- duplicates
-
SERVER-5931 Secondary reads in sharded clusters need stronger consistency
- Closed