Skip to content

TOOLS-4263 Convert mongorestore replica-set oplog-replay tests to Go - #1049

Merged
autarch merged 1 commit into
masterfrom
07-23-tools-4263_convert_mongorestore_replica-set_oplog-replay_tests_to_go
Aug 12, 2026
Merged

TOOLS-4263 Convert mongorestore replica-set oplog-replay tests to Go#1049
autarch merged 1 commit into
masterfrom
07-23-tools-4263_convert_mongorestore_replica-set_oplog-replay_tests_to_go

Conversation

@autarch

@autarch autarch commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Adds TestOplogReplayFromLocalOplogRS in mongorestore/oplog_replset_test.go, which ports two JS tests into a single Go test. It records a checkpoint timestamp, performs more writes, dumps local.oplog.rs with a {ts: {$gt: <checkpoint>}} query, and replays that dump with --oplogReplay --oplogFile, asserting only the ops after the checkpoint are applied. This test requires a replica set, so it is gated on testtype.ReplSetTestType (TOOLS_TESTING_REPLSET) rather than the plain integration test type; that is why these two JS tests were deliberately left out of the earlier oplog edge-case conversion.

JS -> Go mapping (both map to TestOplogReplayFromLocalOplogRS in mongorestore/oplog_replset_test.go):

  • test/qa-tests/jstests/restore/oplog_replay_local_rs.js -> TestOplogReplayFromLocalOplogRS (mongorestore/oplog_replset_test.go) - the --oplogReplay --oplogFile replay half: a dumped local/oplog.rs.bson is replayed against the live replica set and only the expected ops take effect.
  • test/legacy42/jstests/tool/dumprestore7.js -> TestOplogReplayFromLocalOplogRS (mongorestore/oplog_replset_test.go) - the mongodump half: dumping local.oplog.rs with a {ts: {$gt: ...}} timestamp query captures exactly the ops after the checkpoint.

@autarch
autarch force-pushed the 07-17-tools-4263_convert_mongorestore_oplog-replay_edge-case_tests_to_go branch from 6e72aea to 60200d1 Compare July 23, 2026 18:19
@autarch
autarch force-pushed the 07-23-tools-4263_convert_mongorestore_replica-set_oplog-replay_tests_to_go branch from f43b301 to e8077fc Compare July 23, 2026 18:19
@autarch
autarch force-pushed the 07-17-tools-4263_convert_mongorestore_oplog-replay_edge-case_tests_to_go branch from 60200d1 to 04c98db Compare July 24, 2026 16:40
@autarch
autarch force-pushed the 07-23-tools-4263_convert_mongorestore_replica-set_oplog-replay_tests_to_go branch from e8077fc to c060980 Compare July 24, 2026 16:40
@autarch
autarch force-pushed the 07-17-tools-4263_convert_mongorestore_oplog-replay_edge-case_tests_to_go branch from 04c98db to 8fc1df8 Compare July 27, 2026 21:16
@autarch
autarch force-pushed the 07-23-tools-4263_convert_mongorestore_replica-set_oplog-replay_tests_to_go branch from c060980 to 6b97a36 Compare July 27, 2026 21:17
@autarch
autarch force-pushed the 07-17-tools-4263_convert_mongorestore_oplog-replay_edge-case_tests_to_go branch from 8fc1df8 to cb21dec Compare August 5, 2026 21:43
@autarch
autarch force-pushed the 07-23-tools-4263_convert_mongorestore_replica-set_oplog-replay_tests_to_go branch from 6b97a36 to 6108e99 Compare August 5, 2026 21:43
@autarch
autarch force-pushed the 07-23-tools-4263_convert_mongorestore_replica-set_oplog-replay_tests_to_go branch from 6108e99 to d36edee Compare August 5, 2026 21:47
@autarch
autarch force-pushed the 07-17-tools-4263_convert_mongorestore_oplog-replay_edge-case_tests_to_go branch from cb21dec to 20dc955 Compare August 5, 2026 21:48
@autarch
autarch force-pushed the 07-23-tools-4263_convert_mongorestore_replica-set_oplog-replay_tests_to_go branch from d36edee to b2f3635 Compare August 6, 2026 21:25
@autarch
autarch force-pushed the 07-17-tools-4263_convert_mongorestore_oplog-replay_edge-case_tests_to_go branch from 20dc955 to cdfbc96 Compare August 6, 2026 21:25
@autarch
autarch requested a review from mmcclimon August 7, 2026 16:35
@autarch
autarch marked this pull request as ready for review August 7, 2026 16:36
@autarch
autarch requested a review from a team as a code owner August 7, 2026 16:36
@autarch
autarch force-pushed the 07-23-tools-4263_convert_mongorestore_replica-set_oplog-replay_tests_to_go branch from b2f3635 to dee6aeb Compare August 7, 2026 18:41
@autarch
autarch force-pushed the 07-17-tools-4263_convert_mongorestore_oplog-replay_edge-case_tests_to_go branch from cdfbc96 to 2ab1f91 Compare August 7, 2026 18:42
@autarch
autarch force-pushed the 07-23-tools-4263_convert_mongorestore_replica-set_oplog-replay_tests_to_go branch from dee6aeb to 51f2499 Compare August 7, 2026 18:57

