Skip to content
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

Ensure lifecycle tasks wait for messages to be pushed #2603

Open
wants to merge 1 commit into
base: development/8.6
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions extensions/lifecycle/tasks/LifecycleTask.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,8 @@
});
}

const promises = [];

// sending bucket entry - only once - for checking next listing
if (data.IsTruncated && allVersions.length > 0 && nbRetries === 0) {
// Uses last version whether Version or DeleteMarker
Expand All @@ -414,31 +416,30 @@
prevDate: last.LastModified,
},
});
this._sendBucketEntry(entry, err => {
promises.push(new Promise(resolve => this._sendBucketEntry(entry, err => {
if (!err) {
log.debug('sent kafka entry for bucket ' +
'consumption', {
method: 'LifecycleTask._getObjectVersions',
});
}
});
resolve(); // safe to ignore the error, we will retry lifecycle eventually
})));
}

// if no versions to process, skip further processing for this
// batch
// if no versions to process, skip further processing for this batch
if (allVersionsWithStaleDate.length === 0) {
return done(null);
return Promise.allSettled(promises).then(() => done(), done);

Check warning on line 432 in extensions/lifecycle/tasks/LifecycleTask.js

View check run for this annotation

Codecov / codecov/patch/Backbeat

extensions/lifecycle/tasks/LifecycleTask.js#L432

Added line #L432 was not covered by tests
}

// for each version, get their relative rules, compare with
// bucket rules, match with `staleDate` to
// NoncurrentVersionExpiration Days and send expiration if
// rules all apply
return this._compareRulesToList(bucketData, bucketLCRules,
allVersionsWithStaleDate, log, versioningStatus,
err => {
promises.push(new Promise((resolve, reject) => this._compareRulesToList(bucketData,
bucketLCRules, allVersionsWithStaleDate, log, versioningStatus, err => {
if (err) {
return done(err);
return reject(err);

Check warning on line 442 in extensions/lifecycle/tasks/LifecycleTask.js

View check run for this annotation

Codecov / codecov/patch/Backbeat

extensions/lifecycle/tasks/LifecycleTask.js#L442

Added line #L442 was not covered by tests
}

if (!data.IsTruncated) {
Expand All @@ -453,8 +454,10 @@
);
}

return done();
});
return resolve();
})));

return Promise.allSettled(promises).then(() => done(), done);
});
}

Expand Down
102 changes: 60 additions & 42 deletions extensions/lifecycle/tasks/LifecycleTaskV2.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'; // eslint-disable-line

const async = require('async');
const util = require('util');
const { errors } = require('arsenal');

