Skip to content

Commit

Permalink
Initialize space id caches
Browse files Browse the repository at this point in the history
  • Loading branch information
aduffeck committed Jun 20, 2023
1 parent f700f8c commit 9a6ff63
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
21 changes: 18 additions & 3 deletions pkg/storage/utils/decomposedfs/decomposedfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,21 @@ func New(o *options.Options, lu *lookup.Lookup, p Permissions, tp Tree, es event
if o.LockCycleDurationFactor != 0 {
filelocks.SetLockCycleDurationFactor(o.LockCycleDurationFactor)
}
userSpaceIndex := spaceidindex.New(filepath.Join(o.Root, "indexes"), "by-user-id")
err = userSpaceIndex.Init()
if err != nil {
return nil, err
}
groupSpaceIndex := spaceidindex.New(filepath.Join(o.Root, "indexes"), "by-group-id")
err = groupSpaceIndex.Init()
if err != nil {
return nil, err
}
spaceTypeIndex := spaceidindex.New(filepath.Join(o.Root, "indexes"), "by-type")
err = spaceTypeIndex.Init()
if err != nil {
return nil, err
}

fs := &Decomposedfs{
tp: tp,
Expand All @@ -177,9 +192,9 @@ func New(o *options.Options, lu *lookup.Lookup, p Permissions, tp Tree, es event
stream: es,
cache: cache.GetStatCache(o.StatCache.Store, o.StatCache.Nodes, o.StatCache.Database, "stat", time.Duration(o.StatCache.TTL)*time.Second, o.StatCache.Size),
UserCache: ttlcache.NewCache(),
userSpaceIndex: spaceidindex.New(filepath.Join(o.Root, "indexes"), "by-user-id"),
groupSpaceIndex: spaceidindex.New(filepath.Join(o.Root, "indexes"), "by-group-id"),
spaceTypeIndex: spaceidindex.New(filepath.Join(o.Root, "indexes"), "by-type"),
userSpaceIndex: userSpaceIndex,
groupSpaceIndex: groupSpaceIndex,
spaceTypeIndex: spaceTypeIndex,
}

if o.AsyncFileUploads {
Expand Down
9 changes: 7 additions & 2 deletions pkg/storage/utils/decomposedfs/spaceidindex/spaceidindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,18 @@ type readWriteCloseSeekTruncater interface {
Truncate(int64) error
}

func New(root, index string) *Index {
func New(root, name string) *Index {
return &Index{
root: root,
name: index,
name: name,
}
}

func (i *Index) Init() error {
// Make sure to work on an existing tree
return os.MkdirAll(filepath.Join(i.root, i.name), 0700)
}

func (i *Index) Load(index string) (map[string][]byte, error) {
indexPath := filepath.Join(i.root, i.name, index+".mpk")
fi, err := os.Stat(indexPath)
Expand Down

0 comments on commit 9a6ff63

Please sign in to comment.