-
Type:
Task
-
Resolution: Fixed
-
Priority:
Major - P3
-
Affects Version/s: None
-
Component/s: None
-
Query Execution
-
Fully Compatible
-
QE 2026-03-30, QE 2026-03-16, QE 2026-04-13
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Summary
SERVER-111381 implemented AllDatabasesChangeStreamShardTargeterImpl with C++ unit tests and JS smoke tests, but lacks white-box integration tests that verify observable shard-targeting behavior: which shards have open cursors after each lifecycle event, and that placement history is consulted at the right times.
Approach
Two jstest files using two observability mechanisms:
- *$currentOp with
Unknown macro: {Unknown macro}
* — inspects which shards have open change stream cursors. Cursors identified via unique comment per test case.
- Log offset snapshots — before each operation, snapshot checkLog.getGlobalLog(mongos).length. After the operation, search only the new log entries for expected LOGV2 IDs and attributes. This avoids false matches from prior test steps.
Shared fixture: A single ShardingTest created in before(). beforeEach()/afterEach() only clean up databases/collections. Verbose query logging on all nodes via logComponentVerbosity: {query: {verbosity: 3{}}}.
Test Files
- jstests/sharding/query/change_streams/change_stream_all_databases_v2_strict_whitebox.js — 3 shards
- jstests/sharding/query/change_streams/change_stream_all_databases_v2_ignore_removed_shards_whitebox.js — 4 shards (needs spare after removals)
File 1: Strict Mode (change_stream_all_databases_v2_strict_whitebox.js)
Fixture: 3 shards. Tags: featureFlagChangeStreamPreciseShardTargeting, requires_sharding, uses_change_streams, assumes_balancer_off.
Test 1.1: Initialize with data on multiple shards
Setup: Create DB (primary shard0). Shard collection, split chunks across shard0 and shard1. Insert documents on both.
Steps:
- Snapshot log offset on mongos.
- Open cluster-wide v2 change stream.
- Assert cursors: shard0 (has data), shard1 (has data). No cursor on shard2 (no data). Config cursor open.
- Assert log: ID 11138104 on mongos with shards listing shard0 and shard1.
- Insert a document, verify event received.
Test 1.2: Initialize on empty cluster — config server cursor only
Setup: No user databases.
Steps:
- Snapshot log offset.
- Open cluster-wide v2 change stream.
- Assert cursors: No data shard cursors. Config cursor open.
- Assert log: ID 11138104 with empty shards.
- Snapshot log offset again.
- Create database + collection (triggers DatabaseCreatedControlEvent).
- Assert cursors: Data shard cursor now open on the DB's primary shard. Config cursor still open.
- Assert log: ID 11138117 ("Handling placement refresh") with updated shard set.
- Insert document, verify event received.
Test 1.3: DatabaseCreated on a different shard opens cursor on that shard
Setup: DB1 with primary on shard0, unsharded collection with data.
Steps:
- Open change stream. Assert cursors on shard0 + config.
- Snapshot log offset.
- Create DB2 with primaryShard: shard1. Create collection in DB2.
- Assert cursors: Cursor now also open on shard1. shard2 still no cursor. Config still open.
- Assert log: ID 11138117 with shards including shard1.
- Insert into DB2, verify event received.
Test 1.4: MoveChunk triggers placement refresh
Setup: Collection sharded across shard0 and shard1 (data on both).
Steps:
- Open change stream. Assert cursors on shard0, shard1 + config.
- Snapshot log offset.
- moveChunk all chunks from shard0 to shard2.
- Assert cursors: Cursor opened on shard2. Cursor on shard0 closed (no data). shard1 unchanged. Config still open.
- Assert log: ID 11138117 with updated shard set.
- Insert targeting shard2, verify event.
Test 1.5: MovePrimary triggers placement refresh
Setup: Unsharded collection on shard0 (shard0 is DB primary).
Steps:
- Open change stream. Assert cursor on shard0 + config.
- Snapshot log offset.
- movePrimary to shard1.
- Assert cursors: Cursor on shard1 opened. Cursor on shard0 closed. Config still open.
- Assert log: ID 11138117.
- Insert, verify event.
Test 1.6: NamespacePlacementChanged via reshardCollection triggers placement refresh
Setup: Collection sharded across shard0 and shard1 (key {}{_id: 1}{}).
Steps:
- Open change stream. Assert cursors on shard0, shard1 + config.
- Snapshot log offset.
- reshardCollection with new key {{{} {a: 1}
{}}}, distribute chunks to shard1 and shard2.
- Assert cursors: Cursor opened on shard2. Cursor on shard0 closed. shard1 unchanged. Config still open.
- Assert log: ID 11138117 with updated shard set showing shard1, shard2.
- Insert, verify event with new document key shape.
Test 1.7: Multiple databases on different shards
Setup: DB1 (primary shard0), DB2 (primary shard1), DB3 (primary shard2). Each with an unsharded collection.
Steps:
- Open change stream.
- Assert cursors: shard0, shard1, shard2 all have cursors. Config cursor open.
- Insert one document into each DB, verify all 3 events received.
- is related to
-
SERVER-111381 Implement AllDatabasesChangeStreamShardTargeterImpl module
-
- Closed
-
- related to
-
SERVER-122583 Introduce white-box integration tests for collection change stream v2 shard targeting
-
- Closed
-