Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-56514

Tests with casual consistency do not wait for the indexes to finish building

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.2 Required
    • Affects Version/s: 4.0.0, 4.2.0
    • Component/s: None
    • None
    • Fully Compatible
    • ALL
    • v4.0
    • Query Execution 2021-05-03, Query Execution 2021-05-17, Query Execution 2021-05-31, Query Execution 2021-06-14, Query Execution 2021-06-28, Query Execution 2021-07-12
    • 17

      Consider the simple test:

      const coll = db.test;
      coll.drop();
      
      coll.createIndex(/* geospatial index spec */);
      coll.insert(/* documents with geospatial data */);
      
      coll.find(/* query using $near, $nearSphere or $geoNear */).toArray();
      

      Let us try to execute this test in replica_sets_multi_stmt_txn_terminate_primary_jscore_passthrough suite. Network overrides will add w: "majority" to the createIndex command here. With these settings, the following timeline of execution is possible on MongoDB version 4.2:

      First of all, we have 3-node replica set. node2 is Primary, all other nodes are Secondaries. Test issues createIndexes command, it arrives on Primary and command waits until the index is successfully built. To satisfy "majority" write concern, command is replicated to the node1. As soon as command is replicated, createIndexes command returns with success. It does not wait for node1 to finish the index build.

      After the createIndexes command, the test suite issues a stepdown of Primary, which triggers a re-election. node1 is now selected as Primary. Note that the index build on node1 is still in progress.

      After the new Primary was selected, test issues a find command with $near, $nearSphere or $geoNear operator. All these operators require a geospatial index to work. Since the geospatial index on the current Primary node1 is still building, it is not available for querying. Since there is no geospatial index available, query fails.

      Note that starting from version 4.4 createIndexes with write concern "majority" actually waits for the index to finish building on the majority of nodes. So the affected versions are 4.2 and earlier.

        1. 1.jpg
          499 kB
          Nikita Lapkov

            Assignee:
            nikita.lapkov@mongodb.com Nikita Lapkov (Inactive)
            Reporter:
            nikita.lapkov@mongodb.com Nikita Lapkov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: