Skip to content

Commit 9d36c09

Browse files
committed
NC | Lifecycle | Adjust expire/noncurrent state properties to GPFS flow
Signed-off-by: Romy <35330373+romayalon@users.noreply.github.com>
1 parent 947eb7f commit 9d36c09

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

src/manage_nsfs/nc_lifecycle.js

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ class NCLifecycle {
465465
* @returns {Promise<Object[]>}
466466
*/
467467
async get_candidates_by_expiration_rule_posix(lifecycle_rule, bucket_json, object_sdk) {
468-
const rule_state = this.lifecycle_run_status.buckets_statuses[bucket_json.name].rules_statuses[lifecycle_rule.id].state.expire;
468+
const rule_state = this._get_rule_state(bucket_json, lifecycle_rule).expire;
469469
if (rule_state.is_finished) return [];
470470
const expiration = this._get_expiration_time(lifecycle_rule.expiration);
471471
if (expiration < 0) return [];
@@ -520,7 +520,7 @@ class NCLifecycle {
520520
* @returns {Promise<Object[]>}
521521
*/
522522
async get_candidates_by_expiration_delete_marker_rule(lifecycle_rule, bucket_json, object_sdk, {versions_list}) {
523-
const rule_state = this.lifecycle_run_status.buckets_statuses[bucket_json.name].rules_statuses[lifecycle_rule.id].state.noncurrent;
523+
const rule_state = this._get_rule_state(bucket_json, lifecycle_rule).noncurrent;
524524
if (rule_state.is_finished) return [];
525525
if (!versions_list) {
526526
versions_list = await this.load_versions_list(object_sdk, lifecycle_rule, bucket_json, rule_state);
@@ -619,7 +619,7 @@ class NCLifecycle {
619619
* @returns {Promise<Object[]>}
620620
*/
621621
async get_candidates_by_noncurrent_version_expiration_rule(lifecycle_rule, bucket_json, object_sdk, {versions_list}) {
622-
const rule_state = this.lifecycle_run_status.buckets_statuses[bucket_json.name].rules_statuses[lifecycle_rule.id].state.noncurrent;
622+
const rule_state = this._get_rule_state(bucket_json, lifecycle_rule).noncurrent;
623623
if (rule_state.is_finished) return [];
624624

625625
if (!versions_list) {
@@ -965,7 +965,7 @@ class NCLifecycle {
965965
*/
966966
init_rule_status(bucket_name, rule_id) {
967967
this.lifecycle_run_status.buckets_statuses[bucket_name].rules_statuses[rule_id] ??= {};
968-
this.lifecycle_run_status.buckets_statuses[bucket_name].rules_statuses[rule_id].state ??= {expire: {}, noncurrent: {}};
968+
this.lifecycle_run_status.buckets_statuses[bucket_name].rules_statuses[rule_id].state ??= { expire: {}, noncurrent: {} };
969969
this.lifecycle_run_status.buckets_statuses[bucket_name].rules_statuses[rule_id].rule_process_times = {};
970970
this.lifecycle_run_status.buckets_statuses[bucket_name].rules_statuses[rule_id].rule_stats ??= {};
971971
return this.lifecycle_run_status.buckets_statuses[bucket_name].rules_statuses[rule_id];
@@ -977,9 +977,9 @@ class NCLifecycle {
977977
* @param {string} rule_id
978978
*/
979979
update_rule_status_is_finished(bucket_name, rule_id) {
980-
const rule_state = this.lifecycle_run_status.buckets_statuses[bucket_name].rules_statuses[rule_id].state;
981-
rule_state.is_finished = (rule_state.expire.is_finished === undefined || rule_state.expire.is_finished === true) &&
982-
(rule_state.noncurrent.is_finished === undefined || rule_state.noncurrent.is_finished === true);
980+
const rule_state = this._get_rule_state({ name: bucket_name }, { id: rule_id });
981+
rule_state.is_finished = (rule_state.expire?.is_finished === undefined || rule_state.expire?.is_finished === true) &&
982+
(rule_state.noncurrent?.is_finished === undefined || rule_state.noncurrent?.is_finished === true);
983983
}
984984

985985
/**
@@ -1011,7 +1011,10 @@ class NCLifecycle {
10111011
* _set_rule_state sets the current rule state on the lifecycle run status
10121012
* @param {Object} bucket_json
10131013
* @param {*} lifecycle_rule
1014-
* @param {{is_finished?: Boolean | Undefined, candidates_file_offset?: number | undefined}} rule_state
1014+
* @param {{
1015+
* is_finished?: Boolean | Undefined,
1016+
* expire?: {is_finished?: Boolean | Undefined, key_marker?: String | Undefined, candidates_file_offset?: number | undefined}
1017+
* noncurrent?: {is_finished?: Boolean | Undefined, key_marker_versioned?: String | Undefined, version_id_marker?: String | Undefined }}} rule_state
10151018
* @returns {Void}
10161019
*/
10171020
_set_rule_state(bucket_json, lifecycle_rule, rule_state) {
@@ -1022,7 +1025,10 @@ class NCLifecycle {
10221025
* _get_rule_state gets the current rule state on the lifecycle run status
10231026
* @param {Object} bucket_json
10241027
* @param {*} lifecycle_rule
1025-
* @returns {{is_finished?: Boolean | Undefined, candidates_file_offset?: number | undefined}} rule_state
1028+
* @returns {{
1029+
* is_finished: Boolean | Undefined,
1030+
* expire?: {is_finished?: Boolean | Undefined, key_marker?: String | Undefined, candidates_file_offset?: number | undefined}
1031+
* noncurrent?: {is_finished?: Boolean | Undefined, key_marker_versioned?: String | Undefined, version_id_marker?: String | Undefined }}} rule_state
10261032
*/
10271033
_get_rule_state(bucket_json, lifecycle_rule) {
10281034
return this.lifecycle_run_status.buckets_statuses[bucket_json.name].rules_statuses[lifecycle_rule.id].state;
@@ -1164,6 +1170,7 @@ class NCLifecycle {
11641170
for (const bucket_name of bucket_names) {
11651171
const bucket_json = await this.config_fs.get_bucket_by_name(bucket_name, config_fs_options);
11661172
const bucket_mount_point = this.find_mount_point_by_bucket_path(mount_point_to_policy_map, bucket_json.path);
1173+
if (!bucket_json.lifecycle_configuration_rules?.length) continue;
11671174
for (const lifecycle_rule of bucket_json.lifecycle_configuration_rules) {
11681175
// currently we support expiration (current version) only
11691176
if (lifecycle_rule.expiration) {
@@ -1377,22 +1384,28 @@ class NCLifecycle {
13771384
* 1.2.2. parse the key from the candidate line
13781385
* 1.2.3. push the key to the candidates array
13791386
* 2. if candidates file does not exist, we return without error because it's valid that no candidates found
1387+
* GAP - when supporting noncurrent rule, we should update the state type to noncurrent based on the candidates file path
13801388
* @param {Object} bucket_json
13811389
* @param {*} lifecycle_rule
13821390
* @param {String} rule_candidates_path
13831391
* @returns {Promise<Object[]>} parsed_candidates_array
13841392
*/
13851393
async parse_candidates_from_gpfs_ilm_policy(bucket_json, lifecycle_rule, rule_candidates_path) {
13861394
let reader;
1395+
const state_type = 'expire';
1396+
const rule_state = this._get_rule_state(bucket_json, lifecycle_rule)?.[state_type];
1397+
if (rule_state?.is_finished) return [];
1398+
const finished_state = { [state_type]: { is_finished: true, candidates_file_offset: undefined } };
1399+
13871400
try {
1388-
const rule_state = this._get_rule_state(bucket_json, lifecycle_rule);
1389-
dbg.log2(`parse_candidates_from_gpfs_ilm_policy bucket_name=${bucket_json.name}, rule_id ${lifecycle_rule.id}, existing rule_state=${util.inspect(rule_state)}`);
13901401

1402+
dbg.log2(`parse_candidates_from_gpfs_ilm_policy bucket_name=${bucket_json.name}, rule_id ${lifecycle_rule.id}, existing rule_state=${util.inspect(rule_state)}`);
13911403
const parsed_candidates_array = [];
13921404
reader = new NewlineReader(this.non_gpfs_fs_context, rule_candidates_path, { lock: 'SHARED', read_file_offset: rule_state?.candidates_file_offset || 0 });
1405+
13931406
const [count, is_finished] = await reader.forEachFilePathEntry(async entry => {
13941407
if (parsed_candidates_array.length >= config.NC_LIFECYCLE_LIST_BATCH_SIZE) return false;
1395-
const cur_rule_state = { is_finished: false, candidates_file_offset: reader.next_line_file_offset };
1408+
const cur_rule_state = { [state_type]: { is_finished: false, candidates_file_offset: reader.next_line_file_offset } };
13961409
this._set_rule_state(bucket_json, lifecycle_rule, cur_rule_state);
13971410
const key = this._parse_key_from_line(entry, bucket_json);
13981411
// TODO - need to add etag, size, version_id
@@ -1402,14 +1415,14 @@ class NCLifecycle {
14021415
});
14031416

14041417
if (is_finished) {
1405-
this._set_rule_state(bucket_json, lifecycle_rule, { is_finished: true, candidates_file_offset: undefined });
1418+
this._set_rule_state(bucket_json, lifecycle_rule, finished_state);
14061419
}
14071420
dbg.log2(`parse_candidates_from_gpfs_ilm_policy: parsed_candidates_array ${util.inspect(parsed_candidates_array)}, rule_state=${util.inspect(rule_state)}, count=${count} is_finished=${is_finished}`);
14081421
return parsed_candidates_array;
14091422
} catch (err) {
14101423
if (err.code === 'ENOENT') {
14111424
dbg.log2(`parse_candidates_from_gpfs_ilm_policy ilm_candidates_file_exists does not exist, no candidates to delete`);
1412-
this._set_rule_state(bucket_json, lifecycle_rule, { is_finished: true, candidates_file_offset: undefined });
1425+
this._set_rule_state(bucket_json, lifecycle_rule, finished_state);
14131426
return;
14141427
}
14151428
dbg.error('parse_candidates_from_gpfs_ilm_policy: error', err);

0 commit comments

Comments
 (0)