Skip to content

Commit

Permalink
Merge pull request #3428 from fschade/max-acquire-lock-cycles
Browse files Browse the repository at this point in the history
[tests-only] Max acquire lock cycles
  • Loading branch information
dragotin authored Nov 2, 2022
2 parents 3540a98 + 89da97f commit 683c5ad
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
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

0 comments on commit 683c5ad

Please sign in to comment.