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 2 commits 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
27 changes: 16 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());

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,12 @@
);
}

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

return Promise.allSettled(promises).then(results => done(
results.find(r => r.status === 'rejected')?.reason
));
});
}

Expand Down
106 changes: 64 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));

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,24 @@
},
});

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(results => done(
results.find(r => r.status === 'rejected')?.reason
));
});
}

Expand Down Expand Up @@ -173,15 +185,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));

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

View check run for this annotation

Codecov / codecov/patch/Backbeat

extensions/lifecycle/tasks/LifecycleTaskV2.js#L200

Added line #L200 was not covered by tests
}

// create Set of unique keys not matching the next marker to
Expand Down Expand Up @@ -209,19 +225,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 242 in extensions/lifecycle/tasks/LifecycleTaskV2.js

View check run for this annotation

Codecov / codecov/patch/Backbeat

extensions/lifecycle/tasks/LifecycleTaskV2.js#L242

Added line #L242 was not covered by tests
}

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

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

return Promise.allSettled(promises).then(results => done(
results.find(r => r.status === 'rejected')?.reason
));
});
}

Expand Down
Loading