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

Fix race conditions #326

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 2 additions & 3 deletions component/file_cache/file_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -1211,11 +1211,10 @@ func (fc *FileCache) FlushFile(options internal.FlushFileOptions) error {

// If chmod was done on the file before it was uploaded to container then setting up mode would have been missed
// Such file names are added to this map and here post upload we try to set the mode correctly
_, found := fc.missedChmodList.Load(options.Handle.Path)
// Delete the entry from map so that any further flush do not try to update the mode again
_, found := fc.missedChmodList.LoadAndDelete(options.Handle.Path)
if found {
// If file is found in map it means last chmod was missed on this
// Delete the entry from map so that any further flush do not try to update the mode again
fc.missedChmodList.Delete(options.Handle.Path)

// When chmod on container was missed, local file was updated with correct mode
// Here take the mode from local cache and update the container accordingly
Expand Down
8 changes: 7 additions & 1 deletion component/file_cache/lru_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,13 @@ func (p *lruPolicy) asyncCacheValid() {
for {
select {
case name := <-p.validateChan:
p.cacheValidate(name)
// validateChan only gets names that are already cached
// if the file is not in the map anymore, then it was deleted,
// which means calling cacheValidate now would be a bug
_, found := p.nodeMap.Load(name)
if found {
p.cacheValidate(name)
}

case <-p.closeSignalValidate:
return
Expand Down
3 changes: 1 addition & 2 deletions component/libfuse/libfuse2_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ func (cf *CgofuseFS) Opendir(path string) (int, uint64) {
// Releasedir opens the handle for the directory at the path.
func (cf *CgofuseFS) Releasedir(path string, fh uint64) int {
// Get the filehandle
handle, exists := handlemap.Load(handlemap.HandleID(fh))
handle, exists := handlemap.LoadAndDelete(handlemap.HandleID(fh))
if !exists {
log.Trace("Libfuse::Releasedir : Failed to release %s, handle: %d", path, fh)
return -fuse.EBADF
Expand All @@ -435,7 +435,6 @@ func (cf *CgofuseFS) Releasedir(path string, fh uint64) int {
log.Trace("Libfuse::Releasedir : %s, handle: %d", handle.Path, handle.ID)

handle.Cleanup()
handlemap.Delete(handle.ID)
return 0
}

Expand Down
9 changes: 9 additions & 0 deletions internal/handlemap/handle_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,15 @@ func Delete(key HandleID) {
defaultHandleMap.Delete(key)
}

// Delete : Remove handle object from map, and return the entry (if any)
func LoadAndDelete(key HandleID) (*Handle, bool) {
val, found := defaultHandleMap.LoadAndDelete(key)
if !found {
return nil, false
}
return val.(*Handle), true
}

func CreateCacheObject(capacity int64, handle *Handle) {
handle.CacheObj = &Cache{
sync.RWMutex{},
Expand Down
Loading