@mmcclimon mmcclimon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Alright, though I'd probably move these to the dumprestore package and write them to match that style.

Comment thread mongorestore/oplog_replset_test.go Outdated
`{"ts":{"$gt":{"$timestamp":{"t":%d,"i":%d}}},"ns":%q,"op":"i"}`,
checkpoint.T, checkpoint.I, ns,
)
require.NoError(t, runDump(t, baseToolOpts(t), dumpDir, func(md *mongodump.MongoDump) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should these really go in the mongorestore directory, since they're actually running dump + restore?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Moved

Comment thread mongorestore/oplog_replset_test.go Outdated
checkpoint := latestOplogTimestamp(t, client)

// Second batch: these ops follow the checkpoint and must be replayed.
const secondBatch = 7

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

(nit) This const is pretty weird, as is the choice of the number 7?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Claude picked this semi-randomly, but it should differ from the first batch size, so we can be sure that it picks the right "side" of the oplog (with 7 entries after the timestamp rather than 5 before).

Comment thread mongorestore/oplog_replset_test.go Outdated
"only the ops after the checkpoint are replayed",
)

batch1Count, err := coll.CountDocuments(ctx, bson.M{"batch": 1})

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We usually use bson.D for all of these.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

@autarch
autarch force-pushed the 07-17-tools-4263_convert_mongorestore_oplog-replay_edge-case_tests_to_go branch from 0343320 to aa0f959 Compare August 10, 2026 20:44
@autarch
autarch force-pushed the 07-23-tools-4263_convert_mongorestore_replica-set_oplog-replay_tests_to_go branch from 51f2499 to 5bc5a26 Compare August 10, 2026 20:44
@autarch
autarch force-pushed the 07-23-tools-4263_convert_mongorestore_replica-set_oplog-replay_tests_to_go branch from 5bc5a26 to c7741dd Compare August 10, 2026 21:22
@autarch
autarch force-pushed the 07-17-tools-4263_convert_mongorestore_oplog-replay_edge-case_tests_to_go branch from aa0f959 to 4d1d9e4 Compare August 10, 2026 21:22
@autarch
autarch force-pushed the 07-23-tools-4263_convert_mongorestore_replica-set_oplog-replay_tests_to_go branch from c7741dd to ec6cd0a Compare August 11, 2026 17:11
@autarch
autarch force-pushed the 07-17-tools-4263_convert_mongorestore_oplog-replay_edge-case_tests_to_go branch from 4d1d9e4 to 5b3c649 Compare August 11, 2026 17:11

autarch commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator Author

Merge activity

  • Aug 12, 6:36 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Aug 12, 6:42 PM UTC: Graphite rebased this pull request as part of a merge.
  • Aug 12, 6:42 PM UTC: @autarch merged this pull request with Graphite.

@autarch
autarch changed the base branch from 07-17-tools-4263_convert_mongorestore_oplog-replay_edge-case_tests_to_go to graphite-base/1049 August 12, 2026 18:39
@autarch
autarch changed the base branch from graphite-base/1049 to master August 12, 2026 18:40
This adds a new `TestOplogReplayFromLocalOplogRS` test in `mongorestore/oplog_replset_test.go`. This ports two JS tests into one Go test. It dumps `local.oplog.rs` with a `$gt` timestamp query and replays the dump via `--oplogReplay --oplogFile ...`, verifying only the ops after the checkpoint are applied.

JS -> Go mapping:

- test/qa-tests/jstests/restore/oplog_replay_local_rs.js -> the
    --oplogReplay --oplogFile replay of a dumped local/oplog.rs.bson
- test/legacy42/jstests/tool/dumprestore7.js -> the mongodump of
    local.oplog.rs with a {ts:{$gt:...}} timestamp query
@autarch
autarch force-pushed the 07-23-tools-4263_convert_mongorestore_replica-set_oplog-replay_tests_to_go branch from ec6cd0a to bf3464c Compare August 12, 2026 18:41
@autarch
autarch merged commit a069aa5 into master Aug 12, 2026
6 of 7 checks passed
@autarch
autarch deleted the 07-23-tools-4263_convert_mongorestore_replica-set_oplog-replay_tests_to_go branch August 12, 2026 18:42
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