@@ -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
const { is_desired_time, record_current_time } = require ( './manage_nsfs_cli_utils' ) ;
12
11
@@ -17,14 +16,14 @@ async function process_migrations() {
17
16
const fs_context = native_fs_utils . get_process_fs_context ( ) ;
18
17
const lock_path = path . join ( config . NSFS_GLACIER_LOGS_DIR , CLUSTER_LOCK ) ;
19
18
await native_fs_utils . lock_and_run ( fs_context , lock_path , async ( ) => {
20
- const backend = getGlacierBackend ( ) ;
19
+ const backend = Glacier . getBackend ( ) ;
21
20
22
21
if (
23
22
await backend . low_free_space ( ) ||
24
- await time_exceeded ( fs_context , config . NSFS_GLACIER_MIGRATE_INTERVAL , GlacierBackend . MIGRATE_TIMESTAMP_FILE )
23
+ await time_exceeded ( fs_context , config . NSFS_GLACIER_MIGRATE_INTERVAL , Glacier . MIGRATE_TIMESTAMP_FILE )
25
24
) {
26
25
await run_glacier_migrations ( fs_context , backend ) ;
27
- const timestamp_file_path = path . join ( config . NSFS_GLACIER_LOGS_DIR , GlacierBackend . MIGRATE_TIMESTAMP_FILE ) ;
26
+ const timestamp_file_path = path . join ( config . NSFS_GLACIER_LOGS_DIR , Glacier . MIGRATE_TIMESTAMP_FILE ) ;
28
27
await record_current_time ( fs_context , timestamp_file_path ) ;
29
28
}
30
29
} ) ;
@@ -34,46 +33,46 @@ async function process_migrations() {
34
33
* run_tape_migrations reads the migration WALs and attempts to migrate the
35
34
* files mentioned in the WAL.
36
35
* @param {nb.NativeFSContext } fs_context
37
- * @param {import('../sdk/nsfs_glacier_backend/backend ').GlacierBackend } backend
36
+ * @param {import('../sdk/glacier ').Glacier } backend
38
37
*/
39
38
async function run_glacier_migrations ( fs_context , backend ) {
40
- await run_glacier_operation ( fs_context , GlacierBackend . MIGRATE_WAL_NAME , backend . migrate . bind ( backend ) ) ;
39
+ await run_glacier_operation ( fs_context , Glacier . MIGRATE_WAL_NAME , backend . migrate . bind ( backend ) ) ;
41
40
}
42
41
43
42
async function process_restores ( ) {
44
43
const fs_context = native_fs_utils . get_process_fs_context ( ) ;
45
44
const lock_path = path . join ( config . NSFS_GLACIER_LOGS_DIR , CLUSTER_LOCK ) ;
46
45
await native_fs_utils . lock_and_run ( fs_context , lock_path , async ( ) => {
47
- const backend = getGlacierBackend ( ) ;
46
+ const backend = Glacier . getBackend ( ) ;
48
47
49
48
if (
50
49
await backend . low_free_space ( ) ||
51
- ! ( await time_exceeded ( fs_context , config . NSFS_GLACIER_RESTORE_INTERVAL , GlacierBackend . RESTORE_TIMESTAMP_FILE ) )
50
+ ! ( await time_exceeded ( fs_context , config . NSFS_GLACIER_RESTORE_INTERVAL , Glacier . RESTORE_TIMESTAMP_FILE ) )
52
51
) return ;
53
52
54
53
55
54
await run_glacier_restore ( fs_context , backend ) ;
56
- const timestamp_file_path = path . join ( config . NSFS_GLACIER_LOGS_DIR , GlacierBackend . RESTORE_TIMESTAMP_FILE ) ;
55
+ const timestamp_file_path = path . join ( config . NSFS_GLACIER_LOGS_DIR , Glacier . RESTORE_TIMESTAMP_FILE ) ;
57
56
await record_current_time ( fs_context , timestamp_file_path ) ;
58
57
} ) ;
59
58
}
60
59
61
60
/**
62
61
* run_tape_restore reads the restore WALs and attempts to restore the
63
62
* files mentioned in the WAL.
64
- * @param {nb.NativeFSContext } fs_context
65
- * @param {import('../sdk/nsfs_glacier_backend/backend ').GlacierBackend } backend
63
+ * @param {nb.NativeFSContext } fs_context
64
+ * @param {import('../sdk/glacier ').Glacier } backend
66
65
*/
67
66
async function run_glacier_restore ( fs_context , backend ) {
68
- await run_glacier_operation ( fs_context , GlacierBackend . RESTORE_WAL_NAME , backend . restore . bind ( backend ) ) ;
67
+ await run_glacier_operation ( fs_context , Glacier . RESTORE_WAL_NAME , backend . restore . bind ( backend ) ) ;
69
68
}
70
69
71
70
async function process_expiry ( ) {
72
71
const fs_context = native_fs_utils . get_process_fs_context ( ) ;
73
72
const lock_path = path . join ( config . NSFS_GLACIER_LOGS_DIR , SCAN_LOCK ) ;
74
73
await native_fs_utils . lock_and_run ( fs_context , lock_path , async ( ) => {
75
- const backend = getGlacierBackend ( ) ;
76
- const timestamp_file_path = path . join ( config . NSFS_GLACIER_LOGS_DIR , GlacierBackend . EXPIRY_TIMESTAMP_FILE ) ;
74
+ const backend = Glacier . getBackend ( ) ;
75
+ const timestamp_file_path = path . join ( config . NSFS_GLACIER_LOGS_DIR , Glacier . EXPIRY_TIMESTAMP_FILE ) ;
77
76
if (
78
77
await backend . low_free_space ( ) ||
79
78
await is_desired_time (
@@ -126,6 +125,8 @@ async function time_exceeded(fs_context, interval, timestamp_file) {
126
125
*/
127
126
async function run_glacier_operation ( fs_context , log_namespace , cb ) {
128
127
const log = new PersistentLogger ( config . NSFS_GLACIER_LOGS_DIR , log_namespace , { locking : 'EXCLUSIVE' } ) ;
128
+
129
+ fs_context = prepare_galcier_fs_context ( fs_context ) ;
129
130
try {
130
131
await log . process ( async ( entry , failure_recorder ) => cb ( fs_context , entry , failure_recorder ) ) ;
131
132
} catch ( error ) {
@@ -135,6 +136,28 @@ async function run_glacier_operation(fs_context, log_namespace, cb) {
135
136
}
136
137
}
137
138
139
+ /**
140
+ * prepare_galcier_fs_context returns a shallow copy of given
141
+ * fs_context with backend set to 'GPFS'.
142
+ *
143
+ * NOTE: The function will throw error if it detects that libgfs
144
+ * isn't loaded.
145
+ *
146
+ * @param {nb.NativeFSContext } fs_context
147
+ * @returns {nb.NativeFSContext }
148
+ */
149
+ function prepare_galcier_fs_context ( fs_context ) {
150
+ if ( config . NSFS_GLACIER_DMAPI_ENABLE ) {
151
+ if ( ! nb_native ( ) . fs . gpfs ) {
152
+ throw new Error ( 'cannot use DMAPI xattrs: libgpfs not loaded' ) ;
153
+ }
154
+
155
+ return { ...fs_context , backend : 'GPFS' , use_dmapi : true } ;
156
+ }
157
+
158
+ return { ...fs_context } ;
159
+ }
160
+
138
161
exports . process_migrations = process_migrations ;
139
162
exports . process_restores = process_restores ;
140
163
exports . process_expiry = process_expiry ;
0 commit comments