Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests-only] Max acquire lock cycles #3428

Merged
merged 1 commit into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/storage/utils/decomposedfs/decomposedfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import (
"github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/tree"
"github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/upload"
"github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/xattrs"
"github.com/cs3org/reva/v2/pkg/storage/utils/filelocks"
"github.com/cs3org/reva/v2/pkg/storage/utils/templates"
"github.com/cs3org/reva/v2/pkg/storagespace"
"github.com/cs3org/reva/v2/pkg/utils"
Expand Down Expand Up @@ -145,6 +146,11 @@ func New(o *options.Options, lu *lookup.Lookup, p PermissionsChecker, tp Tree, p
return nil, errors.Wrap(err, "could not setup tree")
}

// Fixme: temporary workaround to make MaxAcquireLockCycles configurable.
if o.MaxAcquireLockCycles != 0 {
filelocks.MaxAcquireLockCycles = o.MaxAcquireLockCycles
}

var ev events.Stream
if o.Events.NatsAddress != "" {
evtsCfg := o.Events
Expand Down
2 changes: 2 additions & 0 deletions pkg/storage/utils/decomposedfs/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ type Options struct {
Tokens TokenOptions `mapstructure:"tokens"`

StatCache CacheOptions `mapstructure:"statcache"`

MaxAcquireLockCycles int `mapstructure:"max_acquire_lock_cycles"`
}

// EventOptions are the configurable options for events
Expand Down
8 changes: 6 additions & 2 deletions pkg/storage/utils/filelocks/filelocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ import (
"github.com/gofrs/flock"
)

var _localLocks sync.Map
var (
_localLocks sync.Map
// MaxAcquireLockCycles defines how often the system tries to acquire a lock before failing.
MaxAcquireLockCycles = 25
)

// getMutexedFlock returns a new Flock struct for the given file.
// If there is already one in the local store, it returns nil.
Expand Down Expand Up @@ -70,7 +74,7 @@ func acquireLock(file string, write bool) (*flock.Flock, error) {
}

var flock *flock.Flock
for i := 1; i <= 10; i++ {
for i := 1; i <= MaxAcquireLockCycles; i++ {
if flock = getMutexedFlock(n); flock != nil {
break
}
Expand Down