Skip to content

Commit 2c7d076

Browse files
committed
NC | delete object filter verification on regular delete object (delete marker and version id deletion is not implemented yet)
Signed-off-by: Romy <35330373+romayalon@users.noreply.github.com>
1 parent 7083bb3 commit 2c7d076

File tree

5 files changed

+875
-99
lines changed

5 files changed

+875
-99
lines changed

src/manage_nsfs/nc_lifecycle.js

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,17 @@ class NCLifecycle {
263263
});
264264

265265
if (candidates.delete_candidates?.length > 0) {
266+
const expiration = lifecycle_rule.expiration ? this._get_expiration_time(lifecycle_rule.expiration) : 0;
267+
const filter_func = this._build_lifecycle_filter({filter: lifecycle_rule.filter, expiration});
268+
266269
const delete_res = await this._call_op_and_update_status({
267270
bucket_name,
268271
rule_id,
269272
op_name: TIMED_OPS.DELETE_MULTIPLE_OBJECTS,
270273
op_func: async () => object_sdk.delete_multiple_objects({
271274
bucket: bucket_json.name,
272-
objects: candidates.delete_candidates
275+
objects: candidates.delete_candidates,
276+
filter_func
273277
})
274278
});
275279
if (should_notify) {
@@ -413,18 +417,6 @@ class NCLifecycle {
413417
//////// EXPIRATION HELPERS ////////
414418
////////////////////////////////////
415419

416-
/**
417-
* @param {Object} entry list object entry
418-
*/
419-
_get_lifecycle_object_info_from_list_object_entry(entry) {
420-
return {
421-
key: entry.key,
422-
age: this._get_file_age_days(entry.create_time),
423-
size: entry.size,
424-
tags: entry.tagging,
425-
};
426-
}
427-
428420
/**
429421
* get_candidates_by_expiration_rule processes the expiration rule
430422
* @param {*} lifecycle_rule
@@ -484,8 +476,8 @@ class NCLifecycle {
484476
// also should maybe create a helper function or add argument for a filter in list object
485477
const objects_list = await this.load_objects_list(object_sdk, lifecycle_rule, bucket_json, rule_state);
486478
objects_list.objects.forEach(obj => {
487-
const lifecycle_object = this._get_lifecycle_object_info_from_list_object_entry(obj);
488-
if (filter_func(lifecycle_object)) {
479+
const should_delete = lifecycle_utils.file_matches_filter({ obj_info: obj, filter_func });
480+
if (should_delete) {
489481
//need to delete latest. so remove version_id if exists
490482
const candidate = _.omit(obj, ['version_id']);
491483
filtered_objects.push(candidate);
@@ -516,7 +508,7 @@ class NCLifecycle {
516508
* @returns
517509
*/
518510
filter_expired_delete_marker(object, next_object, filter_func) {
519-
const lifecycle_info = this._get_lifecycle_object_info_from_list_object_entry(object);
511+
const lifecycle_info = lifecycle_utils.get_lifecycle_object_info_for_filter(object);
520512
if (!filter_func(lifecycle_info)) return false;
521513
return object.is_latest && object.delete_marker && object.key !== next_object.key;
522514
}
@@ -542,7 +534,7 @@ class NCLifecycle {
542534
}
543535
}
544536
const last_item = versions_list.objects.length > 0 && versions_list.objects[versions_list.objects.length - 1];
545-
const lifecycle_info = this._get_lifecycle_object_info_from_list_object_entry(last_item);
537+
const lifecycle_info = lifecycle_utils.get_lifecycle_object_info_for_filter(last_item);
546538
if (last_item.is_latest && last_item.delete_marker && filter_func(lifecycle_info)) {
547539
if (rule_state.is_finished) {
548540
candidates.push(last_item);
@@ -640,7 +632,7 @@ class NCLifecycle {
640632
const delete_candidates = [];
641633

642634
for (const entry of versions_list.objects) {
643-
const lifecycle_info = this._get_lifecycle_object_info_from_list_object_entry(entry);
635+
const lifecycle_info = lifecycle_utils.get_lifecycle_object_info_for_filter(entry);
644636
if ((num_newer_versions === undefined || this.filter_newer_versions(entry, rule_state, num_newer_versions)) &&
645637
(num_non_current_days === undefined || this.filter_noncurrent_days(entry, num_non_current_days))) {
646638
if (filter_func(lifecycle_info)) {
@@ -706,7 +698,7 @@ class NCLifecycle {
706698
_get_lifecycle_object_info_for_mpu(create_params_parsed, stat) {
707699
return {
708700
key: create_params_parsed.key,
709-
age: this._get_file_age_days(stat.mtime.getTime()),
701+
age: lifecycle_utils.get_file_age_days(stat.mtime.getTime()),
710702
tags: create_params_parsed.tagging,
711703
};
712704
}
@@ -738,15 +730,6 @@ class NCLifecycle {
738730
};
739731
}
740732

741-
/**
742-
* get file time since last modified in days
743-
* @param {Number} mtime
744-
* @returns {Number} days since object was last modified
745-
*/
746-
_get_file_age_days(mtime) {
747-
return Math.floor((Date.now() - mtime) / 24 / 60 / 60 / 1000);
748-
}
749-
750733
/**
751734
* get the expiration time in days of an object
752735
* if rule is set with date, then rule is applied for all objects after that date

0 commit comments

Comments
 (0)