@@ -47,6 +47,13 @@ const TIMED_OPS = Object.freeze({
47
47
DELETE_MULTIPLE_OBJECTS : 'delete_multiple_objects'
48
48
} ) ;
49
49
50
+ /**
51
+ * @typedef {{
52
+ * is_finished?: Boolean | Undefined,
53
+ * expire?: { is_finished?: Boolean | Undefined, key_marker?: String | Undefined, candidates_file_offset?: number | undefined}
54
+ * noncurrent?: { is_finished?: Boolean | Undefined, key_marker_versioned?: String | Undefined, version_id_marker?: String | Undefined }
55
+ * }} RuleState
56
+ */
50
57
51
58
class NCLifecycle {
52
59
constructor ( config_fs , options = { } ) {
@@ -265,7 +272,7 @@ class NCLifecycle {
265
272
if ( candidates . delete_candidates ?. length > 0 ) {
266
273
const expiration = lifecycle_rule . expiration ? this . _get_expiration_time ( lifecycle_rule . expiration ) : 0 ;
267
274
const filter_func = this . _build_lifecycle_filter ( { filter : lifecycle_rule . filter , expiration} ) ;
268
-
275
+ dbg . log0 ( 'process_rule: calling delete_multiple_objects, num of objects to be deleted' , candidates . delete_candidates . length ) ;
269
276
const delete_res = await this . _call_op_and_update_status ( {
270
277
bucket_name,
271
278
rule_id,
@@ -282,6 +289,7 @@ class NCLifecycle {
282
289
}
283
290
284
291
if ( candidates . abort_mpu_candidates ?. length > 0 ) {
292
+ dbg . log0 ( 'process_rule: calling delete_multiple_objects, num of mpu to be aborted' , candidates . delete_candidates . length ) ;
285
293
await this . _call_op_and_update_status ( {
286
294
bucket_name,
287
295
rule_id,
@@ -465,7 +473,7 @@ class NCLifecycle {
465
473
* @returns {Promise<Object[]> }
466
474
*/
467
475
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 ;
476
+ const rule_state = this . _get_rule_state ( bucket_json , lifecycle_rule ) . expire ;
469
477
if ( rule_state . is_finished ) return [ ] ;
470
478
const expiration = this . _get_expiration_time ( lifecycle_rule . expiration ) ;
471
479
if ( expiration < 0 ) return [ ] ;
@@ -520,7 +528,7 @@ class NCLifecycle {
520
528
* @returns {Promise<Object[]> }
521
529
*/
522
530
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 ;
531
+ const rule_state = this . _get_rule_state ( bucket_json , lifecycle_rule ) . noncurrent ;
524
532
if ( rule_state . is_finished ) return [ ] ;
525
533
if ( ! versions_list ) {
526
534
versions_list = await this . load_versions_list ( object_sdk , lifecycle_rule , bucket_json , rule_state ) ;
@@ -619,7 +627,7 @@ class NCLifecycle {
619
627
* @returns {Promise<Object[]> }
620
628
*/
621
629
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 ;
630
+ const rule_state = this . _get_rule_state ( bucket_json , lifecycle_rule ) . noncurrent ;
623
631
if ( rule_state . is_finished ) return [ ] ;
624
632
625
633
if ( ! versions_list ) {
@@ -965,19 +973,22 @@ class NCLifecycle {
965
973
*/
966
974
init_rule_status ( bucket_name , rule_id ) {
967
975
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 : { } } ;
976
+ this . lifecycle_run_status . buckets_statuses [ bucket_name ] . rules_statuses [ rule_id ] . state ??= { expire : { } , noncurrent : { } } ;
969
977
this . lifecycle_run_status . buckets_statuses [ bucket_name ] . rules_statuses [ rule_id ] . rule_process_times = { } ;
970
978
this . lifecycle_run_status . buckets_statuses [ bucket_name ] . rules_statuses [ rule_id ] . rule_stats ??= { } ;
971
979
return this . lifecycle_run_status . buckets_statuses [ bucket_name ] . rules_statuses [ rule_id ] ;
972
980
}
973
981
974
982
/**
975
- * updates the rule state if all actions finished
983
+ * update_rule_status_is_finished updates the rule state if all actions finished
984
+ * notice that expire and noncurrent properties are initiated in init_rule_status()
985
+ * therefore they should not be undefined
976
986
* @param {string } bucket_name
977
987
* @param {string } rule_id
988
+ * @returns {Void }
978
989
*/
979
990
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 ;
991
+ const rule_state = this . _get_rule_state ( { name : bucket_name } , { id : rule_id } ) ;
981
992
rule_state . is_finished = ( rule_state . expire . is_finished === undefined || rule_state . expire . is_finished === true ) &&
982
993
( rule_state . noncurrent . is_finished === undefined || rule_state . noncurrent . is_finished === true ) ;
983
994
}
@@ -1011,18 +1022,20 @@ class NCLifecycle {
1011
1022
* _set_rule_state sets the current rule state on the lifecycle run status
1012
1023
* @param {Object } bucket_json
1013
1024
* @param {* } lifecycle_rule
1014
- * @param {{is_finished?: Boolean | Undefined, candidates_file_offset?: number | undefined} } rule_state
1025
+ * @param {RuleState } rule_state
1015
1026
* @returns {Void }
1016
1027
*/
1017
1028
_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 ;
1029
+ const existing_state = this . _get_rule_state ( bucket_json , lifecycle_rule ) ;
1030
+ const new_state = { ...existing_state , ...rule_state } ;
1031
+ this . lifecycle_run_status . buckets_statuses [ bucket_json . name ] . rules_statuses [ lifecycle_rule . id ] . state = new_state ;
1019
1032
}
1020
1033
1021
1034
/**
1022
1035
* _get_rule_state gets the current rule state on the lifecycle run status
1023
1036
* @param {Object } bucket_json
1024
1037
* @param {* } lifecycle_rule
1025
- * @returns {{is_finished?: Boolean | Undefined, candidates_file_offset?: number | undefined} } rule_state
1038
+ * @returns {RuleState }
1026
1039
*/
1027
1040
_get_rule_state ( bucket_json , lifecycle_rule ) {
1028
1041
return this . lifecycle_run_status . buckets_statuses [ bucket_json . name ] . rules_statuses [ lifecycle_rule . id ] . state ;
@@ -1164,6 +1177,7 @@ class NCLifecycle {
1164
1177
for ( const bucket_name of bucket_names ) {
1165
1178
const bucket_json = await this . config_fs . get_bucket_by_name ( bucket_name , config_fs_options ) ;
1166
1179
const bucket_mount_point = this . find_mount_point_by_bucket_path ( mount_point_to_policy_map , bucket_json . path ) ;
1180
+ if ( ! bucket_json . lifecycle_configuration_rules ?. length ) continue ;
1167
1181
for ( const lifecycle_rule of bucket_json . lifecycle_configuration_rules ) {
1168
1182
// currently we support expiration (current version) only
1169
1183
if ( lifecycle_rule . expiration ) {
@@ -1377,22 +1391,28 @@ class NCLifecycle {
1377
1391
* 1.2.2. parse the key from the candidate line
1378
1392
* 1.2.3. push the key to the candidates array
1379
1393
* 2. if candidates file does not exist, we return without error because it's valid that no candidates found
1394
+ * GAP - when supporting noncurrent rule, we should update the state type to noncurrent based on the candidates file path
1380
1395
* @param {Object } bucket_json
1381
1396
* @param {* } lifecycle_rule
1382
1397
* @param {String } rule_candidates_path
1383
1398
* @returns {Promise<Object[]> } parsed_candidates_array
1384
1399
*/
1385
1400
async parse_candidates_from_gpfs_ilm_policy ( bucket_json , lifecycle_rule , rule_candidates_path ) {
1386
1401
let reader ;
1402
+ const state_type = 'expire' ;
1403
+ const rule_state = this . _get_rule_state ( bucket_json , lifecycle_rule ) ?. [ state_type ] ;
1404
+ dbg . log2 ( `parse_candidates_from_gpfs_ilm_policy rule_state=${ rule_state } state_type=${ state_type } , currently on gpfs ilm flow - we support only expiration rule` ) ;
1405
+ if ( rule_state ?. is_finished ) return [ ] ;
1406
+ const finished_state = { [ state_type ] : { is_finished : true , candidates_file_offset : undefined } } ;
1407
+
1387
1408
try {
1388
- const rule_state = this . _get_rule_state ( bucket_json , lifecycle_rule ) ;
1389
1409
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
-
1391
1410
const parsed_candidates_array = [ ] ;
1392
1411
reader = new NewlineReader ( this . non_gpfs_fs_context , rule_candidates_path , { lock : 'SHARED' , read_file_offset : rule_state ?. candidates_file_offset || 0 } ) ;
1412
+
1393
1413
const [ count , is_finished ] = await reader . forEachFilePathEntry ( async entry => {
1394
1414
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 } ;
1415
+ const cur_rule_state = { [ state_type ] : { is_finished : false , candidates_file_offset : reader . next_line_file_offset } } ;
1396
1416
this . _set_rule_state ( bucket_json , lifecycle_rule , cur_rule_state ) ;
1397
1417
const key = this . _parse_key_from_line ( entry , bucket_json ) ;
1398
1418
// TODO - need to add etag, size, version_id
@@ -1402,14 +1422,14 @@ class NCLifecycle {
1402
1422
} ) ;
1403
1423
1404
1424
if ( is_finished ) {
1405
- 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 ) ;
1406
1426
}
1407
1427
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
1428
return parsed_candidates_array ;
1409
1429
} catch ( err ) {
1410
1430
if ( err . code === 'ENOENT' ) {
1411
1431
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 } ) ;
1432
+ this . _set_rule_state ( bucket_json , lifecycle_rule , finished_state ) ;
1413
1433
return ;
1414
1434
}
1415
1435
dbg . error ( 'parse_candidates_from_gpfs_ilm_policy: error' , err ) ;
0 commit comments