Details
-
Bug
-
Resolution: Duplicate
-
Major - P3
-
None
-
None
-
None
-
None
-
Ubuntu 10.04
ReplicaSet: 1 Primary and 2 Secondary
Java Driver version: 2.9.0
Driver Options: slaveOk = true, WriteConcern=WriteConcern.Safe
gokoSet:PRIMARY> db.serverBuildInfo()
{
"version" : "1.8.5",
"gitVersion" : "403c8dadcd56f68dcbe06013ecbfac67b32a22ac",
"sysInfo" : "Linux ip-10-110-9-236 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_41",
"bits" : 64,
"debug" : false,
"maxBsonObjectSize" : 16777216,
"ok" : 1
}
Ubuntu 10.04 ReplicaSet: 1 Primary and 2 Secondary Java Driver version: 2.9.0 Driver Options: slaveOk = true, WriteConcern=WriteConcern.Safe gokoSet:PRIMARY> db.serverBuildInfo() { "version" : "1.8.5", "gitVersion" : "403c8dadcd56f68dcbe06013ecbfac67b32a22ac", "sysInfo" : "Linux ip-10-110-9-236 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_41", "bits" : 64, "debug" : false, "maxBsonObjectSize" : 16777216, "ok" : 1 }
Description
We are having stale read issue in a ReplicaSet setup. The use cases are below. What is the best way to resolve these issues?
First, some info with our setup. We have multiple servers which are all talking to mongo.
ReplicaSet: 1 Primary and 2 Secondary
Java Driver version: 2.9.0
Driver Options: slaveOk = true, WriteConcern=WriteConcern.Safe
gokoSet:PRIMARY> db.serverBuildInfo()
{
"version" : "1.8.5",
"gitVersion" : "403c8dadcd56f68dcbe06013ecbfac67b32a22ac",
"sysInfo" : "Linux ip-10-110-9-236 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_41",
"bits" : 64,
"debug" : false,
"maxBsonObjectSize" : 16777216,
"ok" : 1
}
Case#1 - When two of the same API calls execute very close to each other. Here's some pseudo code.
createRoomApi(name) {
Room room = insertRoomIntoDB(name);
if(room != null)
else
{ room = findRoomByName(name); } return room;
}
insertRoomIntoDB(name) {
Room room = null;
try
catch (MongoException.DuplicateKey)
{ log("duplicate room name: " + name); } // if MongoException.DuplicateKey, returns null
return room;
}
API call #1 - CreateRoom("MyRoom")
Room object returned - new room created successfully
API call #2 - CreateRoom("MyRoom")
No room object returned - Room was created in call #1, but cannot find room because it tried to read from a slave and inserted room is not replicated yet.
Case #2 - We have a transactional operation within the one API call.
ObjectA is parent of ObjectB is a parent of ObjectC
Insert Object A
Insert Object B
Insert Object C
/**
more code
**/
Look up ObjectA and set ObjectB as child
Look up ObjectB and set ObjectA as parent
Look up ObjectB and set ObjectC as child
Look up ObjectC and set ObjectB as parent