Skip to content

Preserve Native CDC configuration during controller failover - #13740

Merged
tclinkenbeard-oai merged 2 commits into
apple:mainfrom
tclinkenbeard-oai:dev/tclinkenbeard/native-cdc-shared-tag-invalid-option-startup
Jul 20, 2026
Merged

tclinkenbeard-oai merged 2 commits into
apple:mainfrom
tclinkenbeard-oai:dev/tclinkenbeard/native-cdc-shared-tag-invalid-option-startup

Conversation

@tclinkenbeard-oai

@tclinkenbeard-oai tclinkenbeard-oai commented Jul 18, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

This PR fixes a Native CDC startup race during cluster-controller failover. A freshly elected controller can broadcast bootstrap ServerDBInfo with nativeCdcTagCount=0 while an existing CDC proxy is registering a stream; registration checks nativeCdcEnabled, awaits metadata, then previously reread the replacement tag count and failed with invalid_option_value (2006).

  • seed the bootstrap server-side CDC fields from the configured client knobs
  • snapshot enabled/tag-count together before the registration await
  • add a focused bootstrap regression without weakening shared-tag coverage

Failure and validation

Reproduced failed Joshua test 20260718-104347-joshua-proxy-9ab21403d3930b23 using the exact NativeCdcSharedTag.toml tuple.

The original binary deterministically failed at the second controller change; the fixed binary passed the identical generated configuration three times (Ok=1, 234.454 simulated seconds), with no invalid_option_value, 2006, or workload-start failures. Managed validation also passed all 23 /NativeCDC/ unit cases and all 23 /fdbserver/clustercontroller cases.

@tclinkenbeard-oai
tclinkenbeard-oai marked this pull request as ready for review July 18, 2026 16:12
@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr-clang-ide on Linux RHEL 9

  • Commit ID: 167b157
  • Duration 0:28:38
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr-macos-m1 on macOS 14.x

  • Commit ID: 167b157
  • Duration 0:45:03
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr-clang-arm on Linux RHEL 9

  • Commit ID: 167b157
  • Duration 0:45:27
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr-clang on Linux RHEL 9

  • Commit ID: 167b157
  • Duration 0:58:11
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr-macos on macOS 14.x

  • Commit ID: 167b157
  • Duration 1:18:10
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr-cluster-tests on Linux RHEL 9

  • Commit ID: 167b157
  • Duration 1:36:24
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)
  • Cluster Test Logs zip file of the test logs (available for 30 days)

@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr on Linux RHEL 9

  • Commit ID: 167b157
  • Duration 1:13:43
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@gxglass gxglass left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR 13740 — Preserve Native CDC configuration during controller failover · High · LGTM-with-nits

Review: apple/foundationdb #13740 — Preserve Native CDC configuration during controller failover

Intent

The PR ensures a freshly-constructed cluster controller advertises the correct Native CDC configuration (nativeCdcEnabled, nativeCdcTagCount) from the moment it bootstraps, rather than defaulting to disabled/zero until the first recovery publishes real values. It also tightens registerNativeCdcStream to snapshot both Native CDC config fields from a single clientInfo read so validation and tag allocation see a consistent view.

Correctness

The change achieves its stated intent.

  • ClusterControllerData::ClusterControllerData (ClusterController.actor.cpp:126-127 in current main) builds a default ServerDBInfo whose .client is a default-constructed ClientDBInfo (nativeCdcEnabled=false, nativeCdcTagCount=0), then calls db.serverInfo->set(serverInfo). The PR sets serverInfo.client.nativeCdcEnabled/TagCount from CLIENT_KNOBS before that set.
  • Why this matters for failover: clusterControllerCore starts clusterWatchDatabase (drives recovery, publishes correct client info at ~ClusterController.actor.cpp:769-770 and 1446-1447) concurrently with monitorGlobalConfig (ClusterController.actor.cpp:2081). monitorGlobalConfig does clientInfo = db->serverInfo->get().client; (line 2101) and republishes that to both serverInfo and db->clientInfo. On a fresh CC (a controller failover), if a global-config change fires before recovery's first publish, the pre-PR code would copy the default .client and actively push nativeCdcEnabled=false, nativeCdcTagCount=0 to clients via clusterOpenDatabase (line 915 serves db->clientInfo->get() directly). The constructor fix means that early propagation now carries the real knob values. This is a genuine, correct fix for the failover window.
  • Consistency with existing publish paths: the two knob values are already set identically in clusterWatchDatabase (769-770) and in the registerMaster client-info construction (1446-1447). Seeding them in the constructor is consistent and does not conflict with those later writes — recovery overwrites with the same knob-derived values.
  • registerNativeCdcStream (NativeCdc.cpp:397-400): pre-PR read nativeCdcEnabled for validation, then after co_await observeNativeCdcMetadata(...) (a yield point where the CC can call db.clientInfo->set(...)) re-read nativeCdcTagCount from a possibly different clientInfo snapshot. That torn read could pass validation on an enabled snapshot and then hit a reset snapshot with nativeCdcTagCount==0, making allocator.allocate(0) throw invalid_option_value() (NativeCdc.cpp:77-78) instead of the intended client_invalid_operation() — or, less likely, the reverse. Snapshotting both fields once, before any co_await, removes the torn read. This is exactly the transient-default state a controller failover can produce, so the two halves of the PR reinforce each other.

