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

improvement: S3C-3684 [TEMPORARY] skip replication already COMPLETED #1228

Draft
wants to merge 2 commits into
base: development/7.4
Choose a base branch
from
Draft
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
78 changes: 63 additions & 15 deletions extensions/replication/tasks/ReplicateObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ const AccountCredentials =
const RoleCredentials =
require('../../../lib/credentials/RoleCredentials');
const { metricsExtension, metricsTypeProcessed } = require('../constants');
const ObjectQueueEntry = require('../utils/ObjectQueueEntry');

const MPU_CONC_LIMIT = 10;

const errorAlreadyCompleted = {};

function _extractAccountIdFromRole(role) {
return role.split(':')[4];
}
Expand Down Expand Up @@ -289,22 +292,61 @@ class ReplicateObject extends BackbeatTask {
});
}

_refreshSourceEntry(sourceEntry, log, cb) {
const params = {
Bucket: sourceEntry.getBucket(),
Key: sourceEntry.getObjectKey(),
VersionId: sourceEntry.getEncodedVersionId(),
};
return this.backbeatSource.getMetadata(params, (err, blob) => {
if (err) {
err.origin = 'source';
log.error('error getting metadata blob from S3', {
method: 'ReplicateObject._refreshSourceEntry',
error: err,
});
return cb(err);
}
const parsedEntry = ObjectQueueEntry.createFromBlob(blob.Body);
if (parsedEntry.error) {
log.error('error parsing metadata blob', {
error: parsedEntry.error,
method: 'ReplicateObject._refreshSourceEntry',
});
return cb(errors.InternalError.
customizeDescription('error parsing metadata blob'));
}
const refreshedEntry = new ObjectQueueEntry(sourceEntry.getBucket(),
sourceEntry.getObjectVersionedKey(), parsedEntry.result);
return cb(null, refreshedEntry);
});
}

_getAndPutData(sourceEntry, destEntry, log, cb) {
log.debug('replicating data', { entry: sourceEntry.getLogInfo() });
if (sourceEntry.getLocation().some(part => {
const partObj = new ObjectMDLocation(part);
return partObj.getDataStoreETag() === undefined;
})) {
log.error('cannot replicate object without dataStoreETag ' +
'property',
{ method: 'ReplicateObject._getAndPutData',
entry: sourceEntry.getLogInfo() });
return cb(errors.InvalidObjectState);
}
const locations = sourceEntry.getReducedLocations();
return async.mapLimit(locations, MPU_CONC_LIMIT, (part, done) => {
this._getAndPutPart(sourceEntry, destEntry, part, log, done);
}, cb);
this._refreshSourceEntry(sourceEntry, log, (err, refreshedEntry) => {
if (err) {
return cb(err);
}
const status = refreshedEntry.getReplicationSiteStatus(this.site);
if (status === 'COMPLETED') {
return cb(errorAlreadyCompleted);
}
log.debug('replicating data', { entry: sourceEntry.getLogInfo() });
if (sourceEntry.getLocation().some(part => {
const partObj = new ObjectMDLocation(part);
return partObj.getDataStoreETag() === undefined;
})) {
log.error('cannot replicate object without dataStoreETag ' +
'property',
{ method: 'ReplicateObject._getAndPutData',
entry: sourceEntry.getLogInfo() });
return cb(errors.InvalidObjectState);
}
const locations = sourceEntry.getReducedLocations();
return async.mapLimit(locations, MPU_CONC_LIMIT, (part, done) => {
this._getAndPutPart(sourceEntry, destEntry, part, log, done);
}, cb);
});
}

_getAndPutPartOnce(sourceEntry, destEntry, part, log, done) {
Expand Down Expand Up @@ -578,6 +620,12 @@ class ReplicateObject extends BackbeatTask {
error: err.description });
return done();
}
if (err === errorAlreadyCompleted) {
log.warn('replication skipped: ' +
'source object version already COMPLETED',
{ entry: sourceEntry.getLogInfo() });
return done();
}
if (err.ObjNotFound || err.code === 'ObjNotFound') {
if (err.origin === 'source') {
log.info('replication skipped: ' +
Expand Down