Skip to content

Commit

Permalink
fix panic when locking files
Browse files Browse the repository at this point in the history
Signed-off-by: jkoberg <jkoberg@owncloud.com>
  • Loading branch information
kobergj committed Dec 4, 2023
1 parent a389ddc commit 97562de
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/storage/cache/stat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions pkg/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 97562de

Please sign in to comment.