-
Notifications
You must be signed in to change notification settings - Fork 260
Integrate Pull Replication's clean read into cloudserver #6295
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
1
commit into
development/9.5
Choose a base branch
from
improvement/CLDSRV-957/clean-read-config
base: development/9.5
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.
Open
Changes from all commits
Commits
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
154 changes: 154 additions & 0 deletions
154
tests/functional/aws-node-sdk/test/versioning/cleanRead.js
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 |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| const assert = require('assert'); | ||
| const crypto = require('crypto'); | ||
| const { versioning } = require('arsenal'); | ||
| const { | ||
| S3Client, | ||
| CreateBucketCommand, | ||
| DeleteBucketCommand, | ||
| PutBucketVersioningCommand, | ||
| PutObjectCommand, | ||
| GetObjectCommand, | ||
| HeadObjectCommand, | ||
| ListObjectsV2Command, | ||
| ListObjectVersionsCommand, | ||
| } = require('@aws-sdk/client-s3'); | ||
|
|
||
| const withV4 = require('../support/withV4'); | ||
| const getConfig = require('../support/config'); | ||
| const { config } = require('../../../../../lib/Config'); | ||
| const metadata = require('../../../../../lib/metadata/wrapper'); | ||
| const { initMetadata, getMetadata } = require('../utils/init'); | ||
| const { DummyRequestLogger } = require('../../../../unit/helpers'); | ||
| const { removeAllVersions } = require('../../lib/utility/versioning-util'); | ||
| const { promisify } = require('util'); | ||
|
|
||
| const versionIdUtils = versioning.VersionID; | ||
| const log = new DummyRequestLogger(); | ||
| const removeAllVersionsAsync = promisify(removeAllVersions); | ||
|
|
||
| const bucket = `clean-read-bucket-${Date.now()}`; | ||
| const objectKey = 'clean-read-object'; | ||
| const LOCAL_LOCATION = 'us-east-1'; | ||
| const LOCALIZED_BODY = 'localized'; | ||
| const NON_LOCALIZED_BODY = 'waiting for its data to be copied over'; | ||
|
|
||
| // clean read is implemented by the mongodb metadata backend only | ||
| const describeIfCleanRead = process.env.S3METADATA === 'mongodb' ? describe : describe.skip; | ||
|
|
||
| describeIfCleanRead('clean read', function testSuite() { | ||
| this.timeout(600000); | ||
|
|
||
| withV4(sigCfg => { | ||
| let s3; | ||
| let localizedVersionId; | ||
| let nonLocalizedVersionId; | ||
| let nonLocalizedMD; | ||
| let nonLocalizedDecodedVersionId; | ||
|
|
||
| // Replicates a version the way the clean-room mongo-processor does | ||
| async function replicateNonLocalizedVersion() { | ||
| const decodedVersionId = versionIdUtils.generateVersionId(`${process.pid}`, config.replicationGroupId); | ||
| const objMD = await getMetadata(bucket, objectKey, localizedVersionId); | ||
| objMD.versionId = decodedVersionId; | ||
| // the version carries a content of its own, written on the source site | ||
| objMD['content-length'] = NON_LOCALIZED_BODY.length; | ||
| objMD['content-md5'] = crypto.createHash('md5').update(NON_LOCALIZED_BODY).digest('hex'); | ||
| // the only location flagged "isCRR" in tests/locationConfig/locationConfigTests.json | ||
| objMD.dataStoreName = 'location-crr-v1'; | ||
| objMD['last-modified'] = new Date().toJSON(); | ||
| nonLocalizedMD = objMD; | ||
| nonLocalizedDecodedVersionId = decodedVersionId; | ||
| await new Promise((resolve, reject) => | ||
| metadata.putObjectMD( | ||
| bucket, | ||
| objectKey, | ||
| objMD, | ||
| { versionId: decodedVersionId, repairMaster: true }, | ||
| log, | ||
| err => (err ? reject(err) : resolve()), | ||
| ), | ||
| ); | ||
| return versionIdUtils.encode(decodedVersionId); | ||
| } | ||
|
|
||
| before(async () => { | ||
| s3 = new S3Client(getConfig('default', sigCfg)); | ||
| await initMetadata(); | ||
| await s3.send(new CreateBucketCommand({ Bucket: bucket })); | ||
| await s3.send( | ||
| new PutBucketVersioningCommand({ | ||
| Bucket: bucket, | ||
| VersioningConfiguration: { Status: 'Enabled' }, | ||
| }), | ||
| ); | ||
| const localized = await s3.send( | ||
| new PutObjectCommand({ Bucket: bucket, Key: objectKey, Body: LOCALIZED_BODY }), | ||
| ); | ||
| localizedVersionId = localized.VersionId; | ||
| nonLocalizedVersionId = await replicateNonLocalizedVersion(); | ||
| }); | ||
|
|
||
| after(async () => { | ||
| // removeAllVersions lists through the S3 API, which hides the non-localized | ||
| // version: localize it first, the way the data mover would, so that the | ||
| // teardown can see and delete it | ||
| nonLocalizedMD.dataStoreName = LOCAL_LOCATION; | ||
| await new Promise((resolve, reject) => | ||
| metadata.putObjectMD( | ||
| bucket, | ||
| objectKey, | ||
| nonLocalizedMD, | ||
| { versionId: nonLocalizedDecodedVersionId, repairMaster: true }, | ||
| log, | ||
| err => (err ? reject(err) : resolve()), | ||
| ), | ||
| ); | ||
| await removeAllVersionsAsync({ Bucket: bucket }); | ||
|
SylvainSenechal marked this conversation as resolved.
|
||
| await s3.send(new DeleteBucketCommand({ Bucket: bucket })); | ||
| }); | ||
|
|
||
| it('should omit the non-localized version from the version listing', async () => { | ||
| const res = await s3.send(new ListObjectVersionsCommand({ Bucket: bucket })); | ||
| assert.deepStrictEqual( | ||
| (res.Versions || []).map(version => version.VersionId), | ||
| [localizedVersionId], | ||
| ); | ||
| }); | ||
|
|
||
| it('should list the object, carried by its newest localized version', async () => { | ||
| const res = await s3.send(new ListObjectsV2Command({ Bucket: bucket })); | ||
| assert.strictEqual(res.Contents.length, 1); | ||
| assert.strictEqual(res.Contents[0].Key, objectKey); | ||
| // the size tells the two versions apart, the master having kept the | ||
| // localized one rather than following the newer non-localized version | ||
| assert.strictEqual(res.Contents[0].Size, LOCALIZED_BODY.length); | ||
| }); | ||
|
|
||
| it('should serve the newest localized version as the current object', async () => { | ||
| const res = await s3.send(new GetObjectCommand({ Bucket: bucket, Key: objectKey })); | ||
| assert.strictEqual(res.VersionId, localizedVersionId); | ||
| assert.strictEqual(res.ContentLength, LOCALIZED_BODY.length); | ||
| assert.strictEqual(await res.Body.transformToString(), LOCALIZED_BODY); | ||
| }); | ||
|
|
||
| it('should reject a get on the non-localized version', async () => { | ||
| await assert.rejects( | ||
| s3.send(new GetObjectCommand({ Bucket: bucket, Key: objectKey, VersionId: nonLocalizedVersionId })), | ||
| err => { | ||
| assert.strictEqual(err.name, 'NoSuchVersion'); | ||
| return true; | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| it('should reject a head on the non-localized version', async () => { | ||
| await assert.rejects( | ||
| s3.send(new HeadObjectCommand({ Bucket: bucket, Key: objectKey, VersionId: nonLocalizedVersionId })), | ||
| err => { | ||
| assert.strictEqual(err.$metadata.httpStatusCode, 404); | ||
| return true; | ||
| }, | ||
| ); | ||
| }); | ||
| }); | ||
| }); | ||
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 |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| 'use strict'; | ||
|
|
||
| const assert = require('assert'); | ||
| const { createHash } = require('crypto'); | ||
| const { v4: uuidv4 } = require('uuid'); | ||
| const { | ||
| CreateBucketCommand, | ||
| PutBucketVersioningCommand, | ||
| PutObjectCommand, | ||
| GetObjectCommand, | ||
| ListObjectVersionsCommand, | ||
| } = require('@aws-sdk/client-s3'); | ||
|
|
||
| const { versioning } = require('arsenal'); | ||
| const BucketUtility = require('../aws-node-sdk/lib/utility/bucket-util'); | ||
|
|
||
| const { BackbeatRoutesClient, GetMetadataCommand, PutMetadataCommand } = require('@scality/cloudserverclient'); | ||
|
|
||
| const { generateVersionId, encode: encodeVersionId } = versioning.VersionID; | ||
|
|
||
| const TEST_BUCKET = `bucket-cleanread-${uuidv4().split('-')[0]}`; | ||
| const LOCALIZED_BODY = 'localized'; | ||
| const CANONICAL_ID = '79a59df900b949e55d96a1e698fbacedfd6e09d98eacf8f8d5218e7cd47ef2be'; | ||
| // the only location flagged "isCRR" in tests/locationConfig/locationConfigTests.json | ||
| const SOURCE_LOCATION = 'location-crr-v1'; | ||
| const LOCAL_LOCATION = 'us-east-1'; | ||
| const REPLICATED_BODY = 'waiting for its data to be copied over'; | ||
|
|
||
| const bucketUtil = new BucketUtility('default', {}); | ||
| const s3 = bucketUtil.s3; | ||
|
|
||
| let backbeatClient; | ||
| const replicatedVersions = []; | ||
|
|
||
| function buildMetadataBody(versionId, dataStoreName) { | ||
| return JSON.stringify({ | ||
| 'content-length': Buffer.byteLength(REPLICATED_BODY), | ||
| 'content-type': 'text/plain', | ||
| 'last-modified': new Date().toISOString(), | ||
| 'content-md5': createHash('md5').update(REPLICATED_BODY).digest('hex'), | ||
| 'owner-id': CANONICAL_ID, | ||
| 'owner-display-name': 'test', | ||
| versionId, | ||
| dataStoreName, | ||
| location: null, | ||
| replicationInfo: { | ||
| status: 'REPLICA', | ||
| isReplica: true, | ||
| backends: [], | ||
| content: [], | ||
| destination: '', | ||
| storageClass: '', | ||
| role: '', | ||
| storageType: '', | ||
| dataStoreVersionId: '', | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| // the mongo-processor replicating a version, then the data mover merging it once | ||
| // the data has been copied: same version id, the location rewritten to the local one | ||
| function writeVersion(key, versionId, dataStoreName) { | ||
| if (dataStoreName === SOURCE_LOCATION) { | ||
| replicatedVersions.push({ key, versionId }); | ||
| } | ||
| return backbeatClient.send( | ||
| new PutMetadataCommand({ | ||
| Bucket: TEST_BUCKET, | ||
| Key: key, | ||
| VersionId: encodeVersionId(versionId), | ||
| Body: buildMetadataBody(versionId, dataStoreName), | ||
| }), | ||
| ); | ||
| } | ||
|
|
||
| async function currentVersion(key) { | ||
| const res = await s3.send(new GetObjectCommand({ Bucket: TEST_BUCKET, Key: key })); | ||
| return res.VersionId; | ||
| } | ||
|
|
||
| const describeIfCleanRead = process.env.S3METADATA === 'mongodb' ? describe : describe.skip; | ||
|
|
||
| describeIfCleanRead('clean read: localizing a replicated version', function testSuite() { | ||
| this.timeout(120000); | ||
|
|
||
| before(async () => { | ||
| const creds = await s3.config.credentials(); | ||
| backbeatClient = new BackbeatRoutesClient({ | ||
| endpoint: `http://${process.env.IP || '127.0.0.1'}:8000`, | ||
| region: 'us-east-1', | ||
| credentials: { | ||
| accessKeyId: creds.accessKeyId, | ||
| secretAccessKey: creds.secretAccessKey, | ||
| }, | ||
| forcePathStyle: true, | ||
| }); | ||
| await s3.send(new CreateBucketCommand({ Bucket: TEST_BUCKET })); | ||
| await s3.send( | ||
| new PutBucketVersioningCommand({ | ||
| Bucket: TEST_BUCKET, | ||
| VersioningConfiguration: { Status: 'Enabled' }, | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| after(async () => { | ||
|
SylvainSenechal marked this conversation as resolved.
|
||
| // the teardown lists through the S3 API, which hides the versions left | ||
| // non-localized: localize them first, the way the data mover would | ||
| await Promise.all(replicatedVersions.map(({ key, versionId }) => writeVersion(key, versionId, LOCAL_LOCATION))); | ||
| await bucketUtil.empty(TEST_BUCKET); | ||
| await bucketUtil.deleteOne(TEST_BUCKET); | ||
| }); | ||
|
|
||
| it('should hide the replicated version, then serve it once localized', async () => { | ||
| const key = 'clean-read-localization'; | ||
| const localized = await s3.send(new PutObjectCommand({ Bucket: TEST_BUCKET, Key: key, Body: LOCALIZED_BODY })); | ||
| const replicatedVersionId = generateVersionId(`${process.pid}`, 'RG001'); | ||
|
|
||
| // the version is replicated, its data still on the source site | ||
| await writeVersion(key, replicatedVersionId, SOURCE_LOCATION); | ||
|
|
||
| // clean read hides it: the object still reads as the older localized version | ||
| assert.strictEqual(await currentVersion(key), localized.VersionId); | ||
| const versions = await s3.send(new ListObjectVersionsCommand({ Bucket: TEST_BUCKET, Prefix: key })); | ||
| assert.deepStrictEqual( | ||
| (versions.Versions || []).map(v => v.VersionId), | ||
| [localized.VersionId], | ||
| ); | ||
|
|
||
| // the data mover copies the data and merges the metadata: same version, | ||
| // now pointing at the local location | ||
| await writeVersion(key, replicatedVersionId, LOCAL_LOCATION); | ||
|
|
||
| // it becomes the current version: the master was promoted | ||
| assert.strictEqual(await currentVersion(key), encodeVersionId(replicatedVersionId)); | ||
| }); | ||
|
|
||
| it('should let the data mover read the replicated version by its id', async () => { | ||
| const key = 'clean-read-by-version-id'; | ||
| await s3.send(new PutObjectCommand({ Bucket: TEST_BUCKET, Key: key, Body: LOCALIZED_BODY })); | ||
| const replicatedVersionId = generateVersionId(`${process.pid}`, 'RG001'); | ||
| await writeVersion(key, replicatedVersionId, SOURCE_LOCATION); | ||
|
|
||
| // hidden from the clients | ||
| await assert.rejects( | ||
| s3.send( | ||
| new GetObjectCommand({ | ||
| Bucket: TEST_BUCKET, | ||
| Key: key, | ||
| VersionId: encodeVersionId(replicatedVersionId), | ||
| }), | ||
| ), | ||
| err => { | ||
| assert.strictEqual(err.name, 'NoSuchVersion'); | ||
| return true; | ||
| }, | ||
| ); | ||
|
|
||
| // but readable through the backbeat route, which is how it gets localized | ||
| const res = await backbeatClient.send( | ||
| new GetMetadataCommand({ | ||
| Bucket: TEST_BUCKET, | ||
| Key: key, | ||
| VersionId: encodeVersionId(replicatedVersionId), | ||
| }), | ||
| ); | ||
| const md = JSON.parse(res.Body); | ||
| assert.strictEqual(md.dataStoreName, SOURCE_LOCATION); | ||
| }); | ||
| }); | ||
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.
todo