Skip to content

Commit

Permalink
fix rmdir cache issue
Browse files Browse the repository at this point in the history
  • Loading branch information
iychoi committed Jan 7, 2025
1 parent 1394c9d commit 54e6a34
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
22 changes: 20 additions & 2 deletions fs/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,29 @@ func (cache *FileSystemCache) RemoveEntryCache(path string) {
cache.entryCache.Delete(path)
}

// RemoveDirEntryCache removes an entry cache for dir
func (cache *FileSystemCache) RemoveDirEntryCache(path string, recursive bool) {
cache.entryCache.Delete(path)

if recursive {
prefix := strings.TrimSuffix(path, "/") + "/"

// recursive
items := cache.entryCache.Items()
for k := range items {
if strings.HasPrefix(k, prefix) {
// entries under k dir
cache.entryCache.Delete(k)
}
}
}
}

// RemoveParentDirCache removes an entry cache for the parent path of the given path
func (cache *FileSystemCache) RemoveParentDirCache(path string) {
func (cache *FileSystemCache) RemoveParentDirEntryCache(path string, recursive bool) {
if cache.config.InvalidateParentEntryCacheImmediately {
parentPath := util.GetIRODSPathDirname(path)
cache.entryCache.Delete(parentPath)
cache.RemoveDirEntryCache(parentPath, true)
}
}

Expand Down
13 changes: 7 additions & 6 deletions fs/fs_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (fs *FileSystem) invalidateCacheForDirCreate(path string) {
fs.cache.RemoveNegativeEntryCache(path)

// parent dir's entry also changes
fs.cache.RemoveParentDirCache(path)
fs.cache.RemoveParentDirEntryCache(path, true)
// parent dir's dir entry also changes
parentPath := util.GetIRODSPathDirname(path)
parentDirEntries := fs.cache.GetDirCache(parentPath)
Expand Down Expand Up @@ -100,7 +100,7 @@ func (fs *FileSystem) invalidateCacheForDirRemove(path string, recurse bool) {
fs.cache.RemoveAllNegativeEntryCacheForPath(path)

fs.cache.AddNegativeEntryCache(path)
fs.cache.RemoveEntryCache(path)
fs.cache.RemoveDirEntryCache(path, false)
fs.cache.RemoveMetadataCache(path)

if recurse && entry != nil {
Expand All @@ -117,7 +117,8 @@ func (fs *FileSystem) invalidateCacheForDirRemove(path string, recurse bool) {
fs.cache.RemoveACLsCache(path)

// parent dir's entry also changes
fs.cache.RemoveParentDirCache(path)
fs.cache.RemoveParentDirEntryCache(path, recurse)

// parent dir's dir entry also changes
parentPath := util.GetIRODSPathDirname(path)
parentDirEntries := fs.cache.GetDirCache(parentPath)
Expand Down Expand Up @@ -161,7 +162,7 @@ func (fs *FileSystem) invalidateCacheForDirExtract(path string) {
fs.cache.RemoveACLsCache(path)

// parent dir's entry also changes
fs.cache.RemoveParentDirCache(path)
fs.cache.RemoveParentDirEntryCache(path, true)
// parent dir's dir entry also changes
parentPath := util.GetIRODSPathDirname(path)
parentDirEntries := fs.cache.GetDirCache(parentPath)
Expand Down Expand Up @@ -190,7 +191,7 @@ func (fs *FileSystem) invalidateCacheForFileCreate(path string) {
fs.cache.RemoveNegativeEntryCache(path)

// parent dir's entry also changes
fs.cache.RemoveParentDirCache(path)
fs.cache.RemoveParentDirEntryCache(path, true)
// parent dir's dir entry also changes
parentPath := util.GetIRODSPathDirname(path)
parentDirEntries := fs.cache.GetDirCache(parentPath)
Expand All @@ -211,7 +212,7 @@ func (fs *FileSystem) invalidateCacheForFileRemove(path string) {
fs.cache.RemoveMetadataCache(path)

// parent dir's entry also changes
fs.cache.RemoveParentDirCache(path)
fs.cache.RemoveParentDirEntryCache(path, false)
// parent dir's dir entry also changes
parentPath := util.GetIRODSPathDirname(path)
parentDirEntries := fs.cache.GetDirCache(parentPath)
Expand Down
11 changes: 11 additions & 0 deletions test/testcases/fs_io_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/cyverse/go-irodsclient/fs"
"github.com/cyverse/go-irodsclient/irods/types"
"github.com/rs/xid"
)

Expand Down Expand Up @@ -117,6 +118,16 @@ func testUpRemoveMBFiles(t *testing.T) {
t.Logf("iteration %d, removing dir", i)
err = filesystem.RemoveDir(testDirPath, true, true)
failError(t, err)

t.Logf("iteration %d, stating file again", i)
fileStat2, err := filesystem.Stat(iRODSPath)
if err != nil {
if !types.IsFileNotFoundError(err) {
failError(t, err)
}
} else {
failError(t, fmt.Errorf("file not deleted - %q (size %d)", fileStat2.Path, fileStat2.Size))
}
}

err = os.Remove(localPath)
Expand Down

0 comments on commit 54e6a34

Please sign in to comment.