@@ -1473,15 +1473,23 @@ class NamespaceFS {
14731473 let retries = config . NSFS_RENAME_RETRIES ;
14741474 for ( ; ; ) {
14751475 try {
1476- const new_ver_info = ! is_gpfs && await this . _get_version_info ( fs_context , new_ver_tmp_path ) ;
1477- // get latest version_id if exists
1478- const latest_ver_info = await this . _get_version_info ( fs_context , latest_ver_path ) ;
1479- const versioned_path = latest_ver_info && this . _get_version_path ( key , latest_ver_info . version_id_str ) ;
1480- const versioned_info = latest_ver_info && await this . _get_version_info ( fs_context , versioned_path ) ;
1481-
1482- gpfs_options = await this . _open_files_gpfs ( fs_context , new_ver_tmp_path , latest_ver_path , upload_file ,
1483- latest_ver_info , open_mode , undefined , versioned_info ) ;
1476+ let new_ver_info ;
1477+ let latest_ver_info ;
1478+ if ( is_gpfs ) {
1479+ const latest_ver_info_exist = await native_fs_utils . is_path_exists ( fs_context , latest_ver_path ) ;
1480+ gpfs_options = await this . _open_files_gpfs ( fs_context , new_ver_tmp_path , latest_ver_path , upload_file ,
1481+ latest_ver_info_exist , open_mode , undefined , undefined ) ;
1482+
1483+ //get latest version if exists
1484+ const latest_fd = gpfs_options ?. move_to_dst ?. dst_file ;
1485+ latest_ver_info = latest_fd && await this . _get_version_info ( fs_context , undefined , latest_fd ) ;
1486+ } else {
1487+ new_ver_info = await this . _get_version_info ( fs_context , new_ver_tmp_path ) ;
1488+ //get latest version if exists. TODO use fd like in GPFS
1489+ latest_ver_info = await this . _get_version_info ( fs_context , latest_ver_path ) ;
1490+ }
14841491 const bucket_tmp_dir_path = this . get_bucket_tmpdir_full_path ( ) ;
1492+ const versioned_path = latest_ver_info && this . _get_version_path ( key , latest_ver_info . version_id_str ) ;
14851493 dbg . log1 ( 'Namespace_fs._move_to_dest_version:' , latest_ver_info , new_ver_info , gpfs_options ) ;
14861494
14871495 if ( this . _is_versioning_suspended ( ) ) {
@@ -2725,10 +2733,12 @@ class NamespaceFS {
27252733 // path - specifies the path to version
27262734 // if version xattr contains version info - return info by xattr
27272735 // else - it's a null version - return stat
2728- async _get_version_info ( fs_context , version_path ) {
2736+ // if fd is passed, will use fd instead of path to stat
2737+ async _get_version_info ( fs_context , version_path , fd ) {
27292738 try {
2730- const stat = await nb_native ( ) . fs . stat ( fs_context , version_path , { skip_user_xattr : true } ) ;
2731- dbg . log1 ( 'NamespaceFS._get_version_info stat ' , stat , version_path ) ;
2739+ const stat = fd ? await fd . stat ( fs_context , { skip_user_xattr : true } ) :
2740+ await nb_native ( ) . fs . stat ( fs_context , version_path , { skip_user_xattr : true } ) ;
2741+ dbg . log1 ( 'NamespaceFS._get_version_info stat ' , stat , version_path , fd ) ;
27322742
27332743 const version_id_str = this . _get_version_id_by_xattr ( stat ) ;
27342744 const ver_info_by_xattr = this . _extract_version_info_from_xattr ( version_id_str ) ;
@@ -3152,8 +3162,8 @@ class NamespaceFS {
31523162 // opens the unopened files involved in the version move during upload/deletion
31533163 // returns an object contains the relevant options for the move/unlink flow
31543164 // eslint-disable-next-line max-params
3155- async _open_files_gpfs ( fs_context , src_path , dst_path , upload_or_dir_file , dst_ver_info , open_mode , delete_version , versioned_info ) {
3156- dbg . log1 ( 'Namespace_fs._open_files_gpfs:' , src_path , src_path && path . dirname ( src_path ) , dst_path , upload_or_dir_file , dst_ver_info , open_mode , delete_version , versioned_info ) ;
3165+ async _open_files_gpfs ( fs_context , src_path , dst_path , upload_or_dir_file , dst_ver_exist , open_mode , delete_version , versioned_info ) {
3166+ dbg . log1 ( 'Namespace_fs._open_files_gpfs:' , src_path , src_path && path . dirname ( src_path ) , dst_path , upload_or_dir_file , Boolean ( dst_ver_exist ) , open_mode , delete_version , versioned_info ) ;
31573167 const is_gpfs = native_fs_utils . _is_gpfs ( fs_context ) ;
31583168 if ( ! is_gpfs ) return ;
31593169
@@ -3179,13 +3189,13 @@ class NamespaceFS {
31793189 src_file = upload_or_dir_file ;
31803190 dir_file = await native_fs_utils . open_file ( fs_context , this . bucket_path , path . dirname ( src_path ) , 'r' ) ;
31813191 }
3182- if ( dst_ver_info ) {
3192+ if ( dst_ver_exist ) {
31833193 dbg . log1 ( 'NamespaceFS._open_files_gpfs dst version exist - opening dst version file...' ) ;
31843194 dst_file = await native_fs_utils . open_file ( fs_context , this . bucket_path , dst_path , 'r' ) ;
31853195 }
31863196 return {
3187- move_to_versions : { src_file : dst_file , dir_file, should_override : false } ,
3188- move_to_dst : { src_file, dst_file, dir_file, versioned_file }
3197+ move_to_versions : { src_file : dst_file , dir_file } ,
3198+ move_to_dst : { src_file, dst_file, dir_file}
31893199 } ;
31903200 } catch ( err ) {
31913201 dbg . error ( 'NamespaceFS._open_files_gpfs couldn\'t open files' , err ) ;
0 commit comments