mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-04-22 11:09:02 -05:00
update reva
This commit is contained in:
Generated
Vendored
+7
-3
@@ -129,9 +129,13 @@ type ShareData struct {
|
||||
// The type of the object being shared. This can be one of 'file' or 'folder'.
|
||||
ItemType string `json:"item_type" xml:"item_type"`
|
||||
// The RFC2045-compliant mimetype of the file.
|
||||
MimeType string `json:"mimetype" xml:"mimetype"`
|
||||
StorageID string `json:"storage_id" xml:"storage_id"`
|
||||
Storage uint64 `json:"storage" xml:"storage"`
|
||||
MimeType string `json:"mimetype" xml:"mimetype"`
|
||||
// The space ID of the original file location
|
||||
SpaceID string `json:"space_id" xml:"space_id"`
|
||||
// The space alias of the original file location
|
||||
SpaceAlias string `json:"space_alias" xml:"space_alias"`
|
||||
StorageID string `json:"storage_id" xml:"storage_id"`
|
||||
Storage uint64 `json:"storage" xml:"storage"`
|
||||
// The unique node id of the item being shared.
|
||||
ItemSource string `json:"item_source" xml:"item_source"`
|
||||
// The unique node id of the item being shared. For legacy reasons item_source and file_source attributes have the same value.
|
||||
|
||||
Generated
Vendored
+5
@@ -1209,6 +1209,11 @@ func (h *Handler) addFileInfo(ctx context.Context, s *conversions.ShareData, inf
|
||||
if s.UIDOwner == "" && owner != nil {
|
||||
s.UIDOwner = owner.GetOpaqueId()
|
||||
}
|
||||
|
||||
if info.GetSpace().GetRoot() != nil {
|
||||
s.SpaceID = storagespace.FormatResourceID(*info.GetSpace().GetRoot())
|
||||
}
|
||||
s.SpaceAlias = utils.ReadPlainFromOpaque(info.GetSpace().GetOpaque(), "spaceAlias")
|
||||
}
|
||||
|
||||
// mustGetIdentifiers always returns a struct with identifiers, if the user or group could not be found they will all be empty
|
||||
|
||||
+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))
|
||||
|
||||
+2
-2
@@ -948,11 +948,11 @@ func (n *Node) IsDisabled() bool {
|
||||
|
||||
// GetTreeSize reads the treesize from the extended attributes
|
||||
func (n *Node) GetTreeSize() (treesize uint64, err error) {
|
||||
s, err := n.XattrInt64(prefixes.TreesizeAttr)
|
||||
s, err := n.XattrUint64(prefixes.TreesizeAttr)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return uint64(s), nil
|
||||
return s, nil
|
||||
}
|
||||
|
||||
// SetTreeSize writes the treesize to the extended attributes
|
||||
|
||||
+9
@@ -174,3 +174,12 @@ func (n *Node) XattrInt64(key string) (int64, error) {
|
||||
}
|
||||
return strconv.ParseInt(b, 10, 64)
|
||||
}
|
||||
|
||||
// XattrUint64 returns the uint64 representation of an attribute
|
||||
func (n *Node) XattrUint64(key string) (uint64, error) {
|
||||
b, err := n.XattrString(key)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return strconv.ParseUint(b, 10, 64)
|
||||
}
|
||||
|
||||
+10
-5
@@ -794,12 +794,17 @@ func (t *Tree) Propagate(ctx context.Context, n *node.Node, sizeDiff int64) (err
|
||||
}
|
||||
case err != nil:
|
||||
return err
|
||||
case sizeDiff > 0:
|
||||
newSize = treeSize + uint64(sizeDiff)
|
||||
case uint64(-sizeDiff) > treeSize:
|
||||
// The sizeDiff is larger than the current treesize. Which would result in
|
||||
// a negative new treesize. Something must have gone wrong with the accounting.
|
||||
// Reset the current treesize to 0.
|
||||
sublog.Error().Uint64("treeSize", treeSize).Int64("sizeDiff", sizeDiff).
|
||||
Msg("Error when updating treesize of parent node. Updated treesize < 0. Reestting to 0")
|
||||
newSize = 0
|
||||
default:
|
||||
if sizeDiff > 0 {
|
||||
newSize = treeSize + uint64(sizeDiff)
|
||||
} else {
|
||||
newSize = treeSize - uint64(-sizeDiff)
|
||||
}
|
||||
newSize = treeSize - uint64(-sizeDiff)
|
||||
}
|
||||
|
||||
// update the tree size of the node
|
||||
|
||||
Reference in New Issue
Block a user