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

fix(repositories): remove Lock Access in unlockfunc #6295

Merged
merged 1 commit into from
Sep 21, 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
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