Skip to content

Commit 379eb6e

Browse files
committed
✨ add the versioningPreprocessing call to copy object when needed
Issue: CLDSRV-632
1 parent 4d7d1b3 commit 379eb6e

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
@@ -40,6 +40,8 @@ const { listLifecycleOrphanDeleteMarkers } = require('../api/backbeat/listLifecy
4040
const { objectDeleteInternal } = require('../api/objectDelete');
4141
const quotaUtils = require('../api/apiUtils/quotas/quotaUtils');
4242
const { handleAuthorizationResults } = require('../api/api');
43+
const { versioningPreprocessing }
44+
= require('../api/apiUtils/object/versioning');
4345

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

@@ -508,23 +510,22 @@ function putMetadata(request, response, bucketInfo, objMd, log, callback) {
508510
if (err) {
509511
return callback(err);
510512
}
513+
511514
let omVal;
515+
512516
try {
513517
omVal = JSON.parse(payload);
514518
} catch {
515-
// FIXME: add error type MalformedJSON
516519
return callback(errors.MalformedPOSTRequest);
517520
}
521+
518522
const { headers, bucketName, objectKey } = request;
519-
// check if it's metadata only operation
523+
520524
if (headers['x-scal-replication-content'] === 'METADATA') {
521525
if (!objMd) {
522-
// if the target does not exist, return an error to
523-
// backbeat, who will have to retry the operation as a
524-
// complete replication
525526
return callback(errors.ObjNotFound);
526527
}
527-
// use original data locations and encryption info
528+
528529
[
529530
'location',
530531
'x-amz-server-side-encryption',
@@ -630,6 +631,7 @@ function putMetadata(request, response, bucketInfo, objMd, log, callback) {
630631
}
631632

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

0 commit comments

Comments
 (0)