Skip to content

Commit

Permalink
bugfix: ARSN-278 handle getting versionId when object is versioning s…
Browse files Browse the repository at this point in the history
…uspended

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 d1cd7e8)
  • Loading branch information
Kerkesni authored and nicolas2bert committed Apr 26, 2024
1 parent a643a3e commit f13a5d7
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/models/ObjectMD.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as constants from '../constants';
import * as VersionIDUtils from '../versioning/VersionID';
import { VersioningConstants } from '../versioning/constants';
import ObjectMDLocation, {
ObjectMDLocationData,
Location,
Expand Down Expand Up @@ -797,20 +798,26 @@ export default class ObjectMD {
* @return The object versionId
*/
getVersionId() {
if (this.getIsNull()) {
return VersioningConstants.ExternalNullVersionId;
}
return this._data.versionId;
}

/**
* Get metadata versionId value in encoded form (the one visible
* to the S3 API user)
*
* @return The encoded object versionId
* @return {undefined|string} The encoded object versionId
*/
getEncodedVersionId() {
const versionId = this.getVersionId();
if (versionId) {
if (versionId === VersioningConstants.ExternalNullVersionId) {
return versionId;
} else if (versionId) {
return VersionIDUtils.encode(versionId);
}
return undefined;
}

/**
Expand Down
1 change: 1 addition & 0 deletions lib/versioning/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export const VersioningConstants = {
v1mig: 'v1mig',
v1: 'v1',
},
ExternalNullVersionId: 'null',
};
43 changes: 43 additions & 0 deletions tests/unit/models/ObjectMD.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const assert = require('assert');
const ObjectMD = require('../../../lib/models/ObjectMD').default;
const constants = require('../../../lib/constants');
const ExternalNullVersionId = require('../../../lib/versioning/constants')
.VersioningConstants.ExternalNullVersionId;

const retainDate = new Date();
retainDate.setDate(retainDate.getDate() + 1);
Expand Down Expand Up @@ -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);
});
});

0 comments on commit f13a5d7

Please sign in to comment.