@@ -5,8 +5,7 @@ const path = require('path');
55const { PersistentLogger } = require ( '../util/persistent_logger' ) ;
66const config = require ( '../../config' ) ;
77const 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' ) ;
109const native_fs_utils = require ( '../util/native_fs_utils' ) ;
1110
1211const CLUSTER_LOCK = 'cluster.lock' ;
@@ -16,14 +15,14 @@ async function process_migrations() {
1615 const fs_context = native_fs_utils . get_process_fs_context ( ) ;
1716
1817 await lock_and_run ( fs_context , CLUSTER_LOCK , async ( ) => {
19- const backend = getGlacierBackend ( ) ;
18+ const backend = Glacier . getBackend ( ) ;
2019
2120 if (
2221 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 )
2423 ) {
2524 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 ) ;
2726 }
2827 } ) ;
2928}
@@ -32,56 +31,56 @@ async function process_migrations() {
3231 * run_tape_migrations reads the migration WALs and attempts to migrate the
3332 * files mentioned in the WAL.
3433 * @param {nb.NativeFSContext } fs_context
35- * @param {import('../sdk/nsfs_glacier_backend/backend ').GlacierBackend } backend
34+ * @param {import('../sdk/glacier ').Glacier } backend
3635 */
3736async 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 ) ) ;
3938}
4039
4140async function process_restores ( ) {
4241 const fs_context = native_fs_utils . get_process_fs_context ( ) ;
4342
4443 await lock_and_run ( fs_context , CLUSTER_LOCK , async ( ) => {
45- const backend = getGlacierBackend ( ) ;
44+ const backend = Glacier . getBackend ( ) ;
4645
4746 if (
4847 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 ) )
5049 ) return ;
5150
5251
5352 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 ) ;
5554 } ) ;
5655}
5756
5857/**
5958 * run_tape_restore reads the restore WALs and attempts to restore the
6059 * 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
6362 */
6463async 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 ) ) ;
6665}
6766
6867async 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 ( ) ) ;
7069
7170 await lock_and_run ( fs_context , SCAN_LOCK , async ( ) => {
72- const backend = getGlacierBackend ( ) ;
71+ const backend = Glacier . getBackend ( ) ;
7372 if (
7473 await backend . low_free_space ( ) ||
7574 await is_desired_time (
7675 fs_context ,
7776 new Date ( ) ,
7877 config . NSFS_GLACIER_EXPIRY_RUN_TIME ,
7978 config . NSFS_GLACIER_EXPIRY_RUN_DELAY_LIMIT_MINS ,
80- GlacierBackend . EXPIRY_TIMESTAMP_FILE ,
79+ Glacier . EXPIRY_TIMESTAMP_FILE ,
8180 )
8281 ) {
8382 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 ) ;
8584 }
8685 } ) ;
8786}
@@ -178,6 +177,8 @@ async function record_current_time(fs_context, timestamp_file) {
178177 */
179178async function run_glacier_operation ( fs_context , log_namespace , cb ) {
180179 const log = new PersistentLogger ( config . NSFS_GLACIER_LOGS_DIR , log_namespace , { locking : 'EXCLUSIVE' } ) ;
180+
181+ fs_context = force_gpfs_fs_context ( fs_context ) ;
181182 try {
182183 await log . process ( async ( entry , failure_recorder ) => cb ( fs_context , entry , failure_recorder ) ) ;
183184 } catch ( error ) {
@@ -212,6 +213,28 @@ function get_tz_date(hours, mins, secs, tz) {
212213 return date ;
213214}
214215
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+
215238/**
216239 * lock_and_run acquires a flock and calls the given callback after
217240 * acquiring the lock
0 commit comments