Skip to content

Retry the setup of an ingestion reader when it fails - #2806

Open
benzekrimaha wants to merge 2 commits into
development/9.5from
improvement/BB-846-retry-ingestion-reader-setup
Open

Retry the setup of an ingestion reader when it fails#2806
benzekrimaha wants to merge 2 commits into
development/9.5from
improvement/BB-846-retry-ingestion-reader-setup

Conversation

@benzekrimaha

Copy link
Copy Markdown
Contributor

When a reader's setup fails (typically the getRaftId call to the source), it was dropped from the pending list and never set up again: the reader stays registered in _ingestionSources, so applyUpdates considers the bucket already handled and only refreshes it. The bucket was therefore left out of ingestion until the pod was restarted.

Queue the reader again instead, so it is retried on the next cycle. This follows what _processLogReaderEntries already does with read failures, and keeps the other locations ingesting, which restarting the pod on a failed healthcheck would not.

The reader is only queued again if its source is still configured, as it may have been removed while its setup was in progress.

Issue: BB-846

@bert-e

bert-e commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Hello benzekrimaha,

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.
/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.

@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.64%. Comparing base (225a8a3) to head (3d8f265).
⚠️ Report is 3 commits behind head on development/9.5.

Additional details and impacted files

Impacted file tree graph

Files with missing lines Coverage Δ
lib/queuePopulator/IngestionPopulator.js 73.08% <100.00%> (+5.97%) ⬆️

... and 3 files with indirect coverage changes

Components Coverage Δ
Bucket Notification 80.27% <ø> (ø)
Core Library 81.63% <100.00%> (-0.31%) ⬇️
Ingestion 71.68% <100.00%> (+1.58%) ⬆️
Lifecycle 80.46% <ø> (ø)
Oplog Populator 85.83% <ø> (ø)
Replication 62.01% <ø> (-0.04%) ⬇️
Bucket Scanner 85.76% <ø> (ø)
@@                 Coverage Diff                 @@
##           development/9.5    #2806      +/-   ##
===================================================
- Coverage            75.77%   75.64%   -0.14%     
===================================================
  Files                  200      200              
  Lines                13922    13925       +3     
===================================================
- Hits                 10549    10533      -16     
- Misses                3363     3382      +19     
  Partials                10       10              
Flag Coverage Δ
api:retry 9.10% <0.00%> (-0.01%) ⬇️
api:routes 8.87% <0.00%> (-0.01%) ⬇️
bucket-scanner 85.76% <ø> (ø)
ft_test:queuepopulator 9.14% <0.00%> (-1.90%) ⬇️
ingestion 12.26% <0.00%> (-0.01%) ⬇️
lib 8.82% <0.00%> (-0.01%) ⬇️
lifecycle 19.30% <0.00%> (-0.02%) ⬇️
notification 1.02% <0.00%> (-0.01%) ⬇️
oplogPopulator 0.13% <0.00%> (-0.01%) ⬇️
replication 18.84% <0.00%> (-0.01%) ⬇️
unit 55.06% <100.00%> (+0.17%) ⬆️

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.

@bert-e

bert-e commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Request integration branches

Waiting for integration branch creation to be requested by the user.

To request integration branches, please comment on this pull request with the following command:

/create_integration_branches

Alternatively, the /approve and /create_pull_requests commands will automatically
create the integration branches.

@scality scality deleted a comment from bert-e Aug 18, 2026
@scality scality deleted a comment from bert-e Aug 18, 2026
@benzekrimaha
benzekrimaha force-pushed the improvement/BB-846-retry-ingestion-reader-setup branch from 5ad48bb to bd6999f Compare August 19, 2026 13:20
@benzekrimaha
benzekrimaha marked this pull request as ready for review August 19, 2026 17:21
@benzekrimaha
benzekrimaha requested review from a team, delthas and francoisferrand August 19, 2026 17:21
error: err,
});
// the source may have been removed from the configuration
// while its setup was in progress

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.