const LifecycleTask = require('./LifecycleTask');
Expand Down Expand Up @@ -39,33 +40,33 @@
* @param {array} remainings - array of { prefix, listType, beforeDate }
* @param {object} bucketData - bucket data
* @param {Logger.newRequestLogger} log - logger object
* @param {function} done - callback(error)
* @return {undefined}
*/
_handleRemainingListings(remainings, bucketData, log) {
if (remainings && remainings.length) {
remainings.forEach(l => {
const {
prefix,
listType,
beforeDate,
storageClass,
} = l;

const entry = Object.assign({}, bucketData, {
contextInfo: { requestId: log.getSerializedUids() },
details: { beforeDate, prefix, listType, storageClass },
});
_handleRemainingListings(remainings, bucketData, log, done) {
async.forEach(remainings || [], (l, cb) => {
const {
prefix,
listType,
beforeDate,
storageClass,
} = l;

const entry = Object.assign({}, bucketData, {
contextInfo: { requestId: log.getSerializedUids() },
details: { beforeDate, prefix, listType, storageClass },
});

this._sendBucketEntry(entry, err => {
if (!err) {
log.debug(
'sent kafka entry for bucket consumption', {
method: 'LifecycleTaskV2._getVersionList',
});
}
});
this._sendBucketEntry(entry, err => {
if (!err) {
log.debug(
'sent kafka entry for bucket consumption', {
method: 'LifecycleTaskV2._getVersionList',
});
}
cb();
});
}
}, done);
}

/**
Expand Down Expand Up @@ -101,15 +102,19 @@
return process.nextTick(done);
}

const promises = [];

// re-queue remaining listings only once
if (nbRetries === 0) {
this._handleRemainingListings(remainings, bucketData, log);
promises.push(util.promisify(this._handleRemainingListings).bind(this)(
remainings, bucketData, log,
));
}

return this.backbeatMetadataProxy.listLifecycle(listType, params, log,
(err, contents, isTruncated, markerInfo) => {
if (err) {
return done(err);
return Promise.allSettled(promises).then(() => done(err), () => done(err));

Check warning on line 117 in extensions/lifecycle/tasks/LifecycleTaskV2.js

View check run for this annotation

Codecov / codecov/patch/Backbeat

extensions/lifecycle/tasks/LifecycleTaskV2.js#L117

Added line #L117 was not covered by tests
}

// re-queue truncated listing only once.
Expand All @@ -125,17 +130,22 @@
},
});

this._sendBucketEntry(entry, err => {
promises.push(new Promise(resolve => this._sendBucketEntry(entry, err => {
if (!err) {
log.debug(
'sent kafka entry for bucket consumption', {
method: 'LifecycleTaskV2._getObjectList',
});
method: 'LifecycleTaskV2._getObjectList',
});
}
});
resolve(); // safe to ignore the error, we will retry lifecycle eventually
})));
}
return this._compareRulesToList(bucketData, bucketLCRules,
contents, log, done);

promises.push(util.promisify(this._compareRulesToList).bind(this)(
bucketData, bucketLCRules, contents, log,
));

return Promise.allSettled(promises).then(() => done(), done);
});
}

Expand Down Expand Up @@ -173,15 +183,19 @@
return process.nextTick(done);
}

const promises = [];

// re-queue remaining listings only once
if (nbRetries === 0) {
this._handleRemainingListings(remainings, bucketData, log);
promises.push(util.promisify(this._handleRemainingListings).bind(this)(
remainings, bucketData, log,
));
}

return this.backbeatMetadataProxy.listLifecycle(listType, params, log,
(err, contents, isTruncated, markerInfo) => {
if (err) {
return done(err);
return Promise.allSettled(promises).then(() => done(err), () => done(err));

Check warning on line 198 in extensions/lifecycle/tasks/LifecycleTaskV2.js

View check run for this annotation

Codecov / codecov/patch/Backbeat

extensions/lifecycle/tasks/LifecycleTaskV2.js#L198

Added line #L198 was not covered by tests
}

// create Set of unique keys not matching the next marker to
Expand Down Expand Up @@ -209,19 +223,21 @@
},
});

this._sendBucketEntry(entry, err => {
promises.push(new Promise(resolve => this._sendBucketEntry(entry, err => {
if (!err) {
log.debug(
'sent kafka entry for bucket consumption', {
method: 'LifecycleTaskV2._getObjectList',
});
method: 'LifecycleTaskV2._getObjectVersions',
});
}
});
resolve(); // safe to ignore the error, we will retry lifecycle eventually
})));
}
return this._compareRulesToList(bucketData, bucketLCRules,
contents, log, err => {

promises.push(new Promise((resolve, reject) => this._compareRulesToList(
bucketData, bucketLCRules, contents, log, err => {
if (err) {
return done(err);
return reject(err);

Check warning on line 240 in extensions/lifecycle/tasks/LifecycleTaskV2.js

View check run for this annotation

Codecov / codecov/patch/Backbeat

extensions/lifecycle/tasks/LifecycleTaskV2.js#L240

Added line #L240 was not covered by tests
}

if (!isTruncated) {
Expand All @@ -236,8 +252,10 @@
);
}

return done();
});
return resolve();
})));

return Promise.allSettled(promises).then(() => done(), done);
Copy link
Contributor

@williamlardier williamlardier Dec 19, 2024

Choose a reason for hiding this comment

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

With this code, in case of error in _compareRulesToList, we are ignoring the returned error, as we would have it in the "then" with the rejected status. This looks like a behavior change we don't want? We ignore errors for _sendBucketEntry but for _compareRulesToList, we actually call the reject function...

Promise.allSettled will return an array with the status for each promise, including the ones rejected:

Promise.allSettled([
  Promise.resolve(33),
  new Promise((resolve) => setTimeout(() => resolve(66), 0)),
  99,
  Promise.reject(new Error("an error")),
]).then((values) => console.log(values), err => console.log('catch', err));

[
    {
        "status": "fulfilled",
        "value": 33
    },
    {
        "status": "fulfilled",
        "value": 66
    },
    {
        "status": "fulfilled",
        "value": 99
    },
    {
        "status": "rejected",
        "reason": {}
    }
]

(and no "catch" log).

And if we are aligned, it also means this is something we do not test, or returning the error in the callback has no impact...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you are right (and I will update the code), but actually _compareRulesToList is not upposed to fail either : it calls _retryEntry, which ignores the errors. Errors on individual objects are retried a bit ; but eventually we just skip the object (or batch), relying on the periodic scan to eventually process these obejcts.

});
}

Expand Down
Loading