Skip to content

feat(mongodb-runner): add configShard option for sharded clusters - #963

Draft
autarch wants to merge 3 commits into
mainfrom
11-05-mongodb-runner_config-shard-topology
Draft

autarch wants to merge 3 commits into
mainfrom
11-05-mongodb-runner_config-shard-topology

Conversation

@autarch

@autarch autarch commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds a configShard option to mongodb-runner: for the sharded topology, after the cluster is up and shards are added, the runner runs transitionFromDedicatedConfigServer through mongos, waits until the config server appears in listShards (so start returns with the topology fully usable), and serializes configShard: true so ls --json reports it.

Motivated by REP-8055 (mongosync test clusters on mongodb-runner): mongosync currently runs the transition itself in configureNewCluster and excludes the config shard in GetDataOnlyShardCount; with this option they can pass configShard: true and delete their own transition call.

Details

  • CLI --configShard, config-file / programmatic configShard: true; rejected with a clear error for standalone/replset topologies.
  • Requires MongoDB 8.0+ (the command is new in 8.0; verified it does not exist on 6.0.x and 7.0.x binaries).
  • With keyfile/--auth clusters, the localhost exception does not permit the transition and __system cannot authenticate through mongos without enableTestCommands. The runner therefore creates a temporary root user through the localhost exception, runs the transition and readiness poll as that user, creates the cluster's own users as it (the localhost exception closes permanently once any user exists), then drops it. A regression test asserts the temporary user is gone afterward.
  • Readiness polls are bounded by maxTimeMS from the remaining time budget.

Testing

  • can start a sharded cluster with a config shard (topology + serialize round trip)
  • can start a sharded cluster with a config shard and keyfile auth (auth path + temp user cleanup)
  • rejects configShard for non-sharded topologies
  • CLI: starts a config shard cluster and reports it in ls --json
  • Existing keyfile/auth sharded tests still pass (no regressions).

Caveats

  • configShard is a top-level option only; shards[i].configShard in a config file is ignored.
  • DSC + configShard is untested (mongosync does not combine them); errors will surface naturally if unsupported.
  • start --json reporting of configShard arrives with feat(mongodb-runner): include full topology in start --json output #962 (serialized topology in start output).

@autarch
autarch requested review from a team as code owners November 5, 2026 21:23
@autarch
autarch requested review from esvm and a balanced review from Copilot November 5, 2026 21:23
@autarch
autarch marked this pull request as draft November 5, 2026 21:28
@autarch
autarch removed the request for review from esvm November 5, 2026 21:28
@autarch

autarch commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author

Doh, this should've been a draft.

Copilot AI 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.

🟡 Changes recommended

The temporary authentication account can be deleted without a replacement, blocking administrator bootstrapping, and the readiness request can hang indefinitely without a client-side timeout.

2 open issues
What changed in this PR

Adds optional config shards to mongodb-runner’s sharded clusters, allowing callers to delegate the transition and readiness checks to the runner.

Changes:

  • Adds configShard CLI and programmatic options, validation, and serialized state.
  • Implements the transition, readiness polling, and temporary-user handling for authenticated clusters.
  • Adds integration tests and usage documentation.
File Description
packages/​mongodb-runner/​src/​mongoserver.ts Exposes keyfile contents for authentication detection.
packages/​mongodb-runner/​src/​mongocluster.ts Implements config-shard startup, authentication handling, and serialization.
packages/​mongodb-runner/​src/​mongocluster.spec.ts Tests transitions, authenticated startup, serialization, and topology validation.
packages/​mongodb-runner/​src/​cli.ts Adds the --configShard option.
packages/​mongodb-runner/​src/​cli.spec.ts Tests CLI startup and ls --json reporting.
packages/​mongodb-runner/​README.md Documents config-shard usage and requirements.

Review effort: Balanced

mongos.keyFileContents !== undefined || mongos.isAuth;
if (!needsCredentials) {
await mongos.withClient(runTransition);
} else {
Comment on lines +985 to +990
const { shards: currentShards } = await client.db('admin').command({
listShards: 1,
// Bound each poll by the remaining time budget so that a
// stalled mongos cannot hang start() indefinitely.
maxTimeMS: Math.max(1, deadline - Date.now()),
});
autarch added a commit that referenced this pull request Nov 5, 2026
Review follow-ups on #963:

- On clusters that enforce authentication, configShard now requires at
  least one configured user. Without one, the temporary transition user
  would have been the only account on the cluster, and dropping it after
  the transition would leave no users and a permanently closed localhost
  exception, locking out any administrator bootstrap.
- The transition/readiness clients now set a client-side timeoutMS so a
  mongos that stops responding cannot hang start() indefinitely
  (maxTimeMS only bounds server-side execution).
Passing --configShard (or configShard: true in the config file /
programmatic options) turns the config server replica set into a config
shard once the cluster is up, by running
transitionFromDedicatedConfigServer through mongos (MongoDB 5.0+).
start waits until the transition completes (the config server appears in
listShards), and ls --json reports configShard: true for such clusters,
so consumers can distinguish a config shard from a dedicated config
server without connecting.

This is the topology mongosync's test clusters previously built by
running the transition themselves after mongodb-runner finished.
… to 8.0

Adversarial review follow-ups, verified empirically:

- With keyfile authentication the transition failed: the localhost
  exception does not permit transitionFromDedicatedConfigServer, and
  __system cannot authenticate through mongos without enableTestCommands.
  Instead, create a temporary root user through the localhost exception,
  run the transition and readiness poll as that user, create the
  cluster's own users as it (the localhost exception closes once any
  user exists and does not reopen after a drop), then drop it.
- transitionFromDedicatedConfigServer is new in MongoDB 8.0 (removed in
  6.0/7.0 after existing briefly in 5.0); corrected the option docs,
  CLI help, README, and the error message from 5.0+ to 8.0+. Confirmed
  on 6.0.x and 7.0.x binaries that the command does not exist there.
- Each listShards readiness poll is now bounded by maxTimeMS from the
  remaining time budget, so a stalled mongos cannot hang start().
- README no longer claims start --json reports configShard (that
  arrives with the start --json topology output change).
- New regression test: config shard with keyfile auth, asserting the
  temporary user is removed and only the configured user remains.
Review follow-ups on #963:

- On clusters that enforce authentication, configShard now requires at
  least one configured user. Without one, the temporary transition user
  would have been the only account on the cluster, and dropping it after
  the transition would leave no users and a permanently closed localhost
  exception, locking out any administrator bootstrap.
- The transition/readiness clients now set a client-side timeoutMS so a
  mongos that stops responding cannot hang start() indefinitely
  (maxTimeMS only bounds server-side execution).
@autarch
autarch force-pushed the 11-05-mongodb-runner_config-shard-topology branch from 7e34847 to a5df849 Compare November 6, 2026 21:46
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.

2 participants