Skip to content

Improve BackbeatAPI pause/resume logic #2644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: development/9.1
Choose a base branch
from

Conversation

benzekrimaha
Copy link
Contributor

@benzekrimaha benzekrimaha commented Apr 25, 2025

Issue: BB-658

@bert-e
Copy link
Contributor

bert-e commented Apr 25, 2025

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

@bert-e
Copy link
Contributor

bert-e commented Apr 25, 2025

Incorrect fix version

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

  • None

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

  • 9.0.7

  • 9.1.0

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

@benzekrimaha benzekrimaha force-pushed the improvement/BB-658 branch 3 times, most recently from 5c752cc to 8bdad47 Compare May 7, 2025 11:04
@scality scality deleted a comment from codecov bot May 7, 2025
@benzekrimaha benzekrimaha marked this pull request as ready for review May 7, 2025 11:05
Copy link

codecov bot commented May 7, 2025

Codecov Report

Attention: Patch coverage is 84.39024% with 32 lines in your changes missing coverage. Please review.

Project coverage is 74.25%. Comparing base (487dbb6) to head (91a075a).
Report is 5 commits behind head on development/9.1.

Files with missing lines Patch % Lines
lib/util/LocationStatusManager.js 84.39% 32 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

Files with missing lines Coverage Δ
lib/util/LocationStatusManager.js 83.38% <84.39%> (+0.99%) ⬆️

... and 3 files with indirect coverage changes

Components Coverage Δ
Bucket Notification 75.40% <ø> (ø)
Core Library 80.52% <84.39%> (+0.67%) ⬆️
Ingestion 70.26% <ø> (ø)
Lifecycle 77.94% <ø> (ø)
Oplog Populator 85.06% <ø> (ø)
Replication 61.15% <ø> (ø)
Bucket Scanner 85.60% <ø> (ø)
@@                 Coverage Diff                 @@
##           development/9.1    #2644      +/-   ##
===================================================
+ Coverage            73.91%   74.25%   +0.34%     
===================================================
  Files                  201      201              
  Lines                13446    13591     +145     
===================================================
+ Hits                  9938    10092     +154     
+ Misses                3498     3489       -9     
  Partials                10       10              
Flag Coverage Δ
bucket-scanner 85.60% <ø> (ø)

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
Copy link
Contributor

bert-e commented May 7, 2025

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.

@benzekrimaha benzekrimaha changed the title Improvement/bb 658 Improve BackbeatAPI pause/resume logic May 12, 2025
@bert-e
Copy link
Contributor

bert-e commented May 12, 2025

Incorrect fix version

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

  • 9.1.0

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

  • 9.0.7

  • 9.1.0

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

@@ -438,7 +434,9 @@ class LocationStatusManager {
date.setMinutes(date.getMinutes() + 1);
this._scheduledResumeJobs[service][location] = schedule.scheduleJob(date,
triggerResume.bind(this));
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

should add a test for this case

this._deleteResumeJob(location, service);
this._locationStatusStore[location].setServiceResumeSchedule(service, null);
return this._updateServiceStatusForLocation(location, next);
this._deleteResumeJob(location, service);
Copy link
Contributor

Choose a reason for hiding this comment

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

here _deleteResumeJob() will be applied even if we fail to update the state in mongo : leading to inconsistent state...

}
this._locationStatusStore[location].resumeLocation(service);
Copy link
Contributor

Choose a reason for hiding this comment

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

setting the "in-memory" value afterwards allows to handle errors, but does not actually solve everything: there are still many race conditions here...

  • First and foremost, since we set the value afterwards, changing the value quickly will not "toggle" but keep trying to do the same transition
  • In addition, the state is changed asynchronously: so we may make multiple changes to mongo in parallel, and the results may not be processed in the same order...and so the (in-mem) state may not match the state in mongo (i.e. send "Pause" to mongo ; send "Resume" to mongo ; process the end of the "Resume" call ; process of the "Suspend" call → in mongo we may have state Resume, but store "suspend" in memory)

→ the way to handle this is to actually have a proper automaton, so we can detect the "conflicting" operations and deal with them (reject, retry, ignore/wait for completion...)