this comment is misleading: it is not that it "may have been removed", it is certain that is was removed c.f. the beginning of the function:

        const newReaders = this.logReadersUpdate;
        this.logReadersUpdate = [];

→ here you want to explain why you re-add it

Suggested change
// while its setup was in progress
// Setup failures are usually transient (source unreachable,
// invalid credentials...): queue the reader again so that it
// is retried on the next cycle

@benzekrimaha benzekrimaha Aug 20, 2026

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.

Reworded to say why the reader is queued again.

One precision : that comment was about _ingestionSources, the registry of configured sources, not about logReadersUpdate which the function drains at the top. Those are two different structures, and the guard reads the former.
It was imprecise for another reason though. _closeLogState only deletes the _ingestionSources entry when it finds the reader in logReadersUpdate or in logReaders, and while its setup is in progress the reader is in neither, so a source removed right then still leaves its entry behind. What the guard actually catches is a reader that is no longer the one registered for its bucket, which is what the new comment says.

Comment on lines +621 to +625
// Setup failures are usually transient (source unreachable,
// invalid credentials...). Queue the reader again so that it
// is retried on the next cycle: `applyUpdates` only refreshes
// sources that are already registered, so a reader dropped
// here would never be set up again.

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.

not relevant to the code: the old comment was -and still is- correct, we don't add this one to logReaders and continue setting up others...

Suggested change
// Setup failures are usually transient (source unreachable,
// invalid credentials...). Queue the reader again so that it
// is retried on the next cycle: `applyUpdates` only refreshes
// sources that are already registered, so a reader dropped
// here would never be set up again.
// if setup fails for a log reader, don't add it to `logReaders`
// log the error and continue setting up others

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.

Restored.

