Skip to content
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

feature/BB 383/skipZeroByteToDMF #2386

Merged
merged 2 commits into from
Apr 13, 2023
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
22 changes: 20 additions & 2 deletions extensions/lifecycle/tasks/LifecycleTask.js
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,21 @@ class LifecycleTask extends BackbeatTask {
});
}


// TODO: remove once DMF supports 0 byte objects
// skips 0 byte transitions to DMF locations
_bb383SkipDMFTransition(objectInfo, site, log) {
if (objectInfo.Size === 0
&& locationsConfig[site]
&& locationsConfig[site].type === 'dmf') {
log.debug(`skipping transition task for 0 bytes objects to DMF location`, {
site,
});
return true;
}
return false;
}

/**
* Helper method for NoncurrentVersionTransition.NoncurrentDays rule
* Check if Noncurrent Transition rule applies on the version
Expand All @@ -1159,7 +1174,9 @@ class LifecycleTask extends BackbeatTask {
const ncd = 'NoncurrentDays';
const doesNCVTransitionRuleApply = (rules[ncvt] &&
rules[ncvt][ncd] !== undefined &&
daysSinceInitiated >= rules[ncvt][ncd]);
daysSinceInitiated >= rules[ncvt][ncd]) &&
!this._bb383SkipDMFTransition(version, rules[ncvt].StorageClass, log);

if (doesNCVTransitionRuleApply) {
this._applyTransitionRule({
owner: bucketData.target.owner,
Expand Down Expand Up @@ -1389,7 +1406,8 @@ class LifecycleTask extends BackbeatTask {
log);
return done();
}
if (rules.Transition) {
if (rules.Transition
&& !this._bb383SkipDMFTransition(obj, rules.Transition.StorageClass, log)) {
this._applyTransitionRule({
owner: bucketData.target.owner,
accountId: bucketData.target.accountId,
Expand Down
39 changes: 2 additions & 37 deletions extensions/replication/ReplicationAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@ const ActionQueueEntry = require('../../lib/models/ActionQueueEntry');
const ReplicationMetrics = require('./ReplicationMetrics');

let { dataMoverTopic } = config.extensions.replication;
const {
coldStorageArchiveTopicPrefix,
coldStorageStatusTopicPrefix,
} = config.extensions.lifecycle;
const { coldStorageArchiveTopicPrefix } = config.extensions.lifecycle;
const { LifecycleMetrics } = require('../lifecycle/LifecycleMetrics');

const { emptyObjectArchiveId, emptyObjectArchiveVersion } = require('../../lib/constants');

class ReplicationAPI {
/**
* Create an action to copy an object's data to a new location.
Expand Down Expand Up @@ -89,39 +84,9 @@ class ReplicationAPI {
log.error(errorMsg, { method: 'ReplicationAPI.sendDataMoverAction' });
return cb(new Error(errorMsg));
}

const { reqId } = action.getContext();

if (locationConfig.isCold) {
// Temp special case: current tape implementation does not allow
// zero-byte objects yet. Bypass forwarder and send directly
// to status topic.
if (contentLength === 0 && locationConfig.type === 'dmf') {
topic = `${coldStorageStatusTopicPrefix}${toLocation}`;
const message = {
op: 'archive',
requestId: reqId,
date: new Date(),

accountId,
bucketName: bucket,
objectKey: key,
objectVersion: version,
eTag,

archiveInfo: {
archiveId: emptyObjectArchiveId,
archiveVersion: emptyObjectArchiveVersion,
},
};
kafkaEntry.message = JSON.stringify(message);
return producer.sendToTopic(topic, [kafkaEntry], err => {
LifecycleMetrics.onKafkaPublish(log, 'ColdStorageStatusTopic', 'bucket', err, 1);
return cb();
});
}

topic = `${coldStorageArchiveTopicPrefix}${toLocation}`;
const { reqId } = action.getContext();
const message = {
accountId,
bucketName: bucket,
Expand Down
2 changes: 0 additions & 2 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ const constants = {
replicationStatusProcessor: 'ReplicationStatusProcessor',
},
compressionType: 'Zstd',
emptyObjectArchiveId: 'EMPTY_OBJECT_NO_ARCHIVE_ID',
emptyObjectArchiveVersion: 0,
};

module.exports = constants;
54 changes: 0 additions & 54 deletions tests/unit/replication/ReplicationAPI.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ const ReplicationAPI =
const assert = require('assert');
const ActionQueueEntry = require('../../../lib/models/ActionQueueEntry');

const sinon = require('sinon');

const fakeLogger = require('../../utils/fakeLogger');
const bucketName = 'transition-to-dmf';
const owner = '4f5a1a4bd769fd6e4ebca87b96c86a621ebb9c8be0c012f291757410c55a36f7';
Expand All @@ -31,15 +29,8 @@ describe('ReplicationAPI', () => {
},
};

let clock;

beforeEach(() => {
messages = [];
clock = sinon.useFakeTimers();
});

afterEach(() => {
clock.restore();
});

describe('::sendDataMoverAction ', () => {
Expand Down Expand Up @@ -82,50 +73,5 @@ describe('ReplicationAPI', () => {
return;
});
});

it('should bypass archive topic for empty objects', done => {
const action = ActionQueueEntry.create('copyLocation');
action
.setAttribute('target', {
accountId,
owner,
bucket: bucketName,
key: objectKey,
version: versionId,
eTag,
lastModified,
})
.setAttribute('toLocation', toLocation)
.setAttribute('metrics', {
origin: originLabel,
fromLocation,
contentLength: 0,
})
.setResultsTopic(resultsTopic);
ReplicationAPI.sendDataMoverAction(mockProducer, action, fakeLogger, err => {
assert.ifError(err);
const expectedMessage = [
{
topic: 'cold-status-location-dmf-v1',
entry: {
op: 'archive',
accountId,
bucketName,
objectKey,
objectVersion: versionId,
eTag,
archiveInfo: {
archiveId: 'EMPTY_OBJECT_NO_ARCHIVE_ID',
archiveVersion: 0,
},
date: new Date().toJSON(),
},
},
];
assert.deepStrictEqual(messages, expectedMessage);
done();
return;
});
});
});
});