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
31 changes: 18 additions & 13 deletions src/manage_nsfs/nc_lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ class NCLifecycle {
*/
async get_candidates(bucket_json, lifecycle_rule, object_sdk) {
const candidates = { abort_mpu_candidates: [], delete_candidates: [] };
const versions_list = undefined;
const params = {versions_list: undefined};
if (lifecycle_rule.expiration) {
candidates.delete_candidates = await this.get_candidates_by_expiration_rule(lifecycle_rule, bucket_json,
object_sdk);
Expand All @@ -385,7 +385,7 @@ class NCLifecycle {
lifecycle_rule,
bucket_json,
object_sdk,
{versions_list}
params
);
candidates.delete_candidates = candidates.delete_candidates.concat(dm_candidates);
}
Expand All @@ -395,7 +395,7 @@ class NCLifecycle {
lifecycle_rule,
bucket_json,
object_sdk,
{versions_list}
params
);
candidates.delete_candidates = candidates.delete_candidates.concat(non_current_candidates);
}
Expand Down Expand Up @@ -528,12 +528,13 @@ class NCLifecycle {
* @param {Object} bucket_json
* @returns {Promise<Object[]>}
*/
async get_candidates_by_expiration_delete_marker_rule(lifecycle_rule, bucket_json, object_sdk, {versions_list}) {
async get_candidates_by_expiration_delete_marker_rule(lifecycle_rule, bucket_json, object_sdk, params) {
const rule_state = this._get_rule_state(bucket_json, lifecycle_rule).noncurrent;
if (rule_state.is_finished) return [];
if (!versions_list) {
versions_list = await this.load_versions_list(object_sdk, lifecycle_rule, bucket_json, rule_state);
if (!params.versions_list) {
if (rule_state.is_finished) return [];
params.versions_list = await this.load_versions_list(object_sdk, lifecycle_rule, bucket_json, rule_state);
}
const versions_list = params.versions_list;
const candidates = [];
const expiration = lifecycle_rule.expiration?.days ? this._get_expiration_time(lifecycle_rule.expiration) : 0;
const filter_func = this._build_lifecycle_filter({filter: lifecycle_rule.filter, expiration});
Expand Down Expand Up @@ -630,13 +631,14 @@ class NCLifecycle {
* @param {Object} bucket_json
* @returns {Promise<Object[]>}
*/
async get_candidates_by_noncurrent_version_expiration_rule(lifecycle_rule, bucket_json, object_sdk, {versions_list}) {
async get_candidates_by_noncurrent_version_expiration_rule(lifecycle_rule, bucket_json, object_sdk, params) {
const rule_state = this._get_rule_state(bucket_json, lifecycle_rule).noncurrent;
if (rule_state.is_finished) return [];

if (!versions_list) {
versions_list = await this.load_versions_list(object_sdk, lifecycle_rule, bucket_json, rule_state);
if (!params.versions_list) {
if (rule_state.is_finished) return [];
params.versions_list = await this.load_versions_list(object_sdk, lifecycle_rule, bucket_json, rule_state);
}
const versions_list = params.versions_list;

const filter_func = this._build_lifecycle_filter({filter: lifecycle_rule.filter, expiration: 0});
const num_newer_versions = lifecycle_rule.noncurrent_version_expiration.newer_noncurrent_versions;
Expand All @@ -652,7 +654,6 @@ class NCLifecycle {
}
}
}

return delete_candidates;
}
////////////////////////////////////
Expand Down Expand Up @@ -756,8 +757,12 @@ class NCLifecycle {
const expiration_date = new Date(expiration_rule.date).getTime();
if (Date.now() < expiration_date) return -1;
return 0;
} else if (expiration_rule.days) {
return expiration_rule.days;
} else {
//expiration delete marker rule
return -1;
}
return expiration_rule.days;
}

////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,34 @@ describe('noobaa nc - lifecycle versioning ENABLED', () => {
});
});

it('nc lifecycle - versioning ENABLED - noncurrent expiration rule - expire older versions by number of days whith expire delete marker rule', async () => {
const lifecycle_rule = [{
"id": "expire noncurrent versions after 3 days with size ",
"status": LIFECYCLE_RULE_STATUS_ENUM.ENABLED,
"filter": {
"prefix": '',
},
"expiration": {
"expired_object_delete_marker": true
},
"noncurrent_version_expiration": {
"noncurrent_days": 3
}
}];
await object_sdk.set_bucket_lifecycle_configuration_rules({ name: test_bucket, rules: lifecycle_rule });

const res = await create_object(object_sdk, test_bucket, test_key1_regular, 100, false);
await create_object(object_sdk, test_bucket, test_key1_regular, 100, false);
await update_version_xattr(test_bucket, test_key1_regular, res.version_id);

await exec_manage_cli(TYPES.LIFECYCLE, '', { disable_service_validation: 'true', disable_runtime_validation: 'true', config_root }, undefined, undefined);
const object_list = await object_sdk.list_object_versions({ bucket: test_bucket });
expect(object_list.objects.length).toBe(1);
object_list.objects.forEach(element => {
expect(element.version_id).not.toBe(res.version_id);
});
});

it('nc lifecycle - versioning ENABLED - noncurrent expiration rule - both noncurrent days and older versions', async () => {
const lifecycle_rule = [{
"id": "expire noncurrent versions after 3 days",
Expand Down