Note on the diff base: the diff header for the constructor hunk shows an older base (it does not include the pre-existing lines 769-770/1446-1447 that current main already has), but git apply --check against current main (HEAD 1ae8e7f) succeeds cleanly for all hunks; insertion context matches. No rebase hazard.

Bugs

None found.

  • The NativeCdc.cpp locals are both used (nativeCdcEnabled → validateNativeCdcEnabled, nativeCdcTagCount → allocate); no unused-variable warning.
  • The constructor write is on the local serverInfo before set, so it is observed by the initial publish; no ordering issue.
  • No new TraceEvent / no Sev30/40 risk; no simulation-determinism concern (values are knob-derived, deterministic).

Omissions

  • No test survives. Commit 1 added TEST_CASE("/NativeCDC/ClusterControllerBootstrapPublishesConfiguration") asserting the constructor publishes the knob values; commit 2 removed it as "redundant." The net PR ships with zero coverage for the bootstrap/failover behavior it fixes. The removed unit test was cheap, deterministic, and directly guarded the constructor invariant — its removal is the weakest part of the PR. Even if judged redundant with an end-to-end path, nothing in NativeCdcEndToEnd.cpp exercises a cluster-controller failover: forceTransactionSystemRecovery (NativeCdcEndToEnd.cpp:1139-1150) reboots the master zone to force a transaction-system recovery, which is not the same as a CC process failover constructing a fresh ClusterControllerData. The specific window this PR closes (new CC + early monitorGlobalConfig publish) is therefore untested.
  • The torn-read fix in registerNativeCdcStream has no regression test either (would require injecting a clientInfo change across the observeNativeCdcMetadata await).
  • Consider re-adding the unit test (or noting why it is safe to drop); it costs little and pins the constructor contract.

Alternatives

  • A more robust structural fix would be a single helper that stamps the Native CDC knob fields onto a ClientDBInfo/ServerDBInfo.client, called from all three sites (constructor, clusterWatchDatabase, registerMaster), so the three copies of nativeCdcEnabled = ENABLE_NATIVE_CDC; nativeCdcTagCount = NATIVE_CDC_TAG_COUNT; cannot drift. Not required for this PR, and out of its scope.
  • Alternatively, seed db.clientInfo (not just serverInfo.client) in the constructor, closing the even-earlier window where a client openDatabase lands before any publish. In practice clients retry on clientInfo->onChange, and the feature gate is fail-closed (disabled just rejects registration), so this is not material. "none material."

Verdict

LGTM-with-nits — correct, well-targeted failover fix and a real torn-read hardening; the only nit is that the PR removed its own unit test, leaving the fixed behavior uncovered (no CC-failover coverage exists in NativeCdcEndToEnd).

Interaction with #13733 / #13674

No direct textual conflict is visible from this diff. Both this PR and the surrounding Native CDC work touch fdbclient/NativeCdc.cpp and the CC client-info publish path, so if #13733/#13674 also modify registerNativeCdcStream or the ClientDBInfo publish sites they may textually collide on those lines; that is a merge-order concern, not a correctness defect here. (Flagged per instructions; no evidence of a semantic interaction.)

@tclinkenbeard-oai
tclinkenbeard-oai merged commit 750cd53 into apple:main Jul 20, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants