Skip to content

Commit

Permalink
Merge pull request #641 from ystia/bugfix/GH-640-data-migration-concu…
Browse files Browse the repository at this point in the history
…rrency-limit

Add concurrency limit during data migration for file storage
  • Loading branch information
stebenoist committed May 5, 2020
2 parents 5ef127b + 19dff47 commit e2d9a8a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### BUG FIXES

* Bootstrap may failed with a nil pointer error if download of a component fails ([GH-634](https://github.com/ystia/yorc/issues/634))
* Missing concurrency limit during data migration for logs and events file storage ([GH-640](https://github.com/ystia/yorc/issues/640))

## 4.0.0 (April 17, 2020)

Expand Down
7 changes: 7 additions & 0 deletions storage/internal/file/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type fileStore struct {
cache *ristretto.Cache
withEncryption bool
encryptor *encryption.Encryptor
concurrencyLimit int
}

// NewStore returns a new File store
Expand All @@ -75,6 +76,7 @@ func NewStore(cfg config.Configuration, storeID string, properties config.Dynami
fileLocks: make(map[string]*sync.RWMutex),
withCache: withCache,
withEncryption: withEncryption,
concurrencyLimit: cfg.UpgradeConcurrencyLimit,
}

// Instantiate cache if necessary
Expand Down Expand Up @@ -208,9 +210,14 @@ func (s *fileStore) SetCollection(ctx context.Context, keyValues []store.KeyValu
return nil
}
errGroup, ctx := errgroup.WithContext(ctx)
sem := make(chan struct{}, s.concurrencyLimit)
for _, kv := range keyValues {
sem <- struct{}{}
kvItem := kv
errGroup.Go(func() error {
defer func() {
<-sem
}()
return s.Set(ctx, kvItem.Key, kvItem.Value)
})
}
Expand Down
3 changes: 2 additions & 1 deletion storage/store/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ func SetupTestConfig(t testing.TB) config.Configuration {
assert.Nil(t, err)

return config.Configuration{
WorkingDirectory: workingDir,
WorkingDirectory: workingDir,
UpgradeConcurrencyLimit: config.DefaultUpgradesConcurrencyLimit,
}
}

Expand Down
3 changes: 2 additions & 1 deletion testutil/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func SetupTestConfig(t testing.TB) config.Configuration {
assert.Nil(t, err)

return config.Configuration{
WorkingDirectory: workingDir,
WorkingDirectory: workingDir,
UpgradeConcurrencyLimit: config.DefaultUpgradesConcurrencyLimit,
}
}

0 comments on commit e2d9a8a

Please sign in to comment.