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

Question about WriteConcern and Java driver concurrency using "update if current"

    XMLWordPrintableJSON

Details

    • Icon: Task Task
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • None
    • Connection Management
    • None

    Description

      Hello,

      I am attempting to implement an "update if current" strategy with the MongoDB Java driver and had a couple questions. Our system reads and writes concurrently to Mongo and it is important that we avoid dirty reads. Here are the questions I had while implementing it since it's not that trivial to test at this point:

      1) Do I need to use the requestStart and requestDone methods for the Mongo connection for this strategy? If I was not guaranteed to be using the same connection, the threads could be reading or attempting the update on either the master or slave which means there is a window of opportunity during which an update could still be accepted since the changes made by the thread on another connection have not been propagated yet. Here's an example:

      Thread_A reads message X from connection to Mongo_M
      Thread_B reads message X from connection to Mongo_S
      Thread_A updates some fields, creating message Y. Thread_A sends update details on Mongo_S.
      Thread_B updates some fields, creating message Z. Thread_B sends update details on Mongo_M.
      Mongo_S propagates data (message Y) to Mongo_M (contains message Z).

      2) If in my update in the "update if current" strategy (I am using the WriteConcern.SAFE option), is a Java exception thrown if an error condition occurs during the update?

      Any assistance would be appreciated, thanks.

      Attachments

        Activity

          People

            Unassigned Unassigned
            ccho@gilt.com Chris Cho
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: