Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/routes/routeBackbeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,9 @@ function putMetadata(request, response, bucketInfo, objMd, log, callback) {
// transition processor. Check the content-length as a null location can
// also be from an empty object.
(omVal['content-length'] === 0 || (omVal.location && Array.isArray(omVal.location))) &&
locationKeysHaveChanged(objMd.location, omVal.location)
locationKeysHaveChanged(objMd.location, omVal.location) &&

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Do not delete data on remote location (example : pull replication)
!locationConstraints[objMd.dataStoreName]?.isCRR

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this if condition is hard to read. Can it be simplified ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm leaving now but its more the whole function should be cleaned up its FIVE HUNDRED lines + callbacks but later later

) {
log.info('removing old data locations', {
method: 'putMetadata',
Expand Down
41 changes: 41 additions & 0 deletions tests/unit/routes/routeBackbeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,47 @@ describe('routeBackbeat', () => {
sinon.assert.calledWith(dataDeleteSpy, existingMd.location[0]);
});

it('should not delete data on a CRR location when locations change', async () => {
const existingMd = {
'dataStoreName': 'location-crr-v1',
'location': [
{
key: 'key0',
dataStoreName: 'location-crr-v1',
size: 100,
},
],
'content-length': 100,
};
metadataUtils.standardMetadataValidateBucketAndObj.callsFake((params, denies, log, callback) => {
callback(null, bucketInfo, existingMd);
});

// the data was pulled from the CRR location to a local one
const reqBody = {
'location': [
{
key: 'key1',
dataStoreName: 'us-east-1',
size: 100,
},
],
'content-length': 100,
};
mockRequest = preparePutMetadataRequest(reqBody);
mockRequest.url += '?versionId=aIXVkw5Tw2Pd00000000001I4j3QKsvf';

sandbox
.stub(metadata, 'putObjectMD')
.callsFake((_bucketName, _objectKey, _omVal, _options, _logParam, cb) => cb(null, {}));

routeBackbeat('127.0.0.1', mockRequest, mockResponse, log);
void (await endPromise);

assert.strictEqual(mockResponse.statusCode, 200);
assert.strictEqual(dataDeleteSpy.called, false);
});

it('should not delete data when some keys are still used', async () => {
const existingMd = {
'location': [
Expand Down
Loading