Skip to content

Commit

Permalink
fix(repositories): remove Lock Access in unlockfunc (#6295)
Browse files Browse the repository at this point in the history
  • Loading branch information
sguiheux authored Sep 21, 2022
1 parent 153be18 commit f9d2ee9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion engine/repositories/cleaner.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (s *Service) vacuumFileSystemCleanerFunc(ctx context.Context, repoUUID stri

if !s.dao.isExpired(ctx, repoUUID) {
log.Debug(ctx, "vacuumFileSystemCleanerFunc> %s is not expired. skipping", repoUUID)
_ = s.dao.unlock(ctx, repoUUID, 24*time.Hour*time.Duration(s.Cfg.RepositoriesRetention))
_ = s.dao.unlock(ctx, repoUUID)
return nil
}

Expand Down
5 changes: 1 addition & 4 deletions engine/repositories/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,10 @@ func (d *dao) deleteLock(ctx context.Context, uuid string) error {
return nil
}

func (d *dao) unlock(ctx context.Context, uuid string, retention time.Duration) error {
func (d *dao) unlock(ctx context.Context, uuid string) error {
if err := d.store.Unlock(cache.Key(locksKey, uuid)); err != nil {
log.Error(ctx, "error on unlock uuid %s: %v", uuid, err)
}
if _, err := d.store.Lock(cache.Key(lastAccessKey, uuid), retention, -1, -1); err != nil {
return sdk.WrapError(err, "error on cache.lock uuid:%s", uuid)
}
return nil
}

Expand Down
9 changes: 7 additions & 2 deletions engine/repositories/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
"context"
"time"

"github.com/rockbears/log"

"github.com/ovh/cds/engine/cache"
"github.com/ovh/cds/sdk"
cdslog "github.com/ovh/cds/sdk/log"
"github.com/rockbears/log"
)

func (s *Service) processor(ctx context.Context) error {
Expand Down Expand Up @@ -51,7 +53,10 @@ func (s *Service) do(ctx context.Context, op sdk.Operation) error {
if s.dao.lock(r.ID()) == errLockUnavailable {
return errLockUnavailable
}
defer s.dao.unlock(ctx, r.ID(), 24*time.Hour*time.Duration(s.Cfg.RepositoriesRetention)) // nolint
defer func() {
s.dao.unlock(ctx, r.ID())
s.dao.store.Lock(cache.Key(lastAccessKey, r.ID()), 24*time.Hour*time.Duration(s.Cfg.RepositoriesRetention), -1, -1)
}()

switch {
// Load workflow as code file
Expand Down

0 comments on commit f9d2ee9

Please sign in to comment.