Compare commits

...

2 Commits

Author SHA1 Message Date
Nicolas Humbert d1d140997a ARSN-418 bump package version 2024-06-18 13:55:04 +02:00
Kerkesni 361b546f87 bugfix: ARSN-278 handle getting versionId when object is versioning suspended
When replicating a versioning suspended object, we need to specify 'null'
as the encoded versionId as the versionId contained within the object's
metadata is strictly internal

In the replication processor we use getVersionId() when putting/deleting a tag.
It's used by the mongoClient to fetch the object from MongoDB, here again we
need to specify 'null' to get the versioning suspended object (cloudserver already
knows how to handle 'null' versionId and transforms it to undefined before giving
it to the mongoClient)

(cherry picked from commit d1cd7e8dba)
(cherry picked from commit f13a5d79ea)
2024-06-18 13:53:25 +02:00
4 changed files with 54 additions and 3 deletions

View File

@ -1,5 +1,6 @@
import * as constants from '../constants'; import * as constants from '../constants';
import * as VersionIDUtils from '../versioning/VersionID'; import * as VersionIDUtils from '../versioning/VersionID';
import { VersioningConstants } from '../versioning/constants';
import ObjectMDLocation, { import ObjectMDLocation, {
ObjectMDLocationData, ObjectMDLocationData,
Location, Location,
@ -797,6 +798,9 @@ export default class ObjectMD {
* @return The object versionId * @return The object versionId
*/ */
getVersionId() { getVersionId() {
if (this.getIsNull()) {
return VersioningConstants.ExternalNullVersionId;
}
return this._data.versionId; return this._data.versionId;
} }
@ -804,13 +808,16 @@ export default class ObjectMD {
* Get metadata versionId value in encoded form (the one visible * Get metadata versionId value in encoded form (the one visible
* to the S3 API user) * to the S3 API user)
* *
* @return The encoded object versionId * @return {undefined|string} The encoded object versionId
*/ */
getEncodedVersionId() { getEncodedVersionId() {
const versionId = this.getVersionId(); const versionId = this.getVersionId();
if (versionId) { if (versionId === VersioningConstants.ExternalNullVersionId) {
return versionId;
} else if (versionId) {
return VersionIDUtils.encode(versionId); return VersionIDUtils.encode(versionId);
} }
return undefined;
} }
/** /**

View File

@ -15,4 +15,5 @@ export const VersioningConstants = {
v1mig: 'v1mig', v1mig: 'v1mig',
v1: 'v1', v1: 'v1',
}, },
ExternalNullVersionId: 'null',
}; };

View File

@ -3,7 +3,7 @@
"engines": { "engines": {
"node": ">=16" "node": ">=16"
}, },
"version": "7.70.14", "version": "7.70.14-1",
"description": "Common utilities for the S3 project components", "description": "Common utilities for the S3 project components",
"main": "build/index.js", "main": "build/index.js",
"repository": { "repository": {

View File

@ -1,6 +1,8 @@
const assert = require('assert'); const assert = require('assert');
const ObjectMD = require('../../../lib/models/ObjectMD').default; const ObjectMD = require('../../../lib/models/ObjectMD').default;
const constants = require('../../../lib/constants'); const constants = require('../../../lib/constants');
const ExternalNullVersionId = require('../../../lib/versioning/constants')
.VersioningConstants.ExternalNullVersionId;
const retainDate = new Date(); const retainDate = new Date();
retainDate.setDate(retainDate.getDate() + 1); retainDate.setDate(retainDate.getDate() + 1);
@ -583,3 +585,44 @@ describe('ObjectMD::getReducedLocations', () => {
]); ]);
}); });
}); });
describe('ObjectMD::getVersionId', () => {
let objMd = null;
const versionId = '98451712418844999999RG001 22019.0';
beforeEach(() => {
objMd = new ObjectMD();
});
it('should return undefined when object is non versioned', () => {
assert.strictEqual(objMd.getVersionId(), undefined);
});
it('should return versionId when object versioned', () => {
objMd.setVersionId(versionId);
assert.strictEqual(objMd.getVersionId(), versionId);
});
it('should return "null" when object is in versioning suspended mode', () => {
objMd.setVersionId(versionId);
objMd.setIsNull(true);
assert.strictEqual(objMd.getVersionId(), ExternalNullVersionId);
});
});
describe('ObjectMD::getEncodedVersionId', () => {
let objMd = null;
const versionId = '98451712418844999999RG001 22019.0';
const encodedVersionId = '39383435313731323431383834343939393939395247303031202032323031392e30';
beforeEach(() => {
objMd = new ObjectMD();
});
it('should return undefined when object is non versioned', () => {
assert.strictEqual(objMd.getEncodedVersionId(), undefined);
});
it('should return versionId when object versioned', () => {
objMd.setVersionId(versionId);
assert.strictEqual(objMd.getEncodedVersionId(), encodedVersionId);
});
it('should return "null" when object is in versioning suspended mode', () => {
objMd.setVersionId(versionId);
objMd.setIsNull(true);
assert.strictEqual(objMd.getEncodedVersionId(), ExternalNullVersionId);
});
});