Skip to content

Commit 9b1e4cd

Browse files
committed
fixup on replication status for crr
1 parent c187ed4 commit 9b1e4cd

File tree

1 file changed

+40
-14
lines changed

1 file changed

+40
-14
lines changed

lib/metadata/acl.js

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,31 +36,57 @@ const acl = {
3636
},
3737

3838
addObjectACL(bucket, objectKey, objectMD, addACLParams, params, log, cb) {
39-
log.trace('updating object acl in metadata');
40-
const isAclUnchanged = Object.keys(objectMD.acl).length === Object.keys(addACLParams).length
41-
&& Object.keys(objectMD.acl).every(grant => this._aclGrantDidNotChange(grant, objectMD.acl, addACLParams));
39+
log.trace('updating object acl in metadata');
40+
const isAclUnchanged = Object.keys(objectMD.acl).length === Object.keys(addACLParams).length
41+
&& Object.keys(objectMD.acl).every(grant => this._aclGrantDidNotChange(grant, objectMD.acl, addACLParams));
4242
if (!isAclUnchanged) {
4343
/* eslint-disable no-param-reassign */
4444
objectMD.acl = addACLParams;
4545
objectMD.originOp = 's3:ObjectAcl:Put';
4646

47-
// Use storageType to determine if replication update is needed, as it is set only for
48-
// "cloud" locations. This ensures that we reset replication when CRR is used, but not
49-
// when multi-backend replication (i.e. Zenko) is used.
50-
// TODO: this should be refactored to properly update the replication info, accounting
51-
// for multiple rules and resetting the status only if needed CLDSRV-646
5247
const replicationInfo = getReplicationInfo(config, objectKey, bucket, true);
53-
if (replicationInfo && !replicationInfo.storageType) {
54-
objectMD.replicationInfo = {
55-
...objectMD.replicationInfo,
56-
...replicationInfo,
57-
};
48+
49+
// Split the storageClass and iterate over each one
50+
if (replicationInfo) {
51+
const storageClasses = replicationInfo.storageClass ? replicationInfo.storageClass.split(',') : [];
52+
const crrStorageClasses = [];
53+
const crrBackends = [];
54+
55+
// Iterate over each storage class and check isCRR
56+
storageClasses.forEach((storageClass, index) => {
57+
const trimmedStorageClass = storageClass.trim();
58+
if (config.locationConstraints &&
59+
config.locationConstraints[trimmedStorageClass] &&
60+
config.locationConstraints[trimmedStorageClass].isCRR) {
61+
// This storage class has CRR enabled, include it
62+
crrStorageClasses.push(trimmedStorageClass);
63+
64+
// Include corresponding backend if it exists
65+
if (replicationInfo.backends && replicationInfo.backends[index]) {
66+
crrBackends.push(replicationInfo.backends[index]);
67+
}
68+
}
69+
});
70+
71+
// Only set replication info for storage classes that have isCRR = true
72+
if (crrStorageClasses.length > 0) {
73+
const filteredReplicationInfo = {
74+
...replicationInfo,
75+
storageClass: crrStorageClasses.join(','),
76+
backends: crrBackends
77+
};
78+
79+
objectMD.replicationInfo = {
80+
...objectMD.replicationInfo,
81+
...filteredReplicationInfo,
82+
};
83+
}
5884
}
5985

6086
return metadata.putObjectMD(bucket.getName(), objectKey, objectMD, params, log, cb);
6187
}
6288
return cb();
63-
},
89+
}
6490

6591
parseAclFromHeaders(params, cb) {
6692
const headers = params.headers;

0 commit comments

Comments
 (0)