Fix spurious change streams projections test failure

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Fixed
    • Priority: Major - P3
    • 9.0.0-rc0
    • Affects Version/s: None
    • Component/s: Change streams
    • None
    • Query Execution
    • Fully Compatible
    • QE 2026-04-13
    • 200
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      BF-42445 uncovered issues with the change stream test `jstests/change_streams/oplog_rewrite/projection_changes_type.js` spuriously failing in all-feature-flags build variants after we enabled the all-databases shard targeter for v2.
      The test initially gets the resumeToken for the current cluster time, then runs some DDL & DML operations, and then uses an all-cluster change stream to collect all these events.

      There are multiple issues here:
      1. The main problem is that no change events can be returned by the test. If this is the case, the test will simply continue with an empty array of `fullEvents`. The changes in this PR add an assertion that `fullEvents` is never be empty.
      2. The test returns 0 events from the change stream because it uses a bespoke solution for determining if all events have been fetched. This solution only waits for the change stream cursor PBRT to change compared to the original resume token. This does not reliably work with v2 change streams. The changes in this PR fix the event retrieval so that it continues until at least a specific point in time is reached. This point in time is the current cluster time, taken directly before opening the change stream.

      The problem is that first event read from the change stream in question is an event returned by the config server, namely an insert into `config.databases`. v2 change streams transform this into a control event, which is handled and swallowed by the handle topology change v2 stage on mongos. The event is (intentionally) not returned to the caller. However, the event is consumed by the `AsyncResultsMerger`, which updates the high watermark token and thus the post-batch resume token (PBRT) of the change stream cursor. This way it can change compared to the original resume token, even if no events were returned to the caller.

      Fixing the problem also revealed that another test (`jstests/change_streams/oplog_rewrite/change_stream_null_existence_eq_rewrite_test.js`) was affected by the same problem. The fix from this PR re-enables the full checks from this test as well, however that test's full runtime is prohibitive, so it cannot be re-enabled as is.
      Instead, this PR splits up the checks that were previously performed by the single test (`jstests/change_streams/oplog_rewrite/change_stream_null_existence_eq_rewrite_test.js`) into 3 separate tests:

      • `jstests/change_streams/oplog_rewrite/change_stream_null_existence_eq_rewrite_comp_test.js`
      • `jstests/change_streams/oplog_rewrite/change_stream_null_existence_eq_rewrite_expr_test.js`
      • `jstests/change_streams/oplog_rewrite/change_stream_null_existence_eq_rewrite_remove_test.js`

      These tests only differ by the set of match expressions they test, but otherwise behave identically. A new library file `jstests/libs/query/change_stream_oplog_rewrite_test.js` has been added to provide the common functionalities for these tests.

      Finally, this PR removes the existing test exclusions for `jstests/change_streams/oplog_rewrite/change_stream_null_existence_eq_rewrite_test.js` that were added by SERVER-111381.

            Assignee:
            Jan Steemann
            Reporter:
            Jan Steemann
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: