Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize Rename function logic to reduce the number of REST API calls. #1459

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ blobfuse2
adlsgen1fuse
venv/
*.backup
__debug_bin
__debug_bin*
.env
*.prof
cpplite/
Expand All @@ -21,3 +21,4 @@ lint.log
azure-storage-fuse
bfusemon
test/scripts/dirIterate.go
component/azstorage/logfile.txt
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## 2.3.3 (Unreleased)
## 2.4.0 (Unreleased)
**Bug Fixes**
- Rename file was calling an additional getProperties call.


## 2.3.2 (2024-09-03)
**Bug Fixes**
Expand Down
1 change: 0 additions & 1 deletion component/attr_cache/attr_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ func (ac *AttrCache) RenameFile(options internal.RenameFileOptions) error {
ac.cacheLock.RLock()
defer ac.cacheLock.RUnlock()

// TODO: Can we just copy over the attributes from the source to the destination so we don't have to invalidate?
ac.deletePath(options.Src, time.Now())
ac.invalidatePath(options.Dst)
}
Expand Down
47 changes: 27 additions & 20 deletions component/azstorage/block_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,33 +313,27 @@ func (bb *BlockBlob) DeleteDirectory(name string) (err error) {
}

// RenameFile : Rename the file
// Source file must exist in storage account before calling this method.
func (bb *BlockBlob) RenameFile(source string, target string) error {
log.Trace("BlockBlob::RenameFile : %s -> %s", source, target)

blobClient := bb.Container.NewBlockBlobClient(filepath.Join(bb.Config.prefixPath, source))
newBlobClient := bb.Container.NewBlockBlobClient(filepath.Join(bb.Config.prefixPath, target))

_, err := blobClient.GetProperties(context.Background(), &blob.GetPropertiesOptions{
CPKInfo: bb.blobCPKOpt,
})
if err != nil {
serr := storeBlobErrToErr(err)
if serr == ErrFileNotFound {
log.Err("BlockBlob::RenameFile : %s does not exist", source)
return syscall.ENOENT
} else {
log.Err("BlockBlob::RenameFile : Failed to get blob properties for %s [%s]", source, err.Error())
return err
}
}

// not specifying source blob metadata, since passing empty metadata headers copies
// the source blob metadata to destination blob
startCopy, err := newBlobClient.StartCopyFromURL(context.Background(), blobClient.URL(), &blob.StartCopyFromURLOptions{
Tier: bb.Config.defaultTier,
})

if err != nil {
serr := storeBlobErrToErr(err)
if serr == ErrFileNotFound {
//Ideally this case doesn't hit as we are checking for the existence of src
//before making the call for RenameFile
log.Err("BlockBlob::RenameFile : Src Blob doesn't Exist %s [%s]", source, err.Error())
return syscall.ENOENT
}
log.Err("BlockBlob::RenameFile : Failed to start copy of file %s [%s]", source, err.Error())
return err
}
Expand Down Expand Up @@ -404,13 +398,26 @@ func (bb *BlockBlob) RenameDirectory(source string, target string) error {
}
}

err := bb.RenameFile(source, target)
// check if the marker blob for source directory does not exist but
// blobs were present in it, which were renamed earlier
if err == syscall.ENOENT && srcDirPresent {
err = nil
// To rename source marker blob check its properties before calling rename on it.
blobClient := bb.Container.NewBlockBlobClient(filepath.Join(bb.Config.prefixPath, source))
vibhansa-msft marked this conversation as resolved.
Show resolved Hide resolved
_, err := blobClient.GetProperties(context.Background(), &blob.GetPropertiesOptions{
CPKInfo: bb.blobCPKOpt,
})
if err != nil {
serr := storeBlobErrToErr(err)
if serr == ErrFileNotFound { //marker blob doesn't exist for the directory
if srcDirPresent { //Some files exist inside the directory
return nil
}
log.Err("BlockBlob::RenameDirectory : %s marker blob does not exist and Src Directory doesn't Exist", source)
return syscall.ENOENT
} else {
log.Err("BlockBlob::RenameDirectory : Failed to get source directory marker blob properties for %s [%s]", source, err.Error())
return err
}
vibhansa-msft marked this conversation as resolved.
Show resolved Hide resolved
}
return err

return bb.RenameFile(source, target)
}

func (bb *BlockBlob) getAttrUsingRest(name string) (attr *internal.ObjAttr, err error) {
Expand Down
Loading