@@ -1407,6 +1407,8 @@ class NamespaceFS {
14071407 const is_disabled_dir_content = this . _is_directory_content ( file_path , params . key ) && this . _is_versioning_disabled ( ) ;
14081408
14091409 const stat = await target_file . stat ( fs_context ) ;
1410+ const file_path_stat = config . NSFS_GLACIER_DMAPI_ENABLE_TAPE_RECLAIM &&
1411+ await nb_native ( ) . fs . stat ( fs_context , file_path ) . catch ( _ . noop ) ;
14101412 this . _verify_encryption ( params . encryption , this . _get_encryption_info ( stat ) ) ;
14111413
14121414 const copy_xattr = params . copy_source && params . xattr_copy ;
@@ -1455,6 +1457,10 @@ class NamespaceFS {
14551457 dbg . log1 ( 'NamespaceFS._finish_upload:' , open_mode , file_path , upload_path , fs_xattr ) ;
14561458
14571459 if ( ! same_inode && ! part_upload ) {
1460+ if ( file_path_stat ) {
1461+ await this . append_to_reclaim_wal ( fs_context , file_path , file_path_stat ) ;
1462+ }
1463+
14581464 await this . _move_to_dest ( fs_context , upload_path , file_path , target_file , open_mode , params . key ) ;
14591465 }
14601466
@@ -2126,7 +2132,16 @@ class NamespaceFS {
21262132 if ( files ) await this . _close_files ( fs_context , files . delete_version , undefined , true ) ;
21272133 }
21282134 } else {
2129- await native_fs_utils . unlink_ignore_enoent ( fs_context , file_path ) ;
2135+ try {
2136+ const stat = config . NSFS_GLACIER_DMAPI_ENABLE_TAPE_RECLAIM &&
2137+ await nb_native ( ) . fs . stat ( fs_context , file_path ) . catch ( dbg . warn . bind ( this ) ) ;
2138+ await nb_native ( ) . fs . unlink ( fs_context , file_path ) ;
2139+ if ( stat ) {
2140+ await this . append_to_reclaim_wal ( fs_context , file_path , stat ) ;
2141+ }
2142+ } catch ( err ) {
2143+ if ( err . code !== 'ENOENT' && err . code !== 'EISDIR' ) throw err ;
2144+ }
21302145 }
21312146
21322147 await this . _delete_path_dirs ( file_path , fs_context ) ;
@@ -3715,6 +3730,28 @@ class NamespaceFS {
37153730 await NamespaceFS . restore_wal . append ( Glacier . getBackend ( ) . encode_log ( entry ) ) ;
37163731 }
37173732
3733+ /**
3734+ *
3735+ * @param {nb.NativeFSContext } fs_context
3736+ * @param {string } file_path
3737+ * @param {nb.NativeFSStats } [stat]
3738+ * @returns
3739+ */
3740+ async append_to_reclaim_wal ( fs_context , file_path , stat ) {
3741+ if ( ! config . NSFS_GLACIER_LOGS_ENABLED || ! config . NSFS_GLACIER_DMAPI_ENABLE_TAPE_RECLAIM ) return ;
3742+
3743+ if ( ! stat ) {
3744+ stat = await nb_native ( ) . fs . stat ( fs_context , file_path ) ;
3745+ }
3746+
3747+ const data = JSON . stringify ( {
3748+ full_path : file_path ,
3749+ logical_size : stat . size ,
3750+ ea : stat . xattr ,
3751+ } ) ;
3752+ await NamespaceFS . reclaim_wal . append ( data ) ;
3753+ }
3754+
37183755 static get migrate_wal ( ) {
37193756 if ( ! NamespaceFS . _migrate_wal ) {
37203757 NamespaceFS . _migrate_wal = new PersistentLogger ( config . NSFS_GLACIER_LOGS_DIR , Glacier . MIGRATE_WAL_NAME , {
@@ -3737,6 +3774,17 @@ class NamespaceFS {
37373774 return NamespaceFS . _restore_wal ;
37383775 }
37393776
3777+ static get reclaim_wal ( ) {
3778+ if ( ! NamespaceFS . _reclaim_wal ) {
3779+ NamespaceFS . _reclaim_wal = new PersistentLogger ( config . NSFS_GLACIER_LOGS_DIR , Glacier . RECLAIM_WAL_NAME , {
3780+ poll_interval : config . NSFS_GLACIER_LOGS_POLL_INTERVAL ,
3781+ locking : 'SHARED' ,
3782+ } ) ;
3783+ }
3784+
3785+ return NamespaceFS . _reclaim_wal ;
3786+ }
3787+
37403788 ////////////////////////////
37413789 // LIFECYLE HELPERS //
37423790 ////////////////////////////
@@ -3763,6 +3811,9 @@ class NamespaceFS {
37633811 this . _check_lifecycle_filter_before_deletion ( params , stat ) ;
37643812 const bucket_tmp_dir_path = this . get_bucket_tmpdir_full_path ( ) ;
37653813 await native_fs_utils . safe_unlink ( fs_context , file_path , stat , { dir_file, src_file } , bucket_tmp_dir_path ) ;
3814+ if ( ! is_dir_content ) {
3815+ await this . append_to_reclaim_wal ( fs_context , file_path , src_stat ) . catch ( dbg . warn . bind ( this ) ) ;
3816+ }
37663817 } catch ( err ) {
37673818 dbg . log0 ( '_verify_lifecycle_filter_and_unlink err' , err . code , err , file_path ) ;
37683819 if ( err . code !== 'ENOENT' && err . code !== 'EISDIR' ) throw err ;
@@ -3809,7 +3860,8 @@ NamespaceFS._migrate_wal = null;
38093860/** @type {PersistentLogger } */
38103861NamespaceFS . _restore_wal = null ;
38113862
3863+ /** @type {PersistentLogger } */
3864+ NamespaceFS . _reclaim_wal = null ;
3865+
38123866module . exports = NamespaceFS ;
38133867module . exports . multi_buffer_pool = multi_buffer_pool ;
3814-
3815-
0 commit comments