Skip to content

Commit 4293a9d

Browse files
committed
✨ retrieve the master object to copy it when needed only
Issue: CLDSRV-632
1 parent ba6d867 commit 4293a9d

3 files changed

Lines changed: 19 additions & 5 deletions

File tree

lib/api/apiUtils/object/versioning.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ function _storeNullVersionMD(bucketName, objKey, nullVersionId, objMD, log, cb)
103103
log.debug('error from metadata storing null version as new version',
104104
{ error: err });
105105
}
106+
106107
cb(err);
107108
});
108109
}
@@ -265,6 +266,7 @@ function processVersioningState(mst, vstat, nullVersionCompatMode) {
265266
}
266267
return { options, nullVersionId };
267268
}
269+
268270
// backward-compat: keep a reference to the existing null
269271
// versioned key
270272
if (mst.nullVersionId) {
@@ -295,6 +297,7 @@ function getMasterState(objMD) {
295297
if (!objMD) {
296298
return {};
297299
}
300+
298301
const mst = {
299302
exists: true,
300303
versionId: objMD.versionId,
@@ -304,10 +307,12 @@ function getMasterState(objMD) {
304307
nullVersionId: objMD.nullVersionId,
305308
nullUploadId: objMD.nullUploadId,
306309
};
310+
307311
if (objMD.location) {
308312
mst.objLocation = Array.isArray(objMD.location) ?
309313
objMD.location : [objMD.location];
310314
}
315+
311316
return mst;
312317
}
313318
/** versioningPreprocessing - return versioning information for S3 to handle

lib/routes/routeBackbeat.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ const quotaUtils = require('../api/apiUtils/quotas/quotaUtils');
4242
const { handleAuthorizationResults } = require('../api/api');
4343
const { versioningPreprocessing }
4444
= require('../api/apiUtils/object/versioning');
45+
const {promisify} = require('util');
46+
47+
const versioningPreprocessingPromised = promisify(versioningPreprocessing);
48+
metadata.getBucketAndObjectMDPromised = promisify(metadata.getBucketAndObjectMD);
4549

4650
const { CURRENT_TYPE, NON_CURRENT_TYPE, ORPHAN_DM_TYPE } = constants.lifecycleListing;
4751

@@ -612,6 +616,7 @@ function putMetadata(request, response, bucketInfo, objMd, log, callback) {
612616
// To prevent this, the versionId field is only included in options when it is defined.
613617
if (versionId !== undefined) {
614618
options.versionId = versionId;
619+
615620
// In the MongoDB metadata backend, setting the versionId option leads to the creation
616621
// or update of the version object, the master object is only updated if its versionId
617622
// is the same as the version. This can lead to inconsistencies when replicating objects
@@ -642,6 +647,7 @@ function putMetadata(request, response, bucketInfo, objMd, log, callback) {
642647
if (!request.query?.accountId) {
643648
return next();
644649
}
650+
645651
return getCanonicalIdsByAccountId(request.query.accountId, log, (err, res) => {
646652
if (err) {
647653
return next(err);
@@ -651,12 +657,13 @@ function putMetadata(request, response, bucketInfo, objMd, log, callback) {
651657
return next();
652658
});
653659
},
654-
next => {
655-
if (!versionId) {
656-
return next();
660+
async () => {
661+
if (versioning && !objMd) {
662+
const masterObjectAndBucket =
663+
await metadata.getBucketAndObjectMDPromised(bucketName, objectKey, {}, log);
664+
const masterObject = JSON.parse(masterObjectAndBucket.obj);
665+
await versioningPreprocessingPromised(bucketName, bucketInfo, objectKey, masterObject, log);
657666
}
658-
659-
return versioningPreprocessing(bucketName, bucketInfo, objectKey, objMd, log, next);
660667
},
661668
next => {
662669
log.trace('putting object version', {

tests/multipleBackend/routes/routeBackbeatForReplication.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,7 @@ describe(`backbeat routes for replication (${name})`, () => {
958958
if (err) {
959959
return next(err);
960960
}
961+
961962
versionId = data.VersionId;
962963
return next();
963964
}),
@@ -974,6 +975,7 @@ describe(`backbeat routes for replication (${name})`, () => {
974975
if (err) {
975976
return next(err);
976977
}
978+
977979
objMD = objectMDWithUpdatedAccountInfo(data, src === dst ? null : dstAccountInfo);
978980
return next();
979981
}),

0 commit comments

Comments
 (0)