update reva
This commit is contained in:
+2
-20
@@ -309,8 +309,6 @@ func (m *Manager) Share(ctx context.Context, md *provider.ResourceInfo, g *colla
|
||||
Grantee: g.Grantee,
|
||||
}
|
||||
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
_, err := m.getByKey(ctx, key)
|
||||
if err == nil {
|
||||
// share already exists
|
||||
@@ -468,8 +466,6 @@ func (m *Manager) GetShare(ctx context.Context, ref *collaboration.ShareReferenc
|
||||
return nil, err
|
||||
}
|
||||
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
s, err := m.get(ctx, ref)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -521,8 +517,6 @@ func (m *Manager) Unshare(ctx context.Context, ref *collaboration.ShareReference
|
||||
return err
|
||||
}
|
||||
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
user := ctxpkg.ContextMustGetUser(ctx)
|
||||
|
||||
s, err := m.get(ctx, ref)
|
||||
@@ -547,9 +541,6 @@ func (m *Manager) UpdateShare(ctx context.Context, ref *collaboration.ShareRefer
|
||||
return nil, err
|
||||
}
|
||||
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
|
||||
var toUpdate *collaboration.Share
|
||||
|
||||
if ref != nil {
|
||||
@@ -598,6 +589,8 @@ func (m *Manager) UpdateShare(ctx context.Context, ref *collaboration.ShareRefer
|
||||
toUpdate.Mtime = utils.TSNow()
|
||||
|
||||
// Update provider cache
|
||||
unlock := m.Cache.LockSpace(toUpdate.ResourceId.SpaceId)
|
||||
defer unlock()
|
||||
err := m.Cache.Persist(ctx, toUpdate.ResourceId.StorageId, toUpdate.ResourceId.SpaceId)
|
||||
// when persisting fails
|
||||
if _, ok := err.(errtypes.IsPreconditionFailed); ok {
|
||||
@@ -629,9 +622,6 @@ func (m *Manager) ListShares(ctx context.Context, filters []*collaboration.Filte
|
||||
return nil, err
|
||||
}
|
||||
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
|
||||
user := ctxpkg.ContextMustGetUser(ctx)
|
||||
|
||||
if len(share.FilterFiltersByType(filters, collaboration.Filter_TYPE_RESOURCE_ID)) > 0 {
|
||||
@@ -775,9 +765,6 @@ func (m *Manager) ListReceivedShares(ctx context.Context, filters []*collaborati
|
||||
return nil, err
|
||||
}
|
||||
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
|
||||
user := ctxpkg.ContextMustGetUser(ctx)
|
||||
|
||||
ssids := map[string]*receivedsharecache.Space{}
|
||||
@@ -958,8 +945,6 @@ func (m *Manager) getReceived(ctx context.Context, ref *collaboration.ShareRefer
|
||||
ctx, span := appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "getReceived")
|
||||
defer span.End()
|
||||
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
s, err := m.get(ctx, ref)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -1001,9 +986,6 @@ func (m *Manager) UpdateReceivedShare(ctx context.Context, receivedShare *collab
|
||||
return nil, err
|
||||
}
|
||||
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
|
||||
for i := range fieldMask.Paths {
|
||||
switch fieldMask.Paths[i] {
|
||||
case "state":
|
||||
|
||||
Generated
Vendored
+30
@@ -25,6 +25,7 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1"
|
||||
@@ -42,6 +43,9 @@ const tracerName = "providercache"
|
||||
|
||||
// Cache holds share information structured by provider and space
|
||||
type Cache struct {
|
||||
lockMapLock sync.Mutex
|
||||
lockMap map[string]*sync.Mutex
|
||||
|
||||
Providers map[string]*Spaces
|
||||
|
||||
storage metadata.Storage
|
||||
@@ -100,17 +104,37 @@ func (s *Shares) UnmarshalJSON(data []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// LockSpace locks the cache for a given space and returns an unlock function
|
||||
func (c *Cache) LockSpace(spaceID string) func() {
|
||||
lock := c.lockMap[spaceID]
|
||||
if lock == nil {
|
||||
c.lockMapLock.Lock()
|
||||
lock = c.lockMap[spaceID]
|
||||
if lock == nil {
|
||||
c.lockMap[spaceID] = &sync.Mutex{}
|
||||
lock = c.lockMap[spaceID]
|
||||
}
|
||||
c.lockMapLock.Unlock()
|
||||
}
|
||||
lock.Lock()
|
||||
return func() { lock.Unlock() }
|
||||
}
|
||||
|
||||
// New returns a new Cache instance
|
||||
func New(s metadata.Storage, ttl time.Duration) Cache {
|
||||
return Cache{
|
||||
Providers: map[string]*Spaces{},
|
||||
storage: s,
|
||||
ttl: ttl,
|
||||
lockMap: map[string]*sync.Mutex{},
|
||||
}
|
||||
}
|
||||
|
||||
// Add adds a share to the cache
|
||||
func (c *Cache) Add(ctx context.Context, storageID, spaceID, shareID string, share *collaboration.Share) error {
|
||||
unlock := c.LockSpace(spaceID)
|
||||
defer unlock()
|
||||
|
||||
ctx, span := appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "Add")
|
||||
defer span.End()
|
||||
span.SetAttributes(attribute.String("cs3.storageid", storageID), attribute.String("cs3.spaceid", spaceID), attribute.String("cs3.shareid", shareID))
|
||||
@@ -131,6 +155,9 @@ func (c *Cache) Add(ctx context.Context, storageID, spaceID, shareID string, sha
|
||||
|
||||
// Remove removes a share from the cache
|
||||
func (c *Cache) Remove(ctx context.Context, storageID, spaceID, shareID string) error {
|
||||
unlock := c.LockSpace(spaceID)
|
||||
defer unlock()
|
||||
|
||||
ctx, span := appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "Remove")
|
||||
defer span.End()
|
||||
span.SetAttributes(attribute.String("cs3.storageid", storageID), attribute.String("cs3.spaceid", spaceID), attribute.String("cs3.shareid", shareID))
|
||||
@@ -212,6 +239,9 @@ func (c *Cache) Persist(ctx context.Context, storageID, spaceID string) error {
|
||||
|
||||
// Sync updates the in-memory data with the data from the storage if it is outdated
|
||||
func (c *Cache) Sync(ctx context.Context, storageID, spaceID string) error {
|
||||
unlock := c.LockSpace(spaceID)
|
||||
defer unlock()
|
||||
|
||||
ctx, span := appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "Sync")
|
||||
defer span.End()
|
||||
|
||||
|
||||
Generated
Vendored
+29
-3
@@ -24,6 +24,7 @@ import (
|
||||
"fmt"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1"
|
||||
@@ -43,6 +44,9 @@ const tracerName = "receivedsharecache"
|
||||
// It functions as an in-memory cache with a persistence layer
|
||||
// The storage is sharded by user
|
||||
type Cache struct {
|
||||
lockMapLock sync.Mutex
|
||||
lockMap map[string]*sync.Mutex
|
||||
|
||||
ReceivedSpaces map[string]*Spaces
|
||||
|
||||
storage metadata.Storage
|
||||
@@ -75,11 +79,30 @@ func New(s metadata.Storage, ttl time.Duration) Cache {
|
||||
ReceivedSpaces: map[string]*Spaces{},
|
||||
storage: s,
|
||||
ttl: ttl,
|
||||
lockMap: map[string]*sync.Mutex{},
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Cache) lockUser(userID string) func() {
|
||||
lock := c.lockMap[userID]
|
||||
if lock == nil {
|
||||
c.lockMapLock.Lock()
|
||||
lock = c.lockMap[userID]
|
||||
if lock == nil {
|
||||
c.lockMap[userID] = &sync.Mutex{}
|
||||
lock = c.lockMap[userID]
|
||||
}
|
||||
c.lockMapLock.Unlock()
|
||||
}
|
||||
lock.Lock()
|
||||
return func() { lock.Unlock() }
|
||||
}
|
||||
|
||||
// Add adds a new entry to the cache
|
||||
func (c *Cache) Add(ctx context.Context, userID, spaceID string, rs *collaboration.ReceivedShare) error {
|
||||
unlock := c.lockUser(userID)
|
||||
defer unlock()
|
||||
|
||||
ctx, span := appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "Add")
|
||||
defer span.End()
|
||||
span.SetAttributes(attribute.String("cs3.userid", userID), attribute.String("cs3.spaceid", spaceID))
|
||||
@@ -103,7 +126,7 @@ func (c *Cache) Add(ctx context.Context, userID, spaceID string, rs *collaborati
|
||||
MountPoint: rs.MountPoint,
|
||||
}
|
||||
|
||||
return c.Persist(ctx, userID)
|
||||
return c.persist(ctx, userID)
|
||||
}
|
||||
|
||||
// Get returns one entry from the cache
|
||||
@@ -116,6 +139,9 @@ func (c *Cache) Get(userID, spaceID, shareID string) *State {
|
||||
|
||||
// Sync updates the in-memory data with the data from the storage if it is outdated
|
||||
func (c *Cache) Sync(ctx context.Context, userID string) error {
|
||||
unlock := c.lockUser(userID)
|
||||
defer unlock()
|
||||
|
||||
ctx, span := appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "Sync")
|
||||
defer span.End()
|
||||
span.SetAttributes(attribute.String("cs3.userid", userID))
|
||||
@@ -172,8 +198,8 @@ func (c *Cache) Sync(ctx context.Context, userID string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Persist persists the data for one user to the storage
|
||||
func (c *Cache) Persist(ctx context.Context, userID string) error {
|
||||
// persist persists the data for one user to the storage
|
||||
func (c *Cache) persist(ctx context.Context, userID string) error {
|
||||
ctx, span := appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "Persist")
|
||||
defer span.End()
|
||||
span.SetAttributes(attribute.String("cs3.userid", userID))
|
||||
|
||||
Generated
Vendored
+29
@@ -24,6 +24,7 @@ import (
|
||||
"fmt"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/cs3org/reva/v2/pkg/appctx"
|
||||
@@ -42,6 +43,9 @@ const tracerName = "sharecache"
|
||||
// It functions as an in-memory cache with a persistence layer
|
||||
// The storage is sharded by user/group
|
||||
type Cache struct {
|
||||
lockMapLock sync.Mutex
|
||||
lockMap map[string]*sync.Mutex
|
||||
|
||||
UserShares map[string]*UserShareCache
|
||||
|
||||
storage metadata.Storage
|
||||
@@ -64,6 +68,21 @@ type SpaceShareIDs struct {
|
||||
IDs map[string]struct{}
|
||||
}
|
||||
|
||||
func (c *Cache) lockUser(userID string) func() {
|
||||
lock := c.lockMap[userID]
|
||||
if lock == nil {
|
||||
c.lockMapLock.Lock()
|
||||
lock = c.lockMap[userID]
|
||||
if lock == nil {
|
||||
c.lockMap[userID] = &sync.Mutex{}
|
||||
lock = c.lockMap[userID]
|
||||
}
|
||||
c.lockMapLock.Unlock()
|
||||
}
|
||||
lock.Lock()
|
||||
return func() { lock.Unlock() }
|
||||
}
|
||||
|
||||
// New returns a new Cache instance
|
||||
func New(s metadata.Storage, namespace, filename string, ttl time.Duration) Cache {
|
||||
return Cache{
|
||||
@@ -72,11 +91,15 @@ func New(s metadata.Storage, namespace, filename string, ttl time.Duration) Cach
|
||||
namespace: namespace,
|
||||
filename: filename,
|
||||
ttl: ttl,
|
||||
lockMap: map[string]*sync.Mutex{},
|
||||
}
|
||||
}
|
||||
|
||||
// Add adds a share to the cache
|
||||
func (c *Cache) Add(ctx context.Context, userid, shareID string) error {
|
||||
unlock := c.lockUser(userid)
|
||||
defer unlock()
|
||||
|
||||
ctx, span := appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "Add")
|
||||
defer span.End()
|
||||
span.SetAttributes(attribute.String("cs3.userid", userid), attribute.String("cs3.shareid", shareID))
|
||||
@@ -104,6 +127,9 @@ func (c *Cache) Add(ctx context.Context, userid, shareID string) error {
|
||||
|
||||
// Remove removes a share for the given user
|
||||
func (c *Cache) Remove(ctx context.Context, userid, shareID string) error {
|
||||
unlock := c.lockUser(userid)
|
||||
defer unlock()
|
||||
|
||||
ctx, span := appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "Remove")
|
||||
defer span.End()
|
||||
span.SetAttributes(attribute.String("cs3.userid", userid), attribute.String("cs3.shareid", shareID))
|
||||
@@ -147,6 +173,9 @@ func (c *Cache) List(userid string) map[string]SpaceShareIDs {
|
||||
|
||||
// Sync updates the in-memory data with the data from the storage if it is outdated
|
||||
func (c *Cache) Sync(ctx context.Context, userID string) error {
|
||||
unlock := c.lockUser(userID)
|
||||
defer unlock()
|
||||
|
||||
ctx, span := appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "Sync")
|
||||
defer span.End()
|
||||
span.SetAttributes(attribute.String("cs3.userid", userID))
|
||||
|
||||
Reference in New Issue
Block a user