Skip to content

Commit

Permalink
Use updated etag of home directory even if it is cached (#1416)
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 authored Jan 21, 2021
1 parent 7fe671a commit 44870ec
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
8 changes: 8 additions & 0 deletions changelog/unreleased/etag-cache-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Enhancement: Use updated etag of home directory even if it is cached

We cache the home directory and shares folder etags as calculating these is an
expensive process. But if these directories were updated after the previously
calculated etag was cached, we can ignore this calculation and directly return
the new one.

https://github.com/cs3org/reva/pull/1416
29 changes: 23 additions & 6 deletions internal/grpc/services/gateway/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/cs3org/reva/pkg/storage/utils/etag"
"github.com/cs3org/reva/pkg/storage/utils/templates"
"github.com/cs3org/reva/pkg/user"
"github.com/cs3org/reva/pkg/utils"
"github.com/dgrijalva/jwt-go"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -985,12 +986,17 @@ func (s *svc) statHome(ctx context.Context) (*provider.StatResponse, error) {
}, nil
}

if resEtag, err := s.etagCache.Get(statRes.Info.Owner.OpaqueId + ":" + statRes.Info.Path); err == nil {
statRes.Info.Etag = resEtag.(string)
if etagIface, err := s.etagCache.Get(statRes.Info.Owner.OpaqueId + ":" + statRes.Info.Path); err == nil {
resMtime := utils.TSToTime(statRes.Info.Mtime)
resEtag := etagIface.(etagWithTS)
// Use the updated etag if the home folder has been modified
if resMtime.Before(resEtag.Timestamp) {
statRes.Info.Etag = resEtag.Etag
}
} else {
statRes.Info.Etag = etag.GenerateEtagFromResources(statRes.Info, []*provider.ResourceInfo{statSharedFolder.Info})
if s.c.EtagCacheTTL > 0 {
_ = s.etagCache.Set(statRes.Info.Owner.OpaqueId+":"+statRes.Info.Path, statRes.Info.Etag)
_ = s.etagCache.Set(statRes.Info.Owner.OpaqueId+":"+statRes.Info.Path, etagWithTS{statRes.Info.Etag, time.Now()})
}
}

Expand Down Expand Up @@ -1029,12 +1035,18 @@ func (s *svc) statSharesFolder(ctx context.Context) (*provider.StatResponse, err
}, nil
}

if resEtag, err := s.etagCache.Get(statRes.Info.Owner.OpaqueId + ":" + statRes.Info.Path); err == nil {
statRes.Info.Etag = resEtag.(string)
if etagIface, err := s.etagCache.Get(statRes.Info.Owner.OpaqueId + ":" + statRes.Info.Path); err == nil {
resMtime := utils.TSToTime(statRes.Info.Mtime)
resEtag := etagIface.(etagWithTS)
// Use the updated etag if the shares folder has been modified, i.e., a new
// reference has been created.
if resMtime.Before(resEtag.Timestamp) {
statRes.Info.Etag = resEtag.Etag
}
} else {
statRes.Info.Etag = etag.GenerateEtagFromResources(statRes.Info, lsRes.Infos)
if s.c.EtagCacheTTL > 0 {
_ = s.etagCache.Set(statRes.Info.Owner.OpaqueId+":"+statRes.Info.Path, statRes.Info.Etag)
_ = s.etagCache.Set(statRes.Info.Owner.OpaqueId+":"+statRes.Info.Path, etagWithTS{statRes.Info.Etag, time.Now()})
}
}
return statRes, nil
Expand Down Expand Up @@ -1852,3 +1864,8 @@ func (s *svc) getStorageProvider(ctx context.Context, ref *provider.Reference) (

return res.Provider, nil
}

type etagWithTS struct {
Etag string
Timestamp time.Time
}

0 comments on commit 44870ec

Please sign in to comment.