@@ -465,7 +465,7 @@ class NCLifecycle {
465
465
* @returns {Promise<Object[]> }
466
466
*/
467
467
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 ;
469
469
if ( rule_state . is_finished ) return [ ] ;
470
470
const expiration = this . _get_expiration_time ( lifecycle_rule . expiration ) ;
471
471
if ( expiration < 0 ) return [ ] ;
@@ -520,7 +520,7 @@ class NCLifecycle {
520
520
* @returns {Promise<Object[]> }
521
521
*/
522
522
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 ;
524
524
if ( rule_state . is_finished ) return [ ] ;
525
525
if ( ! versions_list ) {
526
526
versions_list = await this . load_versions_list ( object_sdk , lifecycle_rule , bucket_json , rule_state ) ;
@@ -619,7 +619,7 @@ class NCLifecycle {
619
619
* @returns {Promise<Object[]> }
620
620
*/
621
621
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 ;
623
623
if ( rule_state . is_finished ) return [ ] ;
624
624
625
625
if ( ! versions_list ) {
@@ -965,7 +965,7 @@ class NCLifecycle {
965
965
*/
966
966
init_rule_status ( bucket_name , rule_id ) {
967
967
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 : { } } ;
969
969
this . lifecycle_run_status . buckets_statuses [ bucket_name ] . rules_statuses [ rule_id ] . rule_process_times = { } ;
970
970
this . lifecycle_run_status . buckets_statuses [ bucket_name ] . rules_statuses [ rule_id ] . rule_stats ??= { } ;
971
971
return this . lifecycle_run_status . buckets_statuses [ bucket_name ] . rules_statuses [ rule_id ] ;
@@ -977,7 +977,7 @@ class NCLifecycle {
977
977
* @param {string } rule_id
978
978
*/
979
979
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 ;
980
+ const rule_state = this . _get_rule_state ( { name : bucket_name } , { id : rule_id } ) ;
981
981
rule_state . is_finished = ( rule_state . expire . is_finished === undefined || rule_state . expire . is_finished === true ) &&
982
982
( rule_state . noncurrent . is_finished === undefined || rule_state . noncurrent . is_finished === true ) ;
983
983
}
@@ -1011,18 +1011,26 @@ class NCLifecycle {
1011
1011
* _set_rule_state sets the current rule state on the lifecycle run status
1012
1012
* @param {Object } bucket_json
1013
1013
* @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
1015
1018
* @returns {Void }
1016
1019
*/
1017
1020
_set_rule_state ( bucket_json , lifecycle_rule , rule_state ) {
1018
- this . lifecycle_run_status . buckets_statuses [ bucket_json . name ] . rules_statuses [ lifecycle_rule . id ] . state = rule_state ;
1021
+ const existing_state = this . _get_rule_state ( bucket_json , lifecycle_rule ) ;
1022
+ const new_state = { ...existing_state , ...rule_state } ;
1023
+ this . lifecycle_run_status . buckets_statuses [ bucket_json . name ] . rules_statuses [ lifecycle_rule . id ] . state = new_state ;
1019
1024
}
1020
1025
1021
1026
/**
1022
1027
* _get_rule_state gets the current rule state on the lifecycle run status
1023
1028
* @param {Object } bucket_json
1024
1029
* @param {* } lifecycle_rule
1025
- * @returns {{is_finished?: Boolean | Undefined, candidates_file_offset?: number | undefined} } rule_state
1030
+ * @returns {{
1031
+ * is_finished: Boolean | Undefined,
1032
+ * expire?: {is_finished?: Boolean | Undefined, key_marker?: String | Undefined, candidates_file_offset?: number | undefined}
1033
+ * noncurrent?: {is_finished?: Boolean | Undefined, key_marker_versioned?: String | Undefined, version_id_marker?: String | Undefined } }} rule_state
1026
1034
*/
1027
1035
_get_rule_state ( bucket_json , lifecycle_rule ) {
1028
1036
return this . lifecycle_run_status . buckets_statuses [ bucket_json . name ] . rules_statuses [ lifecycle_rule . id ] . state ;
@@ -1164,6 +1172,7 @@ class NCLifecycle {
1164
1172
for ( const bucket_name of bucket_names ) {
1165
1173
const bucket_json = await this . config_fs . get_bucket_by_name ( bucket_name , config_fs_options ) ;
1166
1174
const bucket_mount_point = this . find_mount_point_by_bucket_path ( mount_point_to_policy_map , bucket_json . path ) ;
1175
+ if ( ! bucket_json . lifecycle_configuration_rules ?. length ) continue ;
1167
1176
for ( const lifecycle_rule of bucket_json . lifecycle_configuration_rules ) {
1168
1177
// currently we support expiration (current version) only
1169
1178
if ( lifecycle_rule . expiration ) {
@@ -1377,22 +1386,28 @@ class NCLifecycle {
1377
1386
* 1.2.2. parse the key from the candidate line
1378
1387
* 1.2.3. push the key to the candidates array
1379
1388
* 2. if candidates file does not exist, we return without error because it's valid that no candidates found
1389
+ * GAP - when supporting noncurrent rule, we should update the state type to noncurrent based on the candidates file path
1380
1390
* @param {Object } bucket_json
1381
1391
* @param {* } lifecycle_rule
1382
1392
* @param {String } rule_candidates_path
1383
1393
* @returns {Promise<Object[]> } parsed_candidates_array
1384
1394
*/
1385
1395
async parse_candidates_from_gpfs_ilm_policy ( bucket_json , lifecycle_rule , rule_candidates_path ) {
1386
1396
let reader ;
1397
+ const state_type = 'expire' ;
1398
+ const rule_state = this . _get_rule_state ( bucket_json , lifecycle_rule ) ?. [ state_type ] ;
1399
+ if ( rule_state ?. is_finished ) return [ ] ;
1400
+ const finished_state = { [ state_type ] : { is_finished : true , candidates_file_offset : undefined } } ;
1401
+
1387
1402
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 ) } ` ) ;
1390
1403
1404
+ 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 ) } ` ) ;
1391
1405
const parsed_candidates_array = [ ] ;
1392
1406
reader = new NewlineReader ( this . non_gpfs_fs_context , rule_candidates_path , { lock : 'SHARED' , read_file_offset : rule_state ?. candidates_file_offset || 0 } ) ;
1407
+
1393
1408
const [ count , is_finished ] = await reader . forEachFilePathEntry ( async entry => {
1394
1409
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 } ;
1410
+ const cur_rule_state = { [ state_type ] : { is_finished : false , candidates_file_offset : reader . next_line_file_offset } } ;
1396
1411
this . _set_rule_state ( bucket_json , lifecycle_rule , cur_rule_state ) ;
1397
1412
const key = this . _parse_key_from_line ( entry , bucket_json ) ;
1398
1413
// TODO - need to add etag, size, version_id
@@ -1402,14 +1417,14 @@ class NCLifecycle {
1402
1417
} ) ;
1403
1418
1404
1419
if ( is_finished ) {
1405
- this . _set_rule_state ( bucket_json , lifecycle_rule , { is_finished : true , candidates_file_offset : undefined } ) ;
1420
+ this . _set_rule_state ( bucket_json , lifecycle_rule , finished_state ) ;
1406
1421
}
1407
1422
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 } ` ) ;
1408
1423
return parsed_candidates_array ;
1409
1424
} catch ( err ) {
1410
1425
if ( err . code === 'ENOENT' ) {
1411
1426
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 } ) ;
1427
+ this . _set_rule_state ( bucket_json , lifecycle_rule , finished_state ) ;
1413
1428
return ;
1414
1429
}
1415
1430
dbg . error ( 'parse_candidates_from_gpfs_ilm_policy: error' , err ) ;
0 commit comments