Comment on lines +626 to +629
const zenkoBucket = logReader.getTargetZenkoBucketName();
this.log.error('error setting up log reader, retrying later', {
method: 'IngestionPopulator._setupUpdatedReaders',
zenkoBucket,

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.

I think we should log the location instead of the bucket, seems more appropriate - or in addition to the bucket, for consistency with other logs in this file:

Suggested change
const zenkoBucket = logReader.getTargetZenkoBucketName();
this.log.error('error setting up log reader, retrying later', {
method: 'IngestionPopulator._setupUpdatedReaders',
zenkoBucket,
this.log.error('error setting up log reader, retrying later', {
method: 'IngestionPopulator._setupUpdatedReaders',)
zenkoBucket: logReader.getTargetZenkoBucketName(),
location: logReader.getLocationConstraint(),

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.

Done, location sits next to zenkoBucket now. I kept the zenkoBucket const since the guard right below reads it.

@bert-e

bert-e commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Incorrect fix version

The Fix Version/s in issue BB-846 contains:

  • 8.6.58

  • 9.0.31

  • 9.1.13

  • 9.2.8

  • 9.3.8

  • 9.4.4

  • 9.5.0

Considering where you are trying to merge, I ignored possible hotfix versions and I expected to find:

  • 8.6.58

  • 9.0.31

  • 9.1.13

  • 9.2.8

  • 9.3.8

  • 9.4.4

  • 9.5.1

  • 9.6.0

Please check the Fix Version/s of BB-846, or the target
branch of this pull request.

@francoisferrand

francoisferrand commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

not the right target branch: no point fixing so far back in time: from 9.5 is enough
(also this is not an improvement, but a bug. so branch name is not right)

@benzekrimaha
benzekrimaha changed the base branch from development/8.6 to development/9.5 August 20, 2026 13:05
@bert-e

bert-e commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Branches have diverged

This pull request's source branch improvement/BB-846-retry-ingestion-reader-setup has diverged from
development/9.5 by more than 50 commits.

To avoid any integration risks, please re-synchronize them using one of the
following solutions:

  • Merge origin/development/9.5 into improvement/BB-846-retry-ingestion-reader-setup
  • Rebase improvement/BB-846-retry-ingestion-reader-setup onto origin/development/9.5

Note: If you choose to rebase, you may have to ask me to rebuild
integration branches using the reset command.

When a reader's setup fails (typically the getRaftId call to the source),
it was dropped from the pending list and never set up again: the reader
stays registered in _ingestionSources, so applyUpdates considers the
bucket already handled and only refreshes it. The bucket was therefore
left out of ingestion until the pod was restarted.

Queue the reader again instead, so it is retried on the next cycle. This
follows what _processLogReaderEntries already does with read failures,
and keeps the other locations ingesting, which restarting the pod on a
failed healthcheck would not.

The reader is only queued again if it is still the one registered for
its bucket, so a source removed or replaced in the meantime is not
brought back.

Issue: BB-846
@benzekrimaha
benzekrimaha force-pushed the improvement/BB-846-retry-ingestion-reader-setup branch from bd6999f to 2f9c7f5 Compare August 20, 2026 13:15
@bert-e

bert-e commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Incorrect fix version

The Fix Version/s in issue BB-846 contains:

  • 8.6.58

  • 9.0.31

  • 9.1.13

  • 9.2.8

  • 9.3.8

  • 9.4.4

  • 9.5.0

Considering where you are trying to merge, I ignored possible hotfix versions and I expected to find:

  • 9.5.1

  • 9.6.0

Please check the Fix Version/s of BB-846, or the target
branch of this pull request.

@benzekrimaha

Copy link
Copy Markdown
Contributor Author

Retargeted to development/9.5 and rebased on it, so the diverged-branch warning is gone.

On the branch prefix: BB-846 is already typed Bug in Jira, only the branch name says otherwise. Renaming it means closing this PR and opening a new one, which also moves the base of #2821 stacked on top, so I left the branch name as is.

@bert-e

bert-e commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Request integration branches

Waiting for integration branch creation to be requested by the user.

To request integration branches, please comment on this pull request with the following command:

/create_integration_branches

Alternatively, the /approve and /create_pull_requests commands will automatically
create the integration branches.

@scality scality deleted a comment from bert-e Aug 20, 2026
@francoisferrand

Copy link
Copy Markdown
Contributor

What happens when the location is deleted?

Please confirm there no risk of path or race condition where we would keep retrying to setup a location which was removed...

A reader whose setup is in flight is in neither `logReaders` nor
`logReadersUpdate`, so `_closeLogState` found nothing to remove and left
its `_ingestionSources` entry behind. The reader then registered itself
once its setup completed: on failure it was queued again, and on success
it became active and could process a batch on a location that no longer
exists.

Unregister the source unconditionally, which makes `_ingestionSources`
authoritative, and hoist the guard above the error branch so that it
covers the success path as well.

Issue: BB-846
@bert-e

bert-e commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Incorrect fix version

The Fix Version/s in issue BB-846 contains:

  • 9.5.1

  • 9.6.0

Considering where you are trying to merge, I ignored possible hotfix versions and I expected to find:

  • 9.5.2

  • 9.6.0

Please check the Fix Version/s of BB-846, or the target
branch of this pull request.

@benzekrimaha

benzekrimaha commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

Fixed here as suggested, in a second commit.
_closeLogState now unregisters the source unconditionally, which makes _ingestionSources authoritative, and the guard moved above the error branch so it covers the success path too.
The point about the extra ingestion round is addressed rather than just bounded: the source is unregistered as soon as it is removed, so a reader whose setup was in flight is neither queued again nor activated. The extra round does not happen at all.
Additionnal validation made by reverting the fix while keeping the tests gives 6 failures and 24 passes, and the 6 failures are exactly the new cases, the pre-existing behaviours pass either way.
One detail worth flagging for future readers: the active-reader test pins that _removeReaderState receives the reader object. The reader has to be read before its entry is deleted, since _removeReaderState polls it on a timer until its batch completes, so a later simplification that drops that ordering would throw every 2s instead of failing loudly.

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

LGTM high level, but I'm not very familiar with that part of the code, so needs a proper second review 😛

});

it('should activate a log reader once its setup succeeds', done => {
const logReaderMock = createLogReaderMock(WORKING_BUCKET, null);

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.

nit: calling createLogReaderMock() is not very readable, the usual pattern is to setup a logReader in the fixture (beforeEach),and let each test setup expectations (logReader.setup.yieldsAsync(setupError))

Of you stick with this form to reduce dedup, than should the next 2 lines as well into that helper

function createLogReaderMock(zenkoBucket, setupError) {
	const logReader = sinon.createStubInstance(IngestionReader);
	logReader.getTargetZenkoBucketName.returns(zenkoBucket);
	logReader.setup.yieldsAsync(setupError);

	ip._ingestionSources[zenkoBucket] = logReader;
	ip.logReadersUpdate = [logReader];

	return logReader;
}

(mixing both approaches makes it a bit weird)

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.

or even just just use the helper to create/add the reader ; but keep the useful mock call (setup) in the test

function addLogReader(zenkoBucket) {
	const logReader = sinon.createStubInstance(IngestionReader);
	logReader.getTargetZenkoBucketName.returns(zenkoBucket);

	ip._ingestionSources[zenkoBucket] = logReader;
	ip.logReadersUpdate = [logReader];

	return logReader;
}

it(....) {
   addLogReader("bucket1").setup.yieldsAsync(errors.InternalError);
}

In addition to making the mocks more explicit, it would also make the tests more readable, by removing extraneous list modifications - like the following, where the test needs to manually edit only to simulate a race condition (nothing needed for simple case):

// should not queue a log reader again when its setup fails and its source is no longer configured
createLogReaderMock("bucket1")
delete ip._ingestionSources["bucket1"]; // remove from the config

});

it('should queue a log reader again when its setup fails', done => {
const logReaderMock =

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.

line break not needed I guess, fits within max column in our prettier config?
(same in following tests)

});
});

describe('removing a source while its setup is in flight', () => {

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.

this describe section is weird: this is still testing _setupUpdatedReaders()

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.

it tests the interaction between _setupUpdatedReaders and _closeLogState, but is it not redundant?

e.g. if you validate on one side the way _setupUpdatedReaders behaves (vs the various contents of _ingestionSources / logReadersUpdate) and the way _closeLogState updates these : then there is nothing left.... if however you want a more "integrated" test, should use the other methods to setup the readers (like applyUpdates and/or addNewLogSource)

// its source may have been removed or replaced in the meantime. It
// must then neither be activated nor retried.
if (this._ingestionSources[zenkoBucket] !== logReader) {
return cb();

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.

should add a log message (just info is enough), would help to troubleshoot if something ever happens in this corner case...

Comment on lines +282 to +283
const FAILING_BUCKET = 'failing-zenko-bucket';
const WORKING_BUCKET = 'working-zenko-bucket';

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.

nit: nothing working or failing for these buckets. Only ingestion is failing, not the buckets

putting the name here (which may be needed because the mocks are hidden deep down c.f. https://github.com/scality/backbeat/pull/2806/changes#r3880675313) gives a false impression there is something, where in fact it is just the ingestion setup mock which fail...

@bert-e

bert-e commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Incorrect fix version

The Fix Version/s in issue BB-846 contains:

  • 9.5.1

  • 9.6.0

Considering where you are trying to merge, I ignored possible hotfix versions and I expected to find:

  • 9.5.3

  • 9.6.0

Please check the Fix Version/s of BB-846, or the target
branch of this pull request.

@francoisferrand

Copy link
Copy Markdown
Contributor

should this land on 9.5 or just delay until 9.6 ?

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.

4 participants