Skip to content

Commit

Permalink
feat: rootmulti store parallel commit (#218)
Browse files Browse the repository at this point in the history
* rootmulti store parallel commit

* += 1 -> ++ for lint

Co-authored-by: wetcod <[email protected]>
  • Loading branch information
iproudhon and wetcod authored Jun 2, 2021
1 parent 9c2db65 commit 2f5ffad
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions store/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"math"
"sort"
"strings"
"sync"

protoio "github.com/gogo/protobuf/io"
gogotypes "github.com/gogo/protobuf/types"
Expand Down Expand Up @@ -908,16 +909,24 @@ func getLatestVersion(db tmdb.DB) int64 {

// Commits each store and returns a new commitInfo.
func commitStores(version int64, storeMap map[types.StoreKey]types.CommitKVStore) *types.CommitInfo {
storeInfos := make([]types.StoreInfo, 0, len(storeMap))
storeInfos := make([]types.StoreInfo, len(storeMap))

var wg sync.WaitGroup
ix := 0
for key, store := range storeMap {
commitID := store.Commit()

si := types.StoreInfo{}
si.Name = key.Name()
si.CommitId = commitID
storeInfos = append(storeInfos, si)
}
wg.Add(1)
go func(i int, k types.StoreKey, s types.CommitKVStore) {
commitID := s.Commit()

si := types.StoreInfo{}
si.Name = k.Name()
si.CommitId = commitID
storeInfos[i] = si
wg.Done()
}(ix, key, store)
ix++
}
wg.Wait()

return &types.CommitInfo{
Version: version,
Expand Down

0 comments on commit 2f5ffad

Please sign in to comment.