Skip to content

Commit b5c2131

Browse files
committed
✨ check that backend support versioning
1 parent da6bfb6 commit b5c2131

File tree

2 files changed

+49
-17
lines changed

2 files changed

+49
-17
lines changed

lib/routes/routeBackbeat.js

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,18 @@ function putMetadata(request, response, bucketInfo, objMd, log, callback) {
543543
let versionId = decodeVersionId(request.query);
544544
let versioning = bucketInfo.isVersioningEnabled();
545545
let isNull = false;
546+
const storageType = headers['x-scal-storage-type'];
547+
let versioningNotImpl = false;
548+
console.info('storage type', { storageType, versioningNotImplBackends: constants.versioningNotImplBackends });
549+
550+
if (constants.versioningNotImplBackends[storageType]) {
551+
log.debug(
552+
'versioning is not implemented on the destination backend',
553+
{ method: 'putMetadata', error: errors.NotImplemented },
554+
);
555+
556+
versioningNotImpl = true;
557+
}
546558

547559
if (versionId === 'null') {
548560
isNull = true;
@@ -616,10 +628,13 @@ function putMetadata(request, response, bucketInfo, objMd, log, callback) {
616628
// To prevent this, the versionId field is only included in options when it is defined.
617629
if (versionId !== undefined) {
618630
options.versionId = versionId;
619-
omVal.versionId = versionId;
620631

621-
if (isNull) {
622-
omVal.isNull = isNull;
632+
if (!versioningNotImpl) {
633+
omVal.versionId = versionId;
634+
635+
if (isNull) {
636+
omVal.isNull = isNull;
637+
}
623638
}
624639

625640
// In the MongoDB metadata backend, setting the versionId option leads to the creation
@@ -663,21 +678,24 @@ function putMetadata(request, response, bucketInfo, objMd, log, callback) {
663678
});
664679
},
665680
async () => {
666-
if (versioning && !objMd) {
667-
const masterObjectAndBucket =
668-
await metadata.getBucketAndObjectMDPromised(bucketName, objectKey, {}, log);
681+
if (!versioning || objMd || versioningNotImpl) {
682+
console.info('skipping versioning preprocessing', { versioning, hasObjMd: !!objMd });
683+
return;
684+
}
669685

670-
if (!masterObjectAndBucket.obj) {
671-
return;
672-
}
686+
const masterObjectAndBucket =
687+
await metadata.getBucketAndObjectMDPromised(bucketName, objectKey, {}, log);
673688

674-
const masterObject = JSON.parse(masterObjectAndBucket.obj);
675-
const versioningPreprocessingResult =
676-
await versioningPreprocessingPromised(bucketName, bucketInfo, objectKey, masterObject, log);
689+
if (!masterObjectAndBucket.obj) {
690+
return;
691+
}
677692

678-
if (versioningPreprocessingResult?.nullVersionId) {
679-
omVal.nullVersionId = versioningPreprocessingResult.nullVersionId;
680-
}
693+
const masterObject = JSON.parse(masterObjectAndBucket.obj);
694+
const versioningPreprocessingResult =
695+
await versioningPreprocessingPromised(bucketName, bucketInfo, objectKey, masterObject, log);
696+
697+
if (versioningPreprocessingResult?.nullVersionId) {
698+
omVal.nullVersionId = versioningPreprocessingResult.nullVersionId;
681699
}
682700
},
683701
next => {

tests/multipleBackend/routes/routeBackbeat.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2467,14 +2467,18 @@ describe('backbeat routes', () => {
24672467
], done);
24682468
});
24692469

2470-
it('should put tags if the source is Azure and tags are provided ' +
2470+
it.only('should put tags if the source is Azure and tags are provided ' +
24712471
'when completing the multipart upload', done => {
24722472
const containerName = getAzureContainerName(azureLocation);
24732473
const blob = uuidv4();
24742474
const multipleBackendPath =
24752475
`/_/backbeat/multiplebackenddata/${containerName}/${blob}`;
24762476
const uploadId = uuidv4().replace(/-/g, '');
24772477
let partData;
2478+
2479+
console.info(`Azure container name: ${containerName}`);
2480+
console.info({ azureLocation });
2481+
24782482
async.series([
24792483
next =>
24802484
makeRequest({
@@ -2525,10 +2529,20 @@ describe('backbeat routes', () => {
25252529
next =>
25262530
azureClient.getContainerClient(containerName).getBlobClient(blob).getProperties()
25272531
.then(result => {
2532+
console.info('got blob properties', { result });
25282533
const tags = JSON.parse(result.metadata.tags);
25292534
assert.deepStrictEqual(tags, { key1: 'value1' });
25302535
return next();
2531-
}, next),
2536+
}, err => {
2537+
console.error({ err });
2538+
console.error('error getting blob properties 1');
2539+
next;
2540+
})
2541+
.catch(err => {
2542+
console.error({ err });
2543+
console.error('error getting blob properties 2', err);
2544+
return next(err);
2545+
}),
25322546
], done);
25332547
});
25342548
});

0 commit comments

Comments
 (0)