Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-647

stale read issue in a ReplicaSet setup

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None

    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

      Attachments

        Activity

          People

            barrie Barrie Segal
            paul.kim@funsockets.com Paul Kim
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: