Skip to content

Commit 507689f

Browse files
committed
✨ add the versioningPreprocessing call to copy object when needed
Issue: CLDSRV-632
1 parent fe01aad commit 507689f

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

lib/api/apiUtils/object/createAndStoreObject.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ function createAndStoreObject(bucketName, bucketMD, objectKey, objMD, authInfo,
218218
metadataStoreParams.contentMD5 = constants.emptyFileMd5;
219219
return next(null, null, null);
220220
}
221+
221222
// Handle mdOnlyHeader as a metadata only operation. If
222223
// the object in question is actually 0 byte or has a body size
223224
// then handle normally.
@@ -244,6 +245,7 @@ function createAndStoreObject(bucketName, bucketMD, objectKey, objMD, authInfo,
244245
return next(null, dataGetInfo, _md5);
245246
}
246247
}
248+
247249
return dataStore(objectKeyContext, cipherBundle, request, size,
248250
streamingV4Params, backendInfo, log, next);
249251
},
@@ -280,10 +282,12 @@ function createAndStoreObject(bucketName, bucketMD, objectKey, objMD, authInfo,
280282
const options = overwritingVersioning(objMD, metadataStoreParams);
281283
return process.nextTick(() => next(null, options, infoArr));
282284
}
285+
283286
if (!bucketMD.isVersioningEnabled() && objMD?.archive?.archiveInfo) {
284287
// Ensure we trigger a "delete" event in the oplog for the previously archived object
285288
metadataStoreParams.needOplogUpdate = 's3:ReplaceArchivedObject';
286289
}
290+
287291
return versioningPreprocessing(bucketName, bucketMD,
288292
metadataStoreParams.objectKey, objMD, log, (err, options) => {
289293
if (err) {
@@ -316,9 +320,11 @@ function createAndStoreObject(bucketName, bucketMD, objectKey, objMD, authInfo,
316320
metadataStoreParams.versioning = options.versioning;
317321
metadataStoreParams.isNull = options.isNull;
318322
metadataStoreParams.deleteNullKey = options.deleteNullKey;
323+
319324
if (options.extraMD) {
320325
Object.assign(metadataStoreParams, options.extraMD);
321326
}
327+
322328
return _storeInMDandDeleteData(bucketName, infoArr,
323329
cipherBundle, metadataStoreParams,
324330
options.dataToDelete, log, requestMethod, next);

lib/api/apiUtils/object/versioning.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,14 +329,15 @@ function versioningPreprocessing(bucketName, bucketMD, objectKey, objMD,
329329
log, callback) {
330330
const mst = getMasterState(objMD);
331331
const vCfg = bucketMD.getVersioningConfiguration();
332-
// bucket is not versioning configured
332+
333333
if (!vCfg) {
334334
const options = { dataToDelete: mst.objLocation };
335335
return process.nextTick(callback, null, options);
336336
}
337-
// bucket is versioning configured
337+
338338
const { options, nullVersionId, delOptions } =
339339
processVersioningState(mst, vCfg.Status, config.nullVersionCompatMode);
340+
340341
return async.series([
341342
function storeNullVersionMD(next) {
342343
if (!nullVersionId) {

lib/routes/routeBackbeat.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ const { listLifecycleNonCurrents } = require('../api/backbeat/listLifecycleNonCu
3939
const { listLifecycleOrphanDeleteMarkers } = require('../api/backbeat/listLifecycleOrphanDeleteMarkers');
4040
const { objectDeleteInternal } = require('../api/objectDelete');
4141
const quotaUtils = require('../api/apiUtils/quotas/quotaUtils');
42+
const { versioningPreprocessing }
43+
= require('../api/apiUtils/object/versioning');
4244

4345
const { CURRENT_TYPE, NON_CURRENT_TYPE, ORPHAN_DM_TYPE } = constants.lifecycleListing;
4446

@@ -507,23 +509,22 @@ function putMetadata(request, response, bucketInfo, objMd, log, callback) {
507509
if (err) {
508510
return callback(err);
509511
}
512+
510513
let omVal;
514+
511515
try {
512516
omVal = JSON.parse(payload);
513517
} catch {
514-
// FIXME: add error type MalformedJSON
515518
return callback(errors.MalformedPOSTRequest);
516519
}
520+
517521
const { headers, bucketName, objectKey } = request;
518-
// check if it's metadata only operation
522+
519523
if (headers['x-scal-replication-content'] === 'METADATA') {
520524
if (!objMd) {
521-
// if the target does not exist, return an error to
522-
// backbeat, who will have to retry the operation as a
523-
// complete replication
524525
return callback(errors.ObjNotFound);
525526
}
526-
// use original data locations and encryption info
527+
527528
[
528529
'location',
529530
'x-amz-server-side-encryption',
@@ -629,6 +630,7 @@ function putMetadata(request, response, bucketInfo, objMd, log, callback) {
629630
}
630631

631632
return async.series([
633+
next => versioningPreprocessing(bucketName, bucketInfo, objectKey, objMd, log, next),
632634
// Zenko's CRR delegates replacing the account
633635
// information to the destination's Cloudserver, as
634636
// Vault admin APIs are not exposed externally.

0 commit comments

Comments
 (0)