Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/api/apiUtils/object/createAndStoreObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,14 @@ function createAndStoreObject(
size,
headers,
isDeleteMarker,
replicationInfo: getReplicationInfo(config, objectKey, bucketMD, false, size, null, null, authInfo),
replicationInfo: getReplicationInfo({
s3config: config,
objKey: objectKey,
bucketMD,
isMD: false,
objSize: size,
authInfo,
}),
overheadField,
log,
};
Expand Down
47 changes: 25 additions & 22 deletions lib/api/apiUtils/object/getReplicationInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,30 +56,33 @@ function _canUserReplicate(authInfo) {
* decides the `content` array based on the operation kind, and
* stitches the result into a `replicationInfo` envelope.
*
* @param {object} s3config - Cloudserver configuration object
* @param {object} s3config.locationConstraints - Configured map of location constraints
* @param {object[]} s3config.replicationEndpoints - Configured replication endpoints
* @param {string} objKey - The key of the object
* @param {object} bucketMD - The bucket metadata
* @param {boolean} isMD - Whether the operation is only updating metadata
* @param {boolean} objSize - The size, in bytes, of the object being PUT
* @param {string} operationType - The type of operation to replicate
* @param {object} objectMD - The object metadata
* @param {AuthInfo} [authInfo] - authentication info of object owner
* @param {string[]} [blockedSiteTypes=[]] - location types to exclude from the returned backends
* @param {object} params - Named parameters
* @param {object} params.s3config - Cloudserver configuration object
* @param {object} params.s3config.locationConstraints - Configured map of location constraints
* @param {object[]} params.s3config.replicationEndpoints - Configured replication endpoints
* @param {string} params.objKey - The key of the object
* @param {object} params.bucketMD - The bucket metadata
* @param {boolean} params.isMD - Whether the operation is only updating metadata
* @param {number} [params.objSize] - The size, in bytes, of the object being PUT (irrelevant when isMD is true)
* @param {string} [params.operationType] - The type of operation to replicate
* @param {object} [params.objectMD] - The object metadata
* @param {AuthInfo} [params.authInfo] - authentication info of object owner
* @param {string[]} [params.blockedSiteTypes=[]] - location types to exclude from the returned backends
* @return {object|undefined}
*/
function getReplicationInfo(
s3config,
objKey,
bucketMD,
isMD,
objSize,
operationType,
objectMD,
authInfo,
blockedSiteTypes = [],
) {
function getReplicationInfo(params) {
const {
s3config,
objKey,
bucketMD,
isMD,
objSize,
operationType,
objectMD,
authInfo,
blockedSiteTypes = [],
} = params;

const config = bucketMD.getReplicationConfiguration();
if (!config || !_canUserReplicate(authInfo)) {
return undefined;
Expand Down
16 changes: 8 additions & 8 deletions lib/api/completeMultipartUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -803,14 +803,14 @@ function completeMultipartUpload(authInfo, request, log, callback) {
size: calculatedSize,
multipart: true,
isDeleteMarker: false,
replicationInfo: getReplicationInfo(
config,
objectKey,
destBucket,
false,
calculatedSize,
REPLICATION_ACTION,
),
replicationInfo: getReplicationInfo({
s3config: config,
objKey: objectKey,
bucketMD: destBucket,
isMD: false,
objSize: calculatedSize,
operationType: REPLICATION_ACTION,
}),
originOp: 's3:ObjectCreated:CompleteMultipartUpload',
overheadField: constants.overheadField,
log,
Expand Down
8 changes: 7 additions & 1 deletion lib/api/objectCopy.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,13 @@ function _prepMetadata(
lastModifiedDate: new Date().toJSON(),
tagging,
taggingCopy,
replicationInfo: getReplicationInfo(config, objectKey, destBucketMD, false, sourceObjMD['content-length']),
replicationInfo: getReplicationInfo({
s3config: config,
objKey: objectKey,
bucketMD: destBucketMD,
isMD: false,
objSize: sourceObjMD['content-length'],
}),
locationMatch,
originOp: 's3:ObjectCreated:Copy',
};
Expand Down
16 changes: 8 additions & 8 deletions lib/api/objectDeleteTagging.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ function objectDeleteTagging(authInfo, request, log, callback) {
// eslint-disable-next-line no-param-reassign
objectMD.tags = {};
const params = getVersionSpecificMetadataOptions(objectMD, config.nullVersionCompatMode);
const replicationInfo = getReplicationInfo(
config,
objectKey,
bucket,
true,
0,
REPLICATION_ACTION,
const replicationInfo = getReplicationInfo({
s3config: config,
objKey: objectKey,
bucketMD: bucket,
isMD: true,
objSize: 0,
operationType: REPLICATION_ACTION,
objectMD,
);
});
if (replicationInfo) {
// eslint-disable-next-line no-param-reassign
objectMD.replicationInfo = Object.assign({}, objectMD.replicationInfo, replicationInfo);
Expand Down
16 changes: 8 additions & 8 deletions lib/api/objectPutLegalHold.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ function objectPutLegalHold(authInfo, request, log, callback) {
// eslint-disable-next-line no-param-reassign
objectMD.legalHold = legalHold;
const params = getVersionSpecificMetadataOptions(objectMD, config.nullVersionCompatMode);
const replicationInfo = getReplicationInfo(
config,
objectKey,
bucket,
true,
0,
REPLICATION_ACTION,
const replicationInfo = getReplicationInfo({
s3config: config,
objKey: objectKey,
bucketMD: bucket,
isMD: true,
objSize: 0,
operationType: REPLICATION_ACTION,
objectMD,
);
});
if (replicationInfo) {
// eslint-disable-next-line no-param-reassign
objectMD.replicationInfo = Object.assign({}, objectMD.replicationInfo, replicationInfo);
Expand Down
16 changes: 8 additions & 8 deletions lib/api/objectPutRetention.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ function objectPutRetention(authInfo, request, log, callback) {
objectMD.retentionMode = retentionInfo.mode;
objectMD.retentionDate = retentionInfo.date;
const params = getVersionSpecificMetadataOptions(objectMD, config.nullVersionCompatMode);
const replicationInfo = getReplicationInfo(
config,
objectKey,
bucket,
true,
0,
REPLICATION_ACTION,
const replicationInfo = getReplicationInfo({
s3config: config,
objKey: objectKey,
bucketMD: bucket,
isMD: true,
objSize: 0,
operationType: REPLICATION_ACTION,
objectMD,
);
});
if (replicationInfo) {
objectMD.replicationInfo = Object.assign({}, objectMD.replicationInfo, replicationInfo);
bumpMicroVersionId(objectMD);
Expand Down
16 changes: 8 additions & 8 deletions lib/api/objectPutTagging.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ function objectPutTagging(authInfo, request, log, callback) {
// eslint-disable-next-line no-param-reassign
objectMD.tags = tags;
const params = getVersionSpecificMetadataOptions(objectMD, config.nullVersionCompatMode);
const replicationInfo = getReplicationInfo(
config,
objectKey,
bucket,
true,
0,
REPLICATION_ACTION,
const replicationInfo = getReplicationInfo({
s3config: config,
objKey: objectKey,
bucketMD: bucket,
isMD: true,
objSize: 0,
operationType: REPLICATION_ACTION,
objectMD,
);
});
if (replicationInfo) {
// eslint-disable-next-line no-param-reassign
objectMD.replicationInfo = Object.assign({}, objectMD.replicationInfo, replicationInfo);
Expand Down
7 changes: 6 additions & 1 deletion lib/metadata/acl.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ const acl = {
const hasDestRole = b => !!b.role;
const sameBackend = (a, b) => a.site === b.site && a.destination === b.destination && a.role === b.role;

const replicationInfo = getReplicationInfo(config, objectKey, bucket, true);
const replicationInfo = getReplicationInfo({
s3config: config,
objKey: objectKey,
bucketMD: bucket,
isMD: true,
});
if (replicationInfo && replicationInfo.backends.some(hasDestRole)) {
const backends = replicationInfo.backends
.map(b => {
Expand Down
17 changes: 7 additions & 10 deletions lib/routes/routeBackbeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -862,17 +862,14 @@ function putMetadata(request, response, bucketInfo, objMd, log, callback) {
const isMDOnly = headers['x-scal-replication-content'] === 'METADATA';
const objSize = omVal['content-length'] || 0;

const nextReplInfo = getReplicationInfo(
config,
objectKey,
bucketInfo,
isMDOnly,
const nextReplInfo = getReplicationInfo({
s3config: config,
objKey: objectKey,
bucketMD: bucketInfo,
isMD: isMDOnly,
objSize,
null,
null,
null,
constants.crrCascadeBlockedLocationTypes,
);
blockedSiteTypes: constants.crrCascadeBlockedLocationTypes,
});

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

Expand Down
79 changes: 38 additions & 41 deletions tests/unit/api/apiUtils/getReplicationInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ function _getObjectReplicationInfo(s3config, replicationConfig, key, objectMD) {
null,
replicationConfig,
);
return getReplicationInfo(s3config, key || 'fookey', bucketInfo, true, 123, null, objectMD || null);
return getReplicationInfo({
s3config,
objKey: key || 'fookey',
bucketMD: bucketInfo,
isMD: true,
objSize: 123,
objectMD: objectMD || null,
});
}

const TEST_CONFIG = {
Expand Down Expand Up @@ -238,16 +245,14 @@ describe('getReplicationInfo helper', () => {
canonicalID: 'abcdef/lifecycle',
accountDisplayName: 'Lifecycle Service Account',
});
const replicationInfo = getReplicationInfo(
TEST_CONFIG,
'fookey',
bucketInfo,
true,
123,
null,
null,
const replicationInfo = getReplicationInfo({
s3config: TEST_CONFIG,
objKey: 'fookey',
bucketMD: bucketInfo,
isMD: true,
objSize: 123,
authInfo,
);
});
assert.deepStrictEqual(replicationInfo, undefined);
});

Expand Down Expand Up @@ -283,16 +288,14 @@ describe('getReplicationInfo helper', () => {
canonicalID: 'abcdef/md-ingestion',
accountDisplayName: 'Metadata Ingestion Service Account',
});
const replicationInfo = getReplicationInfo(
TEST_CONFIG,
'fookey',
bucketInfo,
true,
123,
null,
null,
const replicationInfo = getReplicationInfo({
s3config: TEST_CONFIG,
objKey: 'fookey',
bucketMD: bucketInfo,
isMD: true,
objSize: 123,
authInfo,
);
});
assert.deepStrictEqual(replicationInfo, {
status: 'PENDING',
backends: [
Expand Down Expand Up @@ -629,10 +632,10 @@ describe('getReplicationInfo helper', () => {
],
destination: 'tosomewhere',
};
const info = getReplicationInfo(
configWithRing,
'fookey',
new BucketInfo(
const info = getReplicationInfo({
s3config: configWithRing,
objKey: 'fookey',
bucketMD: new BucketInfo(
'b',
'id',
'name',
Expand All @@ -648,13 +651,10 @@ describe('getReplicationInfo helper', () => {
null,
replicationConfig,
),
true,
123,
null,
null,
null,
[RING_TYPE],
);
isMD: true,
objSize: 123,
blockedSiteTypes: [RING_TYPE],
});
assert.strictEqual(info.backends.length, 1);
assert.strictEqual(info.backends[0].site, 'awsbackend');
});
Expand All @@ -665,10 +665,10 @@ describe('getReplicationInfo helper', () => {
rules: [{ prefix: '', enabled: true, storageClass: 'ring-site' }],
destination: 'tosomewhere',
};
const info = getReplicationInfo(
configWithRing,
'fookey',
new BucketInfo(
const info = getReplicationInfo({
s3config: configWithRing,
objKey: 'fookey',
bucketMD: new BucketInfo(
'b',
'id',
'name',
Expand All @@ -684,13 +684,10 @@ describe('getReplicationInfo helper', () => {
null,
replicationConfig,
),
true,
123,
null,
null,
null,
[RING_TYPE],
);
isMD: true,
objSize: 123,
blockedSiteTypes: [RING_TYPE],
});
assert.strictEqual(info, undefined);
});
});
Expand Down
Loading