From 9e5709293db91009c8ee5b2f299a83313c78da82 Mon Sep 17 00:00:00 2001 From: jkoberg Date: Mon, 27 Nov 2023 10:18:34 +0100 Subject: [PATCH] fix panic when locking files Signed-off-by: jkoberg --- pkg/storage/cache/stat.go | 2 +- .../decomposedfs/metadata/messagepack_backend.go | 7 +++---- pkg/store/store.go | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/pkg/storage/cache/stat.go b/pkg/storage/cache/stat.go index bb39cf93956..cb236d6fd78 100644 --- a/pkg/storage/cache/stat.go +++ b/pkg/storage/cache/stat.go @@ -74,7 +74,7 @@ func (c statCache) RemoveStatContext(ctx context.Context, userID *userpb.UserId, // TODO currently, invalidating the stat cache is inefficient and should be disabled. Storage providers / drivers can more selectively invalidate stat cache entries. // This shotgun invalidation wipes all cache entries for the user, space, and nodeid of a changed resource, which means the stat cache is mostly empty, anyway. - prefixes := []string{uid, "*" + sid, "*" + oid} + prefixes := []string{uid, sid, oid} wg := sync.WaitGroup{} for _, prefix := range prefixes { diff --git a/pkg/storage/utils/decomposedfs/metadata/messagepack_backend.go b/pkg/storage/utils/decomposedfs/metadata/messagepack_backend.go index 22485d7b3c3..92caf0cf52a 100644 --- a/pkg/storage/utils/decomposedfs/metadata/messagepack_backend.go +++ b/pkg/storage/utils/decomposedfs/metadata/messagepack_backend.go @@ -151,12 +151,11 @@ func (b MessagePackBackend) saveAttributes(ctx context.Context, path string, set _, subspan := tracer.Start(ctx, "lockedfile.OpenFile") f, err = lockedfile.OpenFile(lockPath, os.O_RDWR|os.O_CREATE, 0600) subspan.End() + if err != nil { + return err + } defer f.Close() } - if err != nil { - return err - } - // Read current state _, subspan := tracer.Start(ctx, "os.ReadFile") var msgBytes []byte diff --git a/pkg/store/store.go b/pkg/store/store.go index 68f71e3fac3..219eea4194d 100644 --- a/pkg/store/store.go +++ b/pkg/store/store.go @@ -26,6 +26,7 @@ import ( "github.com/cs3org/reva/v2/pkg/store/etcd" "github.com/cs3org/reva/v2/pkg/store/memory" natsjs "github.com/go-micro/plugins/v4/store/nats-js" + natsjskv "github.com/go-micro/plugins/v4/store/nats-js-kv" "github.com/go-micro/plugins/v4/store/redis" redisopts "github.com/go-redis/redis/v8" "github.com/nats-io/nats.go" @@ -50,6 +51,8 @@ const ( TypeOCMem = "ocmem" // TypeNatsJS represents nats-js stores TypeNatsJS = "nats-js" + // TypeNatsJSKV represents nats-js-kv stores + TypeNatsJSKV = "nats-js-kv" ) // Create initializes a new store @@ -126,6 +129,18 @@ func Create(opts ...microstore.Option) microstore.Store { natsjs.NatsOptions(natsOptions), // always pass in properly initialized default nats options natsjs.DefaultTTL(ttl))..., ) // TODO test with ocis nats + case TypeNatsJSKV: + ttl, _ := options.Context.Value(ttlContextKey{}).(time.Duration) + // TODO nats needs a DefaultTTL option as it does not support per Write TTL ... + // FIXME nats has restrictions on the key, we cannot use slashes AFAICT + // host, port, clusterid + natsOptions := nats.GetDefaultOptions() + natsOptions.Name = "TODO" // we can pass in the service name to allow identifying the client, but that requires adding a custom context option + return natsjskv.NewStore( + append(opts, + natsjs.NatsOptions(natsOptions), // always pass in properly initialized default nats options + natsjs.DefaultTTL(ttl))..., + ) // TODO test with ocis nats case TypeMemory, "mem", "": // allow existing short form and use as default return microstore.NewMemoryStore(opts...) default: