Skip to content

Commit

Permalink
Merge branch 'maintain-file-state' into delete-files-synchronously
Browse files Browse the repository at this point in the history
  • Loading branch information
foodprocessor committed Jan 7, 2025
2 parents d3d5b25 + 681b140 commit 258cd37
Showing 1 changed file with 3 additions and 21 deletions.
24 changes: 3 additions & 21 deletions component/file_cache/file_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,33 +482,15 @@ func (fc *FileCache) invalidateDirectory(name string, flocks []*common.LockMapIt
func (fc *FileCache) DeleteDir(options internal.DeleteDirOptions) error {
log.Trace("FileCache::DeleteDir : %s", options.Name)

// we need to lock every file involved in this operation, before starting any of it

// 1. get a complete recursive listing of all cloud objects and local files in the given directory, sorted in lexical order
objectNames, err := fc.listAllObjects(options.Name)
if err != nil {
log.Err("FileCache::DeleteDir : %s listAllObjects failed. Here's why: %v", options.Name, err)
return err
}

// 2. acquire a file lock on each entry, in lexical order (and defer unlock)
var flocks []*common.LockMapItem
for _, objectName := range objectNames {
flock := fc.fileLocks.Get(objectName)
flocks = append(flocks, flock)
flock.Lock()
}
defer unlockAll(flocks)

// 3. delete the directory as normal (in cloud and then locally)
err = fc.NextComponent().DeleteDir(options)
// The libfuse component only calls DeleteDir on empty directories, so this directory must be empty
err := fc.NextComponent().DeleteDir(options)
if err != nil {
log.Err("FileCache::DeleteDir : %s failed", options.Name)
// There is a chance that meta file for directory was not created in which case
// rest api delete will fail while we still need to cleanup the local cache for the same
}

fc.invalidateDirectory(options.Name, flocks)
fc.invalidateDirectory(options.Name, nil)
return err
}

Expand Down

0 comments on commit 258cd37

Please sign in to comment.