Skip to content

Refactor replicate object with async await - #2780

Open
SylvainSenechal wants to merge 4 commits into
development/9.5from
improvement/BB-803
Open

Refactor replicate object with async await#2780
SylvainSenechal wants to merge 4 commits into
development/9.5from
improvement/BB-803

Conversation

@SylvainSenechal

@SylvainSenechal SylvainSenechal commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Issue: BB-803

Review hints :

  • The diff is hard to read on github because indentations changes are marked as a diff, in my code editor, when looking at the diff, the display is different and it is significantly easier to review
  • Reviewable commit by commit

Imo this refactor is super overdue and not so complicated to do.

Refactor replicate object with async await

  • Also updated the async parallel util function into async await
  • Also made minimal mandatory updates to MultipleBackend class, as this class inherits ReplicateObject

@bert-e

bert-e commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Hello sylvainsenechal,

My role is to assist you with the merge of this
pull request. Please type @bert-e help to get information
on this process, or consult the user documentation.

Available options
name description privileged authored
/after_pull_request Wait for the given pull request id to be merged before continuing with the current one.
/bypass_author_approval Bypass the pull request author's approval
/bypass_build_status Bypass the build and test status
/bypass_commit_size Bypass the check on the size of the changeset TBA
/bypass_incompatible_branch Bypass the check on the source branch prefix
/bypass_jira_check Bypass the Jira issue check
/bypass_peer_approval Bypass the pull request peers' approval
/bypass_leader_approval Bypass the pull request leaders' approval
/approve Instruct Bert-E that the author has approved the pull request. ✍️
/create_pull_requests Allow the creation of integration pull requests.
/create_integration_branches Allow the creation of integration branches.
/no_octopus Prevent Wall-E from doing any octopus merge and use multiple consecutive merge instead
/unanimity Change review acceptance criteria from one reviewer at least to all reviewers
/wait Instruct Bert-E not to run until further notice.
Available commands
name description privileged
/help Print Bert-E's manual in the pull request.
/status Print Bert-E's current status in the pull request TBA
/clear Remove all comments from Bert-E from the history TBA
/retry Re-start a fresh build TBA
/build Re-start a fresh build TBA
/force_reset Delete integration branches & pull requests, and restart merge process from the beginning.
/reset Try to remove integration branches unless there are commits on them which do not appear on the source branch.

Status report is not available.

