-
Type:
Engineering Test
-
Resolution: Fixed
-
Priority:
Major - P3
-
Affects Version/s: None
-
Component/s: None
-
None
-
Storage Execution
-
Fully Compatible
-
Storage Execution 2026-04-27
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Overview
Add unit test coverage for PDIB side-write draining into a unique index with TrackDuplicates::kTrack, verifying that duplicate keys are
recorded to the constraint violations table and that the additional container oplog entry is generated.
Background
The existing PDIB drain tests added in SERVER-114680 all use non-unique indexes with TrackDuplicates::kNoTrack and dupsAllowed=true.
There is a separate code path exercised when draining into a unique index with kTrack: duplicate keys hit the onDuplicateKeyFn callback
(index_build_interceptor.cpp:153-157), which calls recordDuplicateKey(), which under PDIB uses container_write::insert() to write to
the constraint violations table (duplicate_key_tracker.cpp:97-122). This generates an additional CI oplog entry beyond the 2 (CI for index
insert, CD for side write removal) that the existing tests verify. No existing test exercises this end-to-end path through drain.
Scope of Work
- src/mongo/db/index_builds/index_build_interceptor_test.cpp — Add a new test (e.g.
DrainInsertSideWriteRecordsDuplicateKeyAndGeneratesContainerOplogEntriesPrimaryDriven)
Implementation Details
The new test should:
- Enable PDIB feature flags (featureFlagContainerWrites, featureFlagPrimaryDrivenIndexBuilds).
- Register the OpObserver (call registerOpObserver()).
- Create an IndexBuildInfo with a unique index spec
- Pre-populate the index with a key (e.g. key value 10, RecordId 1) using insertKeys() directly.
- Buffer a side write that inserts a duplicate of that key (same key value 10, different RecordId 2) via {{interceptor->sideWrite(...,
Op::kInsert, ...)}}. - Record oplog size after buffer phase.
- Call interceptor->drainWritesIntoIndex() with InsertDeleteOptions{.dupsAllowed = true}, TrackDuplicates::kTrack,
DrainYieldPolicy::kNoYield. - Verify:
- The oplog contains an applyOps entry with 3 inner container operations (not 2):
- CI on the index ident (the duplicate key insert)
- CI on the constraint violations table ident (the recorded duplicate)
- CD on the side writes table ident (the consumed side write)
- The constraint violations table is non-empty (use getDuplicateKeyTableContents()).
- The side writes table is empty (use getSideWritesTableContents()).
- The oplog contains an applyOps entry with 3 inner container operations (not 2):
Follow the structure of DrainInsertSideWriteGeneratesContainerOplogEntriesPrimaryDriven (line 844) as a template, adapting it for a unique
index with a pre-existing key conflict and kTrack.
Acceptance Criteria
- New test passes: bazel run +index_build_interceptor_test
- Test verifies 3 container ops in the drain oplog entry (CI index, CI constraint violations, CD side writes)
- Test verifies constraint violations table contains the recorded duplicate
- Test verifies side writes table is empty after drain
- is related to
-
SERVER-114680 Unittest that ci/cd entries are generated when draining side writes
-
- Closed
-