@@ -9,86 +9,53 @@ const { Glacier } = require('../sdk/glacier');
9
9
const native_fs_utils = require ( '../util/native_fs_utils' ) ;
10
10
const { is_desired_time, record_current_time } = require ( './manage_nsfs_cli_utils' ) ;
11
11
12
- const CLUSTER_LOCK = 'cluster.lock' ;
13
- const SCAN_LOCK = 'scan.lock' ;
14
-
15
12
async function process_migrations ( ) {
16
13
const fs_context = native_fs_utils . get_process_fs_context ( ) ;
17
- const lock_path = path . join ( config . NSFS_GLACIER_LOGS_DIR , CLUSTER_LOCK ) ;
18
- await native_fs_utils . lock_and_run ( fs_context , lock_path , async ( ) => {
19
- const backend = Glacier . getBackend ( ) ;
20
-
21
- if (
22
- await backend . low_free_space ( ) ||
23
- await time_exceeded ( fs_context , config . NSFS_GLACIER_MIGRATE_INTERVAL , Glacier . MIGRATE_TIMESTAMP_FILE ) ||
24
- await migrate_log_exceeds_threshold ( )
25
- ) {
26
- await run_glacier_migrations ( fs_context , backend ) ;
27
- const timestamp_file_path = path . join ( config . NSFS_GLACIER_LOGS_DIR , Glacier . MIGRATE_TIMESTAMP_FILE ) ;
28
- await record_current_time ( fs_context , timestamp_file_path ) ;
29
- }
30
- } ) ;
31
- }
32
-
33
- /**
34
- * run_tape_migrations reads the migration WALs and attempts to migrate the
35
- * files mentioned in the WAL.
36
- * @param {nb.NativeFSContext } fs_context
37
- * @param {import('../sdk/glacier').Glacier } backend
38
- */
39
- async function run_glacier_migrations ( fs_context , backend ) {
40
- await run_glacier_operation ( fs_context , Glacier . MIGRATE_WAL_NAME , backend . migrate . bind ( backend ) ) ;
14
+ const backend = Glacier . getBackend ( ) ;
15
+
16
+ if (
17
+ await backend . low_free_space ( ) ||
18
+ await time_exceeded ( fs_context , config . NSFS_GLACIER_MIGRATE_INTERVAL , Glacier . MIGRATE_TIMESTAMP_FILE ) ||
19
+ await migrate_log_exceeds_threshold ( )
20
+ ) {
21
+ await backend . perform ( prepare_galcier_fs_context ( fs_context ) , "MIGRATION" ) ;
22
+ const timestamp_file_path = path . join ( config . NSFS_GLACIER_LOGS_DIR , Glacier . MIGRATE_TIMESTAMP_FILE ) ;
23
+ await record_current_time ( fs_context , timestamp_file_path ) ;
24
+ }
41
25
}
42
26
43
27
async function process_restores ( ) {
44
28
const fs_context = native_fs_utils . get_process_fs_context ( ) ;
45
- const lock_path = path . join ( config . NSFS_GLACIER_LOGS_DIR , CLUSTER_LOCK ) ;
46
- await native_fs_utils . lock_and_run ( fs_context , lock_path , async ( ) => {
47
- const backend = Glacier . getBackend ( ) ;
29
+ const backend = Glacier . getBackend ( ) ;
48
30
49
- if (
50
- await backend . low_free_space ( ) ||
51
- ! ( await time_exceeded ( fs_context , config . NSFS_GLACIER_RESTORE_INTERVAL , Glacier . RESTORE_TIMESTAMP_FILE ) )
52
- ) return ;
31
+ if (
32
+ await backend . low_free_space ( ) ||
33
+ ! ( await time_exceeded ( fs_context , config . NSFS_GLACIER_RESTORE_INTERVAL , Glacier . RESTORE_TIMESTAMP_FILE ) )
34
+ ) return ;
53
35
54
-
55
- await run_glacier_restore ( fs_context , backend ) ;
56
- const timestamp_file_path = path . join ( config . NSFS_GLACIER_LOGS_DIR , Glacier . RESTORE_TIMESTAMP_FILE ) ;
57
- await record_current_time ( fs_context , timestamp_file_path ) ;
58
- } ) ;
59
- }
60
-
61
- /**
62
- * run_tape_restore reads the restore WALs and attempts to restore the
63
- * files mentioned in the WAL.
64
- * @param {nb.NativeFSContext } fs_context
65
- * @param {import('../sdk/glacier').Glacier } backend
66
- */
67
- async function run_glacier_restore ( fs_context , backend ) {
68
- await run_glacier_operation ( fs_context , Glacier . RESTORE_WAL_NAME , backend . restore . bind ( backend ) ) ;
36
+ await backend . perform ( prepare_galcier_fs_context ( fs_context ) , "RESTORE" ) ;
37
+ const timestamp_file_path = path . join ( config . NSFS_GLACIER_LOGS_DIR , Glacier . RESTORE_TIMESTAMP_FILE ) ;
38
+ await record_current_time ( fs_context , timestamp_file_path ) ;
69
39
}
70
40
71
41
async function process_expiry ( ) {
72
42
const fs_context = native_fs_utils . get_process_fs_context ( ) ;
73
- const lock_path = path . join ( config . NSFS_GLACIER_LOGS_DIR , SCAN_LOCK ) ;
74
- await native_fs_utils . lock_and_run ( fs_context , lock_path , async ( ) => {
75
- const backend = Glacier . getBackend ( ) ;
76
- const timestamp_file_path = path . join ( config . NSFS_GLACIER_LOGS_DIR , Glacier . EXPIRY_TIMESTAMP_FILE ) ;
77
- if (
78
- await backend . low_free_space ( ) ||
79
- await is_desired_time (
80
- fs_context ,
81
- new Date ( ) ,
82
- config . NSFS_GLACIER_EXPIRY_RUN_TIME ,
83
- config . NSFS_GLACIER_EXPIRY_RUN_DELAY_LIMIT_MINS ,
84
- timestamp_file_path ,
85
- config . NSFS_GLACIER_EXPIRY_TZ
86
- )
87
- ) {
88
- await backend . expiry ( fs_context ) ;
89
- await record_current_time ( fs_context , timestamp_file_path ) ;
90
- }
91
- } ) ;
43
+ const backend = Glacier . getBackend ( ) ;
44
+ const timestamp_file_path = path . join ( config . NSFS_GLACIER_LOGS_DIR , Glacier . EXPIRY_TIMESTAMP_FILE ) ;
45
+ if (
46
+ await backend . low_free_space ( ) ||
47
+ await is_desired_time (
48
+ fs_context ,
49
+ new Date ( ) ,
50
+ config . NSFS_GLACIER_EXPIRY_RUN_TIME ,
51
+ config . NSFS_GLACIER_EXPIRY_RUN_DELAY_LIMIT_MINS ,
52
+ timestamp_file_path ,
53
+ config . NSFS_GLACIER_EXPIRY_TZ
54
+ )
55
+ ) {
56
+ await backend . perform ( prepare_galcier_fs_context ( fs_context ) , "EXPIRY" ) ;
57
+ await record_current_time ( fs_context , timestamp_file_path ) ;
58
+ }
92
59
}
93
60
94
61
@@ -137,27 +104,6 @@ async function migrate_log_exceeds_threshold(threshold = config.NSFS_GLACIER_MIG
137
104
return log_size > threshold ;
138
105
}
139
106
140
- /**
141
- * run_glacier_operations takes a log_namespace and a callback and executes the
142
- * callback on each log file in that namespace. It will also generate a failure
143
- * log file and persist the failures in that log file.
144
- * @param {nb.NativeFSContext } fs_context
145
- * @param {string } log_namespace
146
- * @param {Function } cb
147
- */
148
- async function run_glacier_operation ( fs_context , log_namespace , cb ) {
149
- const log = new PersistentLogger ( config . NSFS_GLACIER_LOGS_DIR , log_namespace , { locking : 'EXCLUSIVE' } ) ;
150
-
151
- fs_context = prepare_galcier_fs_context ( fs_context ) ;
152
- try {
153
- await log . process ( async ( entry , failure_recorder ) => cb ( fs_context , entry , failure_recorder ) ) ;
154
- } catch ( error ) {
155
- console . error ( 'failed to process log in namespace:' , log_namespace ) ;
156
- } finally {
157
- await log . close ( ) ;
158
- }
159
- }
160
-
161
107
/**
162
108
* prepare_galcier_fs_context returns a shallow copy of given
163
109
* fs_context with backend set to 'GPFS'.
0 commit comments