[JAVA-647] stale read issue in a ReplicaSet setup Created: 18/Sep/12  Updated: 18/Sep/12  Resolved: 18/Sep/12

Status: Closed
Project: Java Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Paul Kim Assignee: Barrie Segal
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

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
}


Issue Links:
Duplicate

 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)

{ return room; }

else

{ room = findRoomByName(name); }

return room;
}

insertRoomIntoDB(name) {
Room room = null;
try

{ // Insert into db room = db.rooms.insert(name); return room; }

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



 Comments   
Comment by Paul Kim [ 18/Sep/12 ]

Oops, please close this. This was supposed to be created in Commercial Support

Generated at Thu Feb 08 08:52:45 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.