diff --git a/lib/metadata/acl.js b/lib/metadata/acl.js index f48ab7aa42..875de7f932 100644 --- a/lib/metadata/acl.js +++ b/lib/metadata/acl.js @@ -44,17 +44,43 @@ const acl = { objectMD.acl = addACLParams; objectMD.originOp = 's3:ObjectAcl:Put'; - // Use storageType to determine if replication update is needed, as it is set only for - // "cloud" locations. This ensures that we reset replication when CRR is used, but not - // when multi-backend replication (i.e. Zenko) is used. - // TODO: this should be refactored to properly update the replication info, accounting - // for multiple rules and resetting the status only if needed CLDSRV-646 const replicationInfo = getReplicationInfo(config, objectKey, bucket, true); - if (replicationInfo && !replicationInfo.storageType) { - objectMD.replicationInfo = { - ...objectMD.replicationInfo, - ...replicationInfo, - }; + + // Split the storageClass and iterate over each one + if (replicationInfo) { + const storageClasses = replicationInfo.storageClass ? replicationInfo.storageClass.split(',') : []; + const crrStorageClasses = []; + const crrBackends = []; + + // Iterate over each storage class and check isCRR + storageClasses.forEach((storageClass, index) => { + const trimmedStorageClass = storageClass.trim(); + if (config.locationConstraints && + config.locationConstraints[trimmedStorageClass] && + config.locationConstraints[trimmedStorageClass].isCRR) { + // This storage class has CRR enabled, include it + crrStorageClasses.push(trimmedStorageClass); + + // Include corresponding backend if it exists + if (replicationInfo.backends && replicationInfo.backends[index]) { + crrBackends.push(replicationInfo.backends[index]); + } + } + }); + + // Only set replication info for storage classes that have isCRR = true + if (crrStorageClasses.length > 0) { + const filteredReplicationInfo = { + ...replicationInfo, + storageClass: crrStorageClasses.join(','), + backends: crrBackends + }; + + objectMD.replicationInfo = { + ...objectMD.replicationInfo, + ...filteredReplicationInfo, + }; + } } return metadata.putObjectMD(bucket.getName(), objectKey, objectMD, params, log, cb); diff --git a/tests/unit/api/objectReplicationMD.js b/tests/unit/api/objectReplicationMD.js index 48451b43ce..e0b8d64ca0 100644 --- a/tests/unit/api/objectReplicationMD.js +++ b/tests/unit/api/objectReplicationMD.js @@ -367,6 +367,7 @@ describe('Replication object MD without bucket replication config', () => { config.locationConstraints['zenko'] = { ...config.locationConstraints['zenko'], type: '', + isCRR: true, }; async.series([