@@ -5,8 +5,7 @@ const path = require('path');
5
5
const { PersistentLogger } = require ( '../util/persistent_logger' ) ;
6
6
const config = require ( '../../config' ) ;
7
7
const nb_native = require ( '../util/nb_native' ) ;
8
- const { GlacierBackend } = require ( '../sdk/nsfs_glacier_backend/backend' ) ;
9
- const { getGlacierBackend } = require ( '../sdk/nsfs_glacier_backend/helper' ) ;
8
+ const { Glacier } = require ( '../sdk/glacier' ) ;
10
9
const native_fs_utils = require ( '../util/native_fs_utils' ) ;
11
10
12
11
const CLUSTER_LOCK = 'cluster.lock' ;
@@ -16,14 +15,14 @@ async function process_migrations() {
16
15
const fs_context = native_fs_utils . get_process_fs_context ( ) ;
17
16
18
17
await lock_and_run ( fs_context , CLUSTER_LOCK , async ( ) => {
19
- const backend = getGlacierBackend ( ) ;
18
+ const backend = Glacier . getBackend ( ) ;
20
19
21
20
if (
22
21
await backend . low_free_space ( ) ||
23
- await time_exceeded ( fs_context , config . NSFS_GLACIER_MIGRATE_INTERVAL , GlacierBackend . MIGRATE_TIMESTAMP_FILE )
22
+ await time_exceeded ( fs_context , config . NSFS_GLACIER_MIGRATE_INTERVAL , Glacier . MIGRATE_TIMESTAMP_FILE )
24
23
) {
25
24
await run_glacier_migrations ( fs_context , backend ) ;
26
- await record_current_time ( fs_context , GlacierBackend . MIGRATE_TIMESTAMP_FILE ) ;
25
+ await record_current_time ( fs_context , Glacier . MIGRATE_TIMESTAMP_FILE ) ;
27
26
}
28
27
} ) ;
29
28
}
@@ -32,56 +31,56 @@ async function process_migrations() {
32
31
* run_tape_migrations reads the migration WALs and attempts to migrate the
33
32
* files mentioned in the WAL.
34
33
* @param {nb.NativeFSContext } fs_context
35
- * @param {import('../sdk/nsfs_glacier_backend/backend ').GlacierBackend } backend
34
+ * @param {import('../sdk/glacier ').Glacier } backend
36
35
*/
37
36
async function run_glacier_migrations ( fs_context , backend ) {
38
- await run_glacier_operation ( fs_context , GlacierBackend . MIGRATE_WAL_NAME , backend . migrate . bind ( backend ) ) ;
37
+ await run_glacier_operation ( fs_context , Glacier . MIGRATE_WAL_NAME , backend . migrate . bind ( backend ) ) ;
39
38
}
40
39
41
40
async function process_restores ( ) {
42
41
const fs_context = native_fs_utils . get_process_fs_context ( ) ;
43
42
44
43
await lock_and_run ( fs_context , CLUSTER_LOCK , async ( ) => {
45
- const backend = getGlacierBackend ( ) ;
44
+ const backend = Glacier . getBackend ( ) ;
46
45
47
46
if (
48
47
await backend . low_free_space ( ) ||
49
- ! ( await time_exceeded ( fs_context , config . NSFS_GLACIER_RESTORE_INTERVAL , GlacierBackend . RESTORE_TIMESTAMP_FILE ) )
48
+ ! ( await time_exceeded ( fs_context , config . NSFS_GLACIER_RESTORE_INTERVAL , Glacier . RESTORE_TIMESTAMP_FILE ) )
50
49
) return ;
51
50
52
51
53
52
await run_glacier_restore ( fs_context , backend ) ;
54
- await record_current_time ( fs_context , GlacierBackend . RESTORE_TIMESTAMP_FILE ) ;
53
+ await record_current_time ( fs_context , Glacier . RESTORE_TIMESTAMP_FILE ) ;
55
54
} ) ;
56
55
}
57
56
58
57
/**
59
58
* run_tape_restore reads the restore WALs and attempts to restore the
60
59
* files mentioned in the WAL.
61
- * @param {nb.NativeFSContext } fs_context
62
- * @param {import('../sdk/nsfs_glacier_backend/backend ').GlacierBackend } backend
60
+ * @param {nb.NativeFSContext } fs_context
61
+ * @param {import('../sdk/glacier ').Glacier } backend
63
62
*/
64
63
async function run_glacier_restore ( fs_context , backend ) {
65
- await run_glacier_operation ( fs_context , GlacierBackend . RESTORE_WAL_NAME , backend . restore . bind ( backend ) ) ;
64
+ await run_glacier_operation ( fs_context , Glacier . RESTORE_WAL_NAME , backend . restore . bind ( backend ) ) ;
66
65
}
67
66
68
67
async function process_expiry ( ) {
69
- const fs_context = native_fs_utils . get_process_fs_context ( ) ;
68
+ const fs_context = force_gpfs_fs_context ( native_fs_utils . get_process_fs_context ( ) ) ;
70
69
71
70
await lock_and_run ( fs_context , SCAN_LOCK , async ( ) => {
72
- const backend = getGlacierBackend ( ) ;
71
+ const backend = Glacier . getBackend ( ) ;
73
72
if (
74
73
await backend . low_free_space ( ) ||
75
74
await is_desired_time (
76
75
fs_context ,
77
76
new Date ( ) ,
78
77
config . NSFS_GLACIER_EXPIRY_RUN_TIME ,
79
78
config . NSFS_GLACIER_EXPIRY_RUN_DELAY_LIMIT_MINS ,
80
- GlacierBackend . EXPIRY_TIMESTAMP_FILE ,
79
+ Glacier . EXPIRY_TIMESTAMP_FILE ,
81
80
)
82
81
) {
83
82
await backend . expiry ( fs_context ) ;
84
- await record_current_time ( fs_context , GlacierBackend . EXPIRY_TIMESTAMP_FILE ) ;
83
+ await record_current_time ( fs_context , Glacier . EXPIRY_TIMESTAMP_FILE ) ;
85
84
}
86
85
} ) ;
87
86
}
@@ -178,6 +177,8 @@ async function record_current_time(fs_context, timestamp_file) {
178
177
*/
179
178
async function run_glacier_operation ( fs_context , log_namespace , cb ) {
180
179
const log = new PersistentLogger ( config . NSFS_GLACIER_LOGS_DIR , log_namespace , { locking : 'EXCLUSIVE' } ) ;
180
+
181
+ fs_context = force_gpfs_fs_context ( fs_context ) ;
181
182
try {
182
183
await log . process ( async ( entry , failure_recorder ) => cb ( fs_context , entry , failure_recorder ) ) ;
183
184
} catch ( error ) {
@@ -212,6 +213,28 @@ function get_tz_date(hours, mins, secs, tz) {
212
213
return date ;
213
214
}
214
215
216
+ /**
217
+ * force_gpfs_fs_context returns a shallow copy of given
218
+ * fs_context with backend set to 'GPFS'.
219
+ *
220
+ * NOTE: The function will throw error if it detects that GPFS
221
+ * DL isn't loaded.
222
+ *
223
+ * @param {nb.NativeFSContext } fs_context
224
+ * @returns {nb.NativeFSContext }
225
+ */
226
+ function force_gpfs_fs_context ( fs_context ) {
227
+ if ( config . NSFS_GLACIER_USE_DMAPI ) {
228
+ if ( ! nb_native ( ) . fs . gpfs ) {
229
+ throw new Error ( 'cannot use DMAPI EA: gpfs dl not loaded' ) ;
230
+ }
231
+
232
+ return { ...fs_context , backend : 'GPFS' , use_dmapi : true } ;
233
+ }
234
+
235
+ return { ...fs_context } ;
236
+ }
237
+
215
238
/**
216
239
* lock_and_run acquires a flock and calls the given callback after
217
240
* acquiring the lock
0 commit comments