Skip to content

Commit e42d8b6

Browse files
refactor getReplicationInfo into object parameters
Issue: CLDSRV-950
1 parent 0d08680 commit e42d8b6

11 files changed

Lines changed: 131 additions & 116 deletions

lib/api/apiUtils/object/createAndStoreObject.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,14 @@ function createAndStoreObject(
179179
size,
180180
headers,
181181
isDeleteMarker,
182-
replicationInfo: getReplicationInfo(config, objectKey, bucketMD, false, size, null, null, authInfo),
182+
replicationInfo: getReplicationInfo({
183+
s3config: config,
184+
objKey: objectKey,
185+
bucketMD,
186+
isMD: false,
187+
objSize: size,
188+
authInfo,
189+
}),
183190
overheadField,
184191
log,
185192
};

lib/api/apiUtils/object/getReplicationInfo.js

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,30 +56,33 @@ function _canUserReplicate(authInfo) {
5656
* decides the `content` array based on the operation kind, and
5757
* stitches the result into a `replicationInfo` envelope.
5858
*
59-
* @param {object} s3config - Cloudserver configuration object
60-
* @param {object} s3config.locationConstraints - Configured map of location constraints
61-
* @param {object[]} s3config.replicationEndpoints - Configured replication endpoints
62-
* @param {string} objKey - The key of the object
63-
* @param {object} bucketMD - The bucket metadata
64-
* @param {boolean} isMD - Whether the operation is only updating metadata
65-
* @param {boolean} objSize - The size, in bytes, of the object being PUT
66-
* @param {string} operationType - The type of operation to replicate
67-
* @param {object} objectMD - The object metadata
68-
* @param {AuthInfo} [authInfo] - authentication info of object owner
69-
* @param {string[]} [blockedSiteTypes=[]] - location types to exclude from the returned backends
59+
* @param {object} params - Named parameters
60+
* @param {object} params.s3config - Cloudserver configuration object
61+
* @param {object} params.s3config.locationConstraints - Configured map of location constraints
62+
* @param {object[]} params.s3config.replicationEndpoints - Configured replication endpoints
63+
* @param {string} params.objKey - The key of the object
64+
* @param {object} params.bucketMD - The bucket metadata
65+
* @param {boolean} params.isMD - Whether the operation is only updating metadata
66+
* @param {number} params.objSize - The size, in bytes, of the object being PUT
67+
* @param {string} [params.operationType] - The type of operation to replicate
68+
* @param {object} [params.objectMD] - The object metadata
69+
* @param {AuthInfo} [params.authInfo] - authentication info of object owner
70+
* @param {string[]} [params.blockedSiteTypes=[]] - location types to exclude from the returned backends
7071
* @return {object|undefined}
7172
*/
72-
function getReplicationInfo(
73-
s3config,
74-
objKey,
75-
bucketMD,
76-
isMD,
77-
objSize,
78-
operationType,
79-
objectMD,
80-
authInfo,
81-
blockedSiteTypes = [],
82-
) {
73+
function getReplicationInfo(params) {
74+
const {
75+
s3config,
76+
objKey,
77+
bucketMD,
78+
isMD,
79+
objSize,
80+
operationType,
81+
objectMD,
82+
authInfo,
83+
blockedSiteTypes = [],
84+
} = params;
85+
8386
const config = bucketMD.getReplicationConfiguration();
8487
if (!config || !_canUserReplicate(authInfo)) {
8588
return undefined;

lib/api/completeMultipartUpload.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -803,14 +803,14 @@ function completeMultipartUpload(authInfo, request, log, callback) {
803803
size: calculatedSize,
804804
multipart: true,
805805
isDeleteMarker: false,
806-
replicationInfo: getReplicationInfo(
807-
config,
808-
objectKey,
809-
destBucket,
810-
false,
811-
calculatedSize,
812-
REPLICATION_ACTION,
813-
),
806+
replicationInfo: getReplicationInfo({
807+
s3config: config,
808+
objKey: objectKey,
809+
bucketMD: destBucket,
810+
isMD: false,
811+
objSize: calculatedSize,
812+
operationType: REPLICATION_ACTION,
813+
}),
814814
originOp: 's3:ObjectCreated:CompleteMultipartUpload',
815815
overheadField: constants.overheadField,
816816
log,

lib/api/objectCopy.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,13 @@ function _prepMetadata(
394394
lastModifiedDate: new Date().toJSON(),
395395
tagging,
396396
taggingCopy,
397-
replicationInfo: getReplicationInfo(config, objectKey, destBucketMD, false, sourceObjMD['content-length']),
397+
replicationInfo: getReplicationInfo({
398+
s3config: config,
399+
objKey: objectKey,
400+
bucketMD: destBucketMD,
401+
isMD: false,
402+
objSize: sourceObjMD['content-length'],
403+
}),
398404
locationMatch,
399405
originOp: 's3:ObjectCreated:Copy',
400406
};

lib/api/objectDeleteTagging.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ function objectDeleteTagging(authInfo, request, log, callback) {
8282
// eslint-disable-next-line no-param-reassign
8383
objectMD.tags = {};
8484
const params = getVersionSpecificMetadataOptions(objectMD, config.nullVersionCompatMode);
85-
const replicationInfo = getReplicationInfo(
86-
config,
87-
objectKey,
88-
bucket,
89-
true,
90-
0,
91-
REPLICATION_ACTION,
85+
const replicationInfo = getReplicationInfo({
86+
s3config: config,
87+
objKey: objectKey,
88+
bucketMD: bucket,
89+
isMD: true,
90+
objSize: 0,
91+
operationType: REPLICATION_ACTION,
9292
objectMD,
93-
);
93+
});
9494
if (replicationInfo) {
9595
// eslint-disable-next-line no-param-reassign
9696
objectMD.replicationInfo = Object.assign({}, objectMD.replicationInfo, replicationInfo);

lib/api/objectPutLegalHold.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ function objectPutLegalHold(authInfo, request, log, callback) {
9494
// eslint-disable-next-line no-param-reassign
9595
objectMD.legalHold = legalHold;
9696
const params = getVersionSpecificMetadataOptions(objectMD, config.nullVersionCompatMode);
97-
const replicationInfo = getReplicationInfo(
98-
config,
99-
objectKey,
100-
bucket,
101-
true,
102-
0,
103-
REPLICATION_ACTION,
97+
const replicationInfo = getReplicationInfo({
98+
s3config: config,
99+
objKey: objectKey,
100+
bucketMD: bucket,
101+
isMD: true,
102+
objSize: 0,
103+
operationType: REPLICATION_ACTION,
104104
objectMD,
105-
);
105+
});
106106
if (replicationInfo) {
107107
// eslint-disable-next-line no-param-reassign
108108
objectMD.replicationInfo = Object.assign({}, objectMD.replicationInfo, replicationInfo);

lib/api/objectPutRetention.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,15 @@ function objectPutRetention(authInfo, request, log, callback) {
116116
objectMD.retentionMode = retentionInfo.mode;
117117
objectMD.retentionDate = retentionInfo.date;
118118
const params = getVersionSpecificMetadataOptions(objectMD, config.nullVersionCompatMode);
119-
const replicationInfo = getReplicationInfo(
120-
config,
121-
objectKey,
122-
bucket,
123-
true,
124-
0,
125-
REPLICATION_ACTION,
119+
const replicationInfo = getReplicationInfo({
120+
s3config: config,
121+
objKey: objectKey,
122+
bucketMD: bucket,
123+
isMD: true,
124+
objSize: 0,
125+
operationType: REPLICATION_ACTION,
126126
objectMD,
127-
);
127+
});
128128
if (replicationInfo) {
129129
objectMD.replicationInfo = Object.assign({}, objectMD.replicationInfo, replicationInfo);
130130
bumpMicroVersionId(objectMD);

lib/api/objectPutTagging.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ function objectPutTagging(authInfo, request, log, callback) {
8585
// eslint-disable-next-line no-param-reassign
8686
objectMD.tags = tags;
8787
const params = getVersionSpecificMetadataOptions(objectMD, config.nullVersionCompatMode);
88-
const replicationInfo = getReplicationInfo(
89-
config,
90-
objectKey,
91-
bucket,
92-
true,
93-
0,
94-
REPLICATION_ACTION,
88+
const replicationInfo = getReplicationInfo({
89+
s3config: config,
90+
objKey: objectKey,
91+
bucketMD: bucket,
92+
isMD: true,
93+
objSize: 0,
94+
operationType: REPLICATION_ACTION,
9595
objectMD,
96-
);
96+
});
9797
if (replicationInfo) {
9898
// eslint-disable-next-line no-param-reassign
9999
objectMD.replicationInfo = Object.assign({}, objectMD.replicationInfo, replicationInfo);

lib/metadata/acl.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ const acl = {
5858
const hasDestRole = b => !!b.role;
5959
const sameBackend = (a, b) => a.site === b.site && a.destination === b.destination && a.role === b.role;
6060

61-
const replicationInfo = getReplicationInfo(config, objectKey, bucket, true);
61+
const replicationInfo = getReplicationInfo({
62+
s3config: config,
63+
objKey: objectKey,
64+
bucketMD: bucket,
65+
isMD: true,
66+
});
6267
if (replicationInfo && replicationInfo.backends.some(hasDestRole)) {
6368
const backends = replicationInfo.backends
6469
.map(b => {

lib/routes/routeBackbeat.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -862,17 +862,14 @@ function putMetadata(request, response, bucketInfo, objMd, log, callback) {
862862
const isMDOnly = headers['x-scal-replication-content'] === 'METADATA';
863863
const objSize = omVal['content-length'] || 0;
864864

865-
const nextReplInfo = getReplicationInfo(
866-
config,
867-
objectKey,
868-
bucketInfo,
869-
isMDOnly,
865+
const nextReplInfo = getReplicationInfo({
866+
s3config: config,
867+
objKey: objectKey,
868+
bucketMD: bucketInfo,
869+
isMD: isMDOnly,
870870
objSize,
871-
null,
872-
null,
873-
null,
874-
constants.crrCascadeBlockedLocationTypes,
875-
);
871+
blockedSiteTypes: constants.crrCascadeBlockedLocationTypes,
872+
});
876873

877874
const hasNextHop = nextReplInfo && nextReplInfo.backends.length > 0;
878875

0 commit comments

Comments
 (0)