@@ -1405,6 +1405,8 @@ class NamespaceFS {
14051405 const is_disabled_dir_content = this . _is_directory_content ( file_path , params . key ) && this . _is_versioning_disabled ( ) ;
14061406
14071407 const stat = await target_file . stat ( fs_context ) ;
1408+ const file_path_stat = config . NSFS_GLACIER_DMAPI_ENABLE_TAPE_RECLAIM &&
1409+ await nb_native ( ) . fs . stat ( fs_context , file_path ) . catch ( _ . noop ) ;
14081410 this . _verify_encryption ( params . encryption , this . _get_encryption_info ( stat ) ) ;
14091411
14101412 const copy_xattr = params . copy_source && params . xattr_copy ;
@@ -1453,6 +1455,11 @@ class NamespaceFS {
14531455 dbg . log1 ( 'NamespaceFS._finish_upload:' , open_mode , file_path , upload_path , fs_xattr ) ;
14541456
14551457 if ( ! same_inode && ! part_upload ) {
1458+ // If the target file is already on tape then this is a candidate for tape reclaim
1459+ if ( file_path_stat && file_path_stat . xattr [ Glacier . GPFS_DMAPI_XATTR_TAPE_INDICATOR ] ) {
1460+ await this . append_to_reclaim_wal ( fs_context , upload_path , file_path_stat ) ;
1461+ }
1462+
14561463 await this . _move_to_dest ( fs_context , upload_path , file_path , target_file , open_mode , params . key ) ;
14571464 }
14581465
@@ -2118,13 +2125,19 @@ class NamespaceFS {
21182125 try {
21192126 files = await this . _open_files ( fs_context , { src_path : file_path , delete_version : true } ) ;
21202127 await this . _verify_lifecycle_filter_and_unlink ( fs_context , params , file_path , files . delete_version ) ;
2128+ await this . append_to_reclaim_wal ( fs_context , file_path ) ;
21212129 } catch ( err ) {
21222130 if ( err . code !== 'ENOENT' ) throw err ;
21232131 } finally {
21242132 if ( files ) await this . _close_files ( fs_context , files . delete_version , undefined , true ) ;
21252133 }
21262134 } else {
2127- await native_fs_utils . unlink_ignore_enoent ( fs_context , file_path ) ;
2135+ try {
2136+ await nb_native ( ) . fs . unlink ( fs_context , file_path ) ;
2137+ await this . append_to_reclaim_wal ( fs_context , file_path ) ;
2138+ } catch ( err ) {
2139+ if ( err . code !== 'ENOENT' && err . code !== 'EISDIR' ) throw err ;
2140+ }
21282141 }
21292142
21302143 await this . _delete_path_dirs ( file_path , fs_context ) ;
@@ -3709,6 +3722,30 @@ class NamespaceFS {
37093722 await NamespaceFS . restore_wal . append ( entry ) ;
37103723 }
37113724
3725+ /**
3726+ *
3727+ * @param {nb.NativeFSContext } fs_context
3728+ * @param {string } file_path
3729+ * @param {nb.NativeFSStats } [stat]
3730+ * @returns
3731+ */
3732+ async append_to_reclaim_wal ( fs_context , file_path , stat ) {
3733+ console . log ( 'calling append_to_reclaim_wal:' , file_path ) ;
3734+ if ( ! config . NSFS_GLACIER_LOGS_ENABLED || ! config . NSFS_GLACIER_DMAPI_ENABLE_TAPE_RECLAIM ) return ;
3735+
3736+ if ( ! stat ) {
3737+ stat = await nb_native ( ) . fs . stat ( fs_context , file_path ) ;
3738+ }
3739+
3740+ const data = JSON . stringify ( {
3741+ full_path : file_path ,
3742+ logical_size : stat . size ,
3743+ ea : stat . xattr ,
3744+ } ) ;
3745+ console . log ( 'calling append_to_reclaim_wal data:' , { file_path, data } ) ;
3746+ await NamespaceFS . reclaim_wal . append ( data ) ;
3747+ }
3748+
37123749 static get migrate_wal ( ) {
37133750 if ( ! NamespaceFS . _migrate_wal ) {
37143751 NamespaceFS . _migrate_wal = new PersistentLogger ( config . NSFS_GLACIER_LOGS_DIR , Glacier . MIGRATE_WAL_NAME , {
@@ -3731,6 +3768,17 @@ class NamespaceFS {
37313768 return NamespaceFS . _restore_wal ;
37323769 }
37333770
3771+ static get reclaim_wal ( ) {
3772+ if ( ! NamespaceFS . _reclaim_wal ) {
3773+ NamespaceFS . _reclaim_wal = new PersistentLogger ( config . NSFS_GLACIER_LOGS_DIR , Glacier . RECLAIM_WAL_NAME , {
3774+ poll_interval : config . NSFS_GLACIER_LOGS_POLL_INTERVAL ,
3775+ locking : 'SHARED' ,
3776+ } ) ;
3777+ }
3778+
3779+ return NamespaceFS . _reclaim_wal ;
3780+ }
3781+
37343782 ////////////////////////////
37353783 // LIFECYLE HELPERS //
37363784 ////////////////////////////
@@ -3803,7 +3851,8 @@ NamespaceFS._migrate_wal = null;
38033851/** @type {PersistentLogger } */
38043852NamespaceFS . _restore_wal = null ;
38053853
3854+ /** @type {PersistentLogger } */
3855+ NamespaceFS . _reclaim_wal = null ;
3856+
38063857module . exports = NamespaceFS ;
38073858module . exports . multi_buffer_pool = multi_buffer_pool ;
3808-
3809-
0 commit comments