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

Scala failover test leads to a write concern exception

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:

      Hi!

      I set up a test with the 4.2.3 Scala driver and Atlas. The test is a straightforward one, I increment a field recursively and then start a Failover test on Atlas. The recursive incrementation continues throughout the test. In my test case, I set the recursion to go through the incrementation 200 000 times as my experimentation showed that to be long enough to last through the entire Failover test.

      My expectation was that when the primary election is underway, the driver would pause operation during that time and resume once a primary was again available. However, this didn’t occur as the driver threw an exception and interrupted processing. The exception was a MongoWriteConcernException. The connection had retryWrites=true&w=majority set.

      There’s not a whole lot in the documentation about how to handle Failover. I was expecting the driver to handle the election without needing exception handling in our own code. Is this assumption correct? If it is, there seems to be an issue with the driver.

      Below is the relevant code from the test:

      {{}}

      val testCollection = database.getCollection("test")
      
      private def mongoTest(userId: String, curr: Int, times: Int) = {
        if (curr >= times) Future(Ok("Complete"))
        else incrementMongoTestField(userId) flatMap { _ => 
          mongoTest(userId, curr+1, times)
        }
      }
      
      def incrementMongoTestField(userId: String) : Future[UpdateResult] = {
        val query = Document("userId" -> userId)
        val update = Document("$inc" -> Document("mongoTestField" -> 1))
        testCollection.updateOne(query, update).toFuture
      }

      {{}}

            Assignee:
            ross@mongodb.com Ross Lawley
            Reporter:
            valtteri.pirttila@traplightgames.com Valtteri Pirttilä
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: