Ensure unique indexes with duplicate keys generate all ci/cd oplog entries

XMLWordPrintableJSON

    • Type: Engineering Test
    • Resolution: Fixed
    • Priority: Major - P3
    • 9.0.0-rc0
    • 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:

      1. Enable PDIB feature flags (featureFlagContainerWrites, featureFlagPrimaryDrivenIndexBuilds).
      2. Register the OpObserver (call registerOpObserver()).
      3. Create an IndexBuildInfo with a unique index spec
      4. Pre-populate the index with a key (e.g. key value 10, RecordId 1) using insertKeys() directly.
      5. Buffer a side write that inserts a duplicate of that key (same key value 10, different RecordId 2) via {{interceptor->sideWrite(...,
        Op::kInsert, ...)}}.
      6. Record oplog size after buffer phase.
      7. Call interceptor->drainWritesIntoIndex() with InsertDeleteOptions{.dupsAllowed = true}, TrackDuplicates::kTrack,
        DrainYieldPolicy::kNoYield.
      8. 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()).

      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

            Assignee:
            Stephanie Eristoff
            Reporter:
            Stephanie Eristoff
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: