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

Race condition with collation and time series can yield incorrect query results

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 8.1.0-rc0
    • Affects Version/s: 4.9.0-alpha0
    • Component/s: None
    • None
    • Storage Execution
    • Fully Compatible
    • ALL
    • v8.0, v7.0, v6.0, v5.0
    • Hide

      NOTE: This is just a specific way the issue can manifest, collation is not the only setting that can be changed.

      Take a set of measurements with values 1, 3, and 10. Sorted lexicographically, the order is 1, 10, 3. Sorted numerically, the order is 1, 3, 10. If these measurements were prepared on a collection with the collation setting numericOrdering: false, the control field is min: 1 and max: 3.

      Suppose that after preparing the insert but before writing it, the collection is dropped and recreated with collation numericOrdering: true. The insert proceeds normally, making the control field no longer match the data. With numericOrdering: true, the bucket's control.max being 3 hides the presence of the 10 measurement. A subsequent query filtered on value: $gte: 5 would not return the correct data.

      Reproduction on master:

      Attached is a patch that will demonstrate the above case. Because validation can detect the inconsistency between the data and control fields on a bucket, the test appears to fail. To get around this, the test will print BUG-97488 if the incorrect behavior is present.

      Reproduction on 8.0:

      The same as above, but replace the fail point used in the script with hangTimeseriesInsertBeforeWrite.

      Show
      NOTE: This is just a specific way the issue can manifest, collation is not the only setting that can be changed. Take a set of measurements with values 1, 3, and 10. Sorted lexicographically, the order is 1, 10, 3. Sorted numerically, the order is 1, 3, 10. If these measurements were prepared on a collection with the collation setting numericOrdering: false, the control field is min: 1 and max: 3 . Suppose that after preparing the insert but before writing it, the collection is dropped and recreated with collation numericOrdering: true . The insert proceeds normally, making the control field no longer match the data. With numericOrdering: true , the bucket's control.max being 3 hides the presence of the 10 measurement. A subsequent query filtered on value: $gte: 5 would not return the correct data. Reproduction on master: Attached is a patch that will demonstrate the above case. Because validation can detect the inconsistency between the data and control fields on a bucket, the test appears to fail. To get around this, the test will print BUG-97488 if the incorrect behavior is present. Reproduction on 8.0: The same as above, but replace the fail point used in the script with hangTimeseriesInsertBeforeWrite .
    • Execution Team 2024-12-09, Execution Team 2024-12-23

      When performing a time series insert or update, the operation is prepared with a string comparator retrieved from the collection looked up by namespace. Later, when the write begins, the collection is looked up by namespace and locked. Between these two lookups, the collection can be dropped then re-created with different options, for example, collation settings. This results in the control fields on the target buckets being updated according to an outdated comparator, which can result in incorrect query results.

       

      EDIT: The actual bug is the window between preparing and committing a time-series insert or update for a collection to be "edited." The consequences of this bug depend on what happens during that window to the collection in question. 

            Assignee:
            malik.endsley@mongodb.com Malik Endsley
            Reporter:
            malik.endsley@mongodb.com Malik Endsley
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: