-
Notifications
You must be signed in to change notification settings - Fork 255
Add CRR Cascaded capabilities #6179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SylvainSenechal
wants to merge
2
commits into
development/9.4
Choose a base branch
from
improvement/CLDSRV-897
base: development/9.4
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+556
−80
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ const joi = require('@hapi/joi'); | |
| const backbeatProxy = httpProxy.createProxyServer({ | ||
| ignorePath: true, | ||
| }); | ||
| const { auth, errors, errorInstances, s3middleware, s3routes, models, storage } = | ||
| const { auth, errors, errorInstances, s3middleware, s3routes, models, storage, versioning } = | ||
| require('arsenal'); | ||
|
|
||
| const { responseJSONBody } = s3routes.routesUtils; | ||
|
|
@@ -25,6 +25,7 @@ const { dataStore } = require('../api/apiUtils/object/storeObject'); | |
| const prepareRequestContexts = require( | ||
| '../api/apiUtils/authorization/prepareRequestContexts'); | ||
| const { decodeVersionId } = require('../api/apiUtils/object/versioning'); | ||
| const { decode, encode, checkCrrCascadeEvent } = versioning.VersionID; | ||
| const locationKeysHaveChanged | ||
| = require('../api/apiUtils/object/locationKeysHaveChanged'); | ||
| const { standardMetadataValidateBucketAndObj, | ||
|
|
@@ -47,6 +48,7 @@ const quotaUtils = require('../api/apiUtils/quotas/quotaUtils'); | |
| const { handleAuthorizationResults } = require('../api/api'); | ||
| const { versioningPreprocessing } | ||
| = require('../api/apiUtils/object/versioning'); | ||
| const getReplicationInfo = require('../api/apiUtils/object/getReplicationInfo'); | ||
| const {promisify} = require('util'); | ||
|
|
||
| const versioningPreprocessingPromised = promisify(versioningPreprocessing); | ||
|
|
@@ -430,6 +432,27 @@ function putData(request, response, bucketInfo, objMd, log, callback) { | |
| log.error(errMessage); | ||
| return callback(errorInstances.BadRequest.customizeDescription(errMessage)); | ||
| } | ||
|
|
||
| const incomingVersionIdEncoded = request.headers['x-scal-source-version-id']; | ||
| const decoded = incomingVersionIdEncoded ? decode(incomingVersionIdEncoded) : null; | ||
| const incomingVersionIdDecoded = decoded instanceof Error ? null : decoded; | ||
| if (incomingVersionIdDecoded && objMd && objMd.versionId === incomingVersionIdDecoded) { | ||
| // Skip the write if data is already at destination for this version id | ||
| // x-scal-micro-version-id header is used by Backbeat : | ||
| // non-empty : microVersionId available, use it for crr cascade detection | ||
| // empty : old object without microVersionId, can still proceed with metadata-only | ||
| log.debug('crr cascade putData: version already at destination', { | ||
| method: 'putData', | ||
| bucketName: request.bucketName, | ||
| objectKey: request.objectKey, | ||
| hasMicroVersionId: !!objMd.microVersionId, | ||
| }); | ||
| return _respondWithHeaders(response, null, | ||
| { 'x-scal-micro-version-id': objMd.microVersionId | ||
| ? encode(objMd.microVersionId) : '' }, | ||
| log, callback); | ||
| } | ||
|
|
||
| const context = { | ||
| bucketName: request.bucketName, | ||
| owner: canonicalID, | ||
|
|
@@ -541,6 +564,28 @@ function getCanonicalIdsByAccountId(accountId, log, cb) { | |
| } | ||
|
|
||
| function putMetadata(request, response, bucketInfo, objMd, log, callback) { | ||
| const { bucketName, objectKey } = request; | ||
|
|
||
| const encodedMicroVersionId = request.headers['x-scal-micro-version-id']; | ||
| const decoded = encodedMicroVersionId ? decode(encodedMicroVersionId) : null; | ||
| const incomingRaw = decoded instanceof Error ? null : decoded; | ||
| if (incomingRaw) { | ||
| const event = checkCrrCascadeEvent(incomingRaw, objMd && objMd.microVersionId); | ||
| if (event === 'loop') { | ||
| log.debug('crr cascade putMetadata: loop detected, skipping write', { | ||
| method: 'putMetadata', bucketName, objectKey, | ||
| }); | ||
| return _respondWithHeaders(response, {}, | ||
| { 'x-scal-micro-version-id-exists': 'true' }, log, callback); | ||
| } | ||
| if (event === 'stale') { | ||
| log.debug('crr cascade putMetadata: stale event, rejecting', { | ||
| method: 'putMetadata', bucketName, objectKey, | ||
| }); | ||
| return callback(errors.OperationAborted); | ||
| } | ||
| } | ||
|
|
||
| return _getRequestPayload(request, (err, payload) => { | ||
| if (err) { | ||
| return callback(err); | ||
|
|
@@ -554,14 +599,15 @@ function putMetadata(request, response, bucketInfo, objMd, log, callback) { | |
| return callback(errors.MalformedPOSTRequest); | ||
| } | ||
|
|
||
| const { headers, bucketName, objectKey } = request; | ||
| const { headers } = request; | ||
|
|
||
| // Destination-side delete-marker replication. | ||
| // We need the REPLICA status to distinguish from | ||
| // source-side replication status updates that also carry isDeleteMarker=true. | ||
| if (omVal.isDeleteMarker | ||
| && omVal.replicationInfo | ||
| && omVal.replicationInfo.status === 'REPLICA' | ||
| && (omVal.replicationInfo.isReplica === true | ||
| || omVal.replicationInfo.status === 'REPLICA') | ||
| && request.serverAccessLog) { | ||
| // eslint-disable-next-line no-param-reassign | ||
| request.serverAccessLog.replication = true; | ||
|
|
@@ -575,7 +621,8 @@ function putMetadata(request, response, bucketInfo, objMd, log, callback) { | |
| // URI shape. | ||
| // The REPLICA status excludes source-side replication-status updates. | ||
| if (omVal.replicationInfo | ||
| && omVal.replicationInfo.status === 'REPLICA' | ||
| && (omVal.replicationInfo.isReplica === true | ||
| || omVal.replicationInfo.status === 'REPLICA') | ||
| && (omVal.originOp === 's3:ObjectTagging:Put' | ||
| || omVal.originOp === 's3:ObjectTagging:Delete') | ||
| && request.serverAccessLog) { | ||
|
|
@@ -591,7 +638,8 @@ function putMetadata(request, response, bucketInfo, objMd, log, callback) { | |
| // populates the aclRequired field. | ||
| // The REPLICA status excludes source-side replication-status updates. | ||
| if (omVal.replicationInfo | ||
| && omVal.replicationInfo.status === 'REPLICA' | ||
| && (omVal.replicationInfo.isReplica === true | ||
| || omVal.replicationInfo.status === 'REPLICA') | ||
| && omVal.originOp === 's3:ObjectAcl:Put' | ||
| && request.serverAccessLog) { | ||
| // eslint-disable-next-line no-param-reassign | ||
|
|
@@ -669,7 +717,8 @@ function putMetadata(request, response, bucketInfo, objMd, log, callback) { | |
| // then we want to create a version for the replica object even though | ||
| // none was provided in the object metadata value. | ||
| if (omVal.replicationInfo.isNFS) { | ||
| const isReplica = omVal.replicationInfo.status === 'REPLICA'; | ||
| const isReplica = omVal.replicationInfo.isReplica === true | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should probably use the new helper function from arsenal : getReplicationIsReplica ? |
||
| || omVal.replicationInfo.status === 'REPLICA'; | ||
| versioning = isReplica; | ||
| omVal.replicationInfo.isNFS = !isReplica; | ||
| } | ||
|
|
@@ -721,6 +770,53 @@ function putMetadata(request, response, bucketInfo, objMd, log, callback) { | |
| options.isNull = isNull; | ||
| } | ||
|
|
||
| // Cascade triggering | ||
| // If the bucket receiving this replica has its own CRR rules, set | ||
| // status to PENDING so the queue populator here picks it up for the | ||
| // next hop. If not, clear the source-side replicationInfo fields | ||
| // Always mark isReplica=true. | ||
| if (incomingRaw) { | ||
| const isMDOnly = headers['x-scal-replication-content'] === 'METADATA'; | ||
| const objSize = omVal['content-length'] || 0; | ||
|
|
||
| // These S3-compatible Scality locations are excluded | ||
| // as cascade targets because they use the MultiBackend S3 path which | ||
| // bypasses the putData/putMetadata routes, so loop detection cannot fire | ||
| // on those destinations. | ||
| const BLOCKED_LOCATION_TYPES = [ | ||
| 'location-scality-ring-s3-v1', | ||
| 'location-scality-artesca-s3-v1', | ||
| ]; | ||
|
|
||
| const nextReplInfo = getReplicationInfo( | ||
| config, objectKey, bucketInfo, isMDOnly, objSize, | ||
| null, null, null); | ||
|
|
||
| if (nextReplInfo) { | ||
| nextReplInfo.backends = nextReplInfo.backends.filter(b => { | ||
| const loc = config.locationConstraints[b.site]; | ||
| return !loc || !BLOCKED_LOCATION_TYPES.includes(loc.type); | ||
| }); | ||
| } | ||
|
|
||
| if (nextReplInfo && nextReplInfo.backends.length > 0) { | ||
| omVal.replicationInfo = nextReplInfo; | ||
| } else { | ||
| omVal.replicationInfo = { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe this should be an arsenal function as its updating metadata |
||
| status: '', | ||
| backends: [], | ||
| content: [], | ||
| destination: '', | ||
| storageClass: '', | ||
| role: '', | ||
| storageType: '', | ||
| dataStoreVersionId: '', | ||
| }; | ||
| } | ||
|
|
||
| omVal.replicationInfo.isReplica = true; | ||
| } | ||
|
|
||
| return async.series([ | ||
| // Zenko's CRR delegates replacing the account | ||
| // information to the destination's Cloudserver, as | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be in arsenal 🤔
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no i think its fine here (talking to myself)