this._deleteResumeJob(location, service);
return this._updateServiceStatusForLocation(location, err => {
if (err) {
this._logger.debug('failed to delete scheduled resume', {
Copy link
Contributor

Choose a reason for hiding this comment

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

not tested

if (!paused) {
this._updateServiceStatusForLocation(location, err => {
if (err) {
this._logger.debug('failed to pause service', {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe this log should be moved to _updateServiceStatusForLocation, may be less redundant than having it after each call...

@benzekrimaha benzekrimaha changed the base branch from development/9.0 to development/9.1 May 13, 2025 07:53
@bert-e
Copy link
Contributor

bert-e commented May 13, 2025

Waiting for approval

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

  • the author

  • 2 peers

This commit fixes the callback error format in the LocationStatusManager class.
It also ensures that the status is stored in memory only if it has been updated in MongoDB
successfully, ensuring thus consistensy between both.
Issue: BB-658
Copy link
Contributor

@williamlardier williamlardier left a comment

Choose a reason for hiding this comment

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

I tried to review everything but due to some changes I discuss, some of my comments will likely end up irrelevant, I suggest reading the whole review and work on the "big part"s first, so you don't waste time addressing some of my comments I wrote with the current code


/**
/**
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/**
/**

@@ -343,7 +924,7 @@ class LocationStatusManager {
return cb(null, statuses);
});
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change

@@ -12,20 +12,156 @@ const actions = {
resume: 'resumeService',
};

// Operation types for the state machine
const OPERATION_TYPES = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const OPERATION_TYPES = {
const OPERATION_TYPES = Object.freeze({

if we want to use enum-like values without TS I suggest using this to ensure it will never be changed in any way

}

canTransitionTo(newState) {
const validTransitions = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const validTransitions = {
const validTransitions = Object.freeze({

/**
* Represents a queued operation
*/
class QueuedOperation {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a generic class name that should:

  • Have a more specific name if we can only handle specific operations, here it seems it's related to location, so it should be in the name (maybe ServiceOperation?)
  • Be fully unit tested
  • Be in a dedicated file, as we tend to avoid having multiple classes in the same file

if (operation.retryCount < operation.maxRetries) {
setTimeout(() => {
this._operationQueue.push(operation);
}, 1000 * Math.pow(2, operation.retryCount));
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have support for exponentional backoff in arsenal?
We should add a comment maybe stating the periods it gives given the number of retries we have right now, maybe it will be too big or too small

Comment on lines +366 to +369
{ key, oldState: stateMachineInstance.state, newState: newSmState,
oldScheduledResume: stateMachineInstance.scheduledResumeDate,
newScheduledResume: newScheduledResumeDate,
zkDataUsed: currentZkData });
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
{ key, oldState: stateMachineInstance.state, newState: newSmState,
oldScheduledResume: stateMachineInstance.scheduledResumeDate,
newScheduledResume: newScheduledResumeDate,
zkDataUsed: currentZkData });
{
key, oldState: stateMachineInstance.state,
newState: newSmState,
oldScheduledResume: stateMachineInstance.scheduledResumeDate,
newScheduledResume: newScheduledResumeDate,
zkDataUsed: currentZkData,
});

Comment on lines 362 to 363
(stateMachineInstance.scheduledResumeDate ?
stateMachineInstance.scheduledResumeDate.toISOString() : null) !==
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
(stateMachineInstance.scheduledResumeDate ?
stateMachineInstance.scheduledResumeDate.toISOString() : null) !==
(stateMachineInstance.scheduledResumeDate?.toISOString?.()

Also what if we get two null (or undefined with my suggestion) -> the condition will pass, is that what we want?

if (this._serviceConfig[service] && !this._serviceConfig[service].isMongo) {
this._logger.debug('Initializing state machine for ZK-based service', { key, service, location });
try {
sourceData = await this._getZkDataForLocation(service, location);
Copy link
Contributor

Choose a reason for hiding this comment

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

This calls ZK every time we process an operation, is that OK? I saw we increased the timeouts in tests from 1000ms to 2000ms, is this change fine if we pause/resume at high rate?

Comment on lines 154 to 156
if (transition) {
transition();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (transition) {
transition();
}
transition?.();
  • A log in case there is no transition?

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.

5 participants