/**
* Runs an async task for each item in a collection, up to `limit` at a time.
* On error, no new tasks are started, but already-running tasks are awaited
* before the function resolves. Returns [firstError, results] so that callers

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Return the first error only : Keeping same behavior as before with mapLimitWaitPendingIfError.

Could've returned all errors as a list but not needed now and prefer to keep existing behavior.
Cannot aggregate errors neither, as we need to keep the original error to check its properties to determine if its retryable or not

Comment thread lib/util/mapLimitWaitPendingIfError.js Outdated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

refactored with async await, in the file runTaskWithConcurrency

@scality scality deleted a comment from bert-e Jul 23, 2026
@bert-e

bert-e commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Waiting for approval

The following approvals are needed before I can proceed with the merge:

  • the author

  • 2 peers

@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.80000% with 33 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.48%. Comparing base (ce83f7c) to head (64afb79).

Files with missing lines Patch % Lines
extensions/replication/tasks/ReplicateObject.js 88.60% 22 Missing ⚠️
...xtensions/replication/tasks/MultipleBackendTask.js 68.57% 11 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

Files with missing lines Coverage Δ
lib/tasks/BackbeatTask.js 95.65% <100.00%> (+0.53%) ⬆️
lib/util/runTasksWithConcurrency.js 100.00% <100.00%> (ø)
...xtensions/replication/tasks/MultipleBackendTask.js 59.80% <68.57%> (-0.25%) ⬇️
extensions/replication/tasks/ReplicateObject.js 92.17% <88.60%> (-0.27%) ⬇️

... and 3 files with indirect coverage changes

Components Coverage Δ
Bucket Notification 80.22% <ø> (ø)
Core Library 81.24% <100.00%> (+0.14%) ⬆️
Ingestion 70.75% <ø> (ø)
Lifecycle 80.25% <ø> (ø)
Oplog Populator 85.83% <ø> (ø)
Replication 61.88% <85.52%> (-0.09%) ⬇️
Bucket Scanner 85.76% <ø> (ø)
@@                 Coverage Diff                 @@
##           development/9.5    #2780      +/-   ##
===================================================
+ Coverage            75.43%   75.48%   +0.05%     
===================================================
  Files                  201      202       +1     
  Lines                13928    13949      +21     
===================================================
+ Hits                 10506    10529      +23     
+ Misses                3412     3410       -2     
  Partials                10       10              
Flag Coverage Δ
api:retry 9.05% <0.00%> (+<0.01%) ⬆️
api:routes 8.83% <0.00%> (+<0.01%) ⬆️
bucket-scanner 85.76% <ø> (ø)
ft_test:queuepopulator 10.37% <0.00%> (+1.25%) ⬆️
ingestion 12.30% <0.00%> (-0.01%) ⬇️
lifecycle 19.15% <0.00%> (-0.11%) ⬇️
notification 1.00% <0.00%> (+<0.01%) ⬆️
oplogPopulator 0.13% <0.00%> (+<0.01%) ⬆️
replication 18.74% <79.60%> (-0.06%) ⬇️
unit 54.64% <55.60%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread extensions/replication/tasks/ReplicateObject.js
}
}

_refreshSourceEntry(sourceEntry, log, cb) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Partial hierarchy migration: ReplicateObject._refreshSourceEntry was migrated to async _refreshSourceEntry(sourceEntry, log) (no callback), but this override still uses the callback signature (sourceEntry, log, cb). Not broken today because MultipleBackendTask.processQueueEntry calls it with a callback, but if any code path ever calls await this._refreshSourceEntry(sourceEntry, log) on a MultipleBackendTask instance, cb will be undefined and the method will throw.

Consider migrating this override to async in the same PR to keep the hierarchy consistent, per the "migrate when you touch" rule for class methods.

this commit is mandatory as multipleBackend is a class that extends replicateObject and some functions are overloaded

Issue: BB-803
if (err.$metadata?.httpStatusCode === 404) {
return doneOnce(err);
// eslint-disable-next-line no-param-reassign
err.origin = 'source';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Behavioral change: the old stream error handler returned errors.ObjNotFound (no .origin property). In _handleReplicationOutcome (line 1034), the ObjNotFound check matched but err.origin === 'source' was false, so it entered _processQueueEntryRetryFull. With err.origin = 'source' now set, _handleReplicationOutcome instead skips the entry immediately via done().

Old path: source 404 during streaming → retry full → next attempt likely gets a send-level 404 (no ObjNotFound) → marked FAILED
New path: source 404 during streaming → skipped silently (no FAILED status published)

The new behavior is arguably more correct (the source object is gone, retrying is pointless), but it changes replication status reporting in a production path — entries that were previously marked FAILED now produce no status at all.

});
throw errors.BadRole;
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hierarchy contract mismatch: ReplicateObject._setupRolesOnce now returns [sourceRole, targetRole] (line 348), but this override returns nothing. _setupRoles resolves to undefined, which would throw TypeError: undefined is not iterable if destructured like ReplicateObject.processQueueEntry does (const [, targetRole] = await this._setupRoles(...)). Currently safe because MultipleBackendTask._setupClients ignores the result, but returning the roles would keep the hierarchy contract consistent.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Migrations here aren't the main point of this pr, but were kinda forced as MultipleBackend extends ReplicateObject.

I did the minimum required migration on this file

@SylvainSenechal
SylvainSenechal requested review from a team, benzekrimaha and delthas July 23, 2026 20:35
@SylvainSenechal
SylvainSenechal marked this pull request as ready for review July 23, 2026 20:35
@SylvainSenechal
SylvainSenechal requested review from maeldonn and removed request for delthas July 23, 2026 20:35

@benzekrimaha benzekrimaha 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.

Good refactor overall, but one real issue with the outcome handler being called from inside the try.

await this._deleteOrphans(destEntry, destLocations, log);
throw err;
}
return this._handleReplicationOutcome(null, sourceEntry, destEntry, kafkaEntry, log, done);

@benzekrimaha benzekrimaha Jul 24, 2026

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.

_handleReplicationOutcome(null, …, done) is called from inside the try: if it throws after calling done, the catch calls it again and done fires twice. We can compute the error in the try/catch and call the handler exactly once after it. (same at line 909 and in _processQueueEntryRetryFull)

@bert-e

bert-e commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Waiting for approval

The following approvals are needed before I can proceed with the merge:

  • the author

  • 2 peers

The following reviewers are expecting changes from the author, or must review again:

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