Skip to content

Commit

Permalink
Merge pull request #16 from cyverse/WIP_UserGroupQuota
Browse files Browse the repository at this point in the history
Cache file/dir ACLs
  • Loading branch information
iychoi authored Jun 14, 2021
2 parents ba03548 + f026a51 commit c0316d9
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 23 deletions.
68 changes: 68 additions & 0 deletions fs/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type FileSystemCache struct {
GroupUsersCache *gocache.Cache
GroupsCache *gocache.Cache
UsersCache *gocache.Cache
DirACLsCache *gocache.Cache
FileACLsCache *gocache.Cache
}

// NewFileSystemCache creates a new FileSystemCache
Expand All @@ -29,6 +31,8 @@ func NewFileSystemCache(cacheTimeout time.Duration, cleanup time.Duration) *File
groupUsersCache := gocache.New(cacheTimeout, cleanup)
groupsCache := gocache.New(cacheTimeout, cleanup)
usersCache := gocache.New(cacheTimeout, cleanup)
dirACLsCache := gocache.New(cacheTimeout, cleanup)
fileACLsCache := gocache.New(cacheTimeout, cleanup)

return &FileSystemCache{
CacheTimeout: cacheTimeout,
Expand All @@ -39,6 +43,8 @@ func NewFileSystemCache(cacheTimeout time.Duration, cleanup time.Duration) *File
GroupUsersCache: groupUsersCache,
GroupsCache: groupsCache,
UsersCache: usersCache,
DirACLsCache: dirACLsCache,
FileACLsCache: fileACLsCache,
}
}

Expand Down Expand Up @@ -217,3 +223,65 @@ func (cache *FileSystemCache) GetUsersCache() []*types.IRODSUser {
}
return nil
}

// AddDirACLsCache ...
func (cache *FileSystemCache) AddDirACLsCache(path string, accesses []*types.IRODSAccess) {
if shouldHaveInfiniteCacheTTL(path) {
cache.DirACLsCache.Set(path, accesses, -1)
}

// default
cache.DirACLsCache.Set(path, accesses, 0)
}

// RemoveDirACLsCache ...
func (cache *FileSystemCache) RemoveDirACLsCache(path string) {
cache.DirACLsCache.Delete(path)
}

// GetDirACLsCache ...
func (cache *FileSystemCache) GetDirACLsCache(path string) []*types.IRODSAccess {
data, exist := cache.DirACLsCache.Get(path)
if exist {
if entries, ok := data.([]*types.IRODSAccess); ok {
return entries
}
}
return nil
}

// ClearDirCache ...
func (cache *FileSystemCache) ClearDirACLsCache() {
cache.DirACLsCache.Flush()
}

// AddFileACLsCache ...
func (cache *FileSystemCache) AddFileACLsCache(path string, accesses []*types.IRODSAccess) {
if shouldHaveInfiniteCacheTTL(path) {
cache.FileACLsCache.Set(path, accesses, -1)
}

// default
cache.FileACLsCache.Set(path, accesses, 0)
}

// RemoveFileACLsCache ...
func (cache *FileSystemCache) RemoveFileACLsCache(path string) {
cache.FileACLsCache.Delete(path)
}

// GetFileACLsCache ...
func (cache *FileSystemCache) GetFileACLsCache(path string) []*types.IRODSAccess {
data, exist := cache.FileACLsCache.Get(path)
if exist {
if entries, ok := data.([]*types.IRODSAccess); ok {
return entries
}
}
return nil
}

// ClearFileACLsCache ...
func (cache *FileSystemCache) ClearFileACLsCache() {
cache.FileACLsCache.Flush()
}
45 changes: 22 additions & 23 deletions fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,13 @@ func (fs *FileSystem) ListACLsWithGroupUsers(path string) ([]*types.IRODSAccess,
func (fs *FileSystem) ListDirACLs(path string) ([]*types.IRODSAccess, error) {
irodsPath := util.GetCorrectIRODSPath(path)

// check cache first
cachedAccesses := fs.Cache.GetDirACLsCache(irodsPath)
if cachedAccesses != nil {
return cachedAccesses, nil
}

// otherwise, retrieve it and add it to cache
conn, err := fs.Session.AcquireConnection()
if err != nil {
return nil, err
Expand All @@ -270,20 +277,15 @@ func (fs *FileSystem) ListDirACLs(path string) ([]*types.IRODSAccess, error) {
return nil, err
}

// cache it
fs.Cache.AddDirACLsCache(irodsPath, accesses)

return accesses, nil
}

// ListDirACLsWithGroupUsers returns ACLs of a directory
func (fs *FileSystem) ListDirACLsWithGroupUsers(path string) ([]*types.IRODSAccess, error) {
irodsPath := util.GetCorrectIRODSPath(path)

conn, err := fs.Session.AcquireConnection()
if err != nil {
return nil, err
}
defer fs.Session.ReturnConnection(conn)

accesses, err := irods_fs.ListCollectionAccess(conn, irodsPath)
accesses, err := fs.ListDirACLs(path)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -328,6 +330,13 @@ func (fs *FileSystem) ListDirACLsWithGroupUsers(path string) ([]*types.IRODSAcce
func (fs *FileSystem) ListFileACLs(path string) ([]*types.IRODSAccess, error) {
irodsPath := util.GetCorrectIRODSPath(path)

// check cache first
cachedAccesses := fs.Cache.GetFileACLsCache(irodsPath)
if cachedAccesses != nil {
return cachedAccesses, nil
}

// otherwise, retrieve it and add it to cache
conn, err := fs.Session.AcquireConnection()
if err != nil {
return nil, err
Expand All @@ -344,25 +353,15 @@ func (fs *FileSystem) ListFileACLs(path string) ([]*types.IRODSAccess, error) {
return nil, err
}

// cache it
fs.Cache.AddFileACLsCache(irodsPath, accesses)

return accesses, nil
}

// ListFileACLsWithGroupUsers returns ACLs of a file
func (fs *FileSystem) ListFileACLsWithGroupUsers(path string) ([]*types.IRODSAccess, error) {
irodsPath := util.GetCorrectIRODSPath(path)

conn, err := fs.Session.AcquireConnection()
if err != nil {
return nil, err
}
defer fs.Session.ReturnConnection(conn)

collection, err := fs.getCollection(util.GetIRODSPathDirname(irodsPath))
if err != nil {
return nil, err
}

accesses, err := irods_fs.ListDataObjectAccess(conn, collection.Internal.(*types.IRODSCollection), util.GetIRODSPathFileName(irodsPath))
accesses, err := fs.ListFileACLs(path)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit c0316d9

Please sign in to comment.