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

Release/v0.50.x cachekv par #882

Draft
wants to merge 3 commits into
base: release/v0.50.x
Choose a base branch
from
Draft
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
44 changes: 41 additions & 3 deletions store/cachemulti/store.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package cachemulti

import (
"errors"
"fmt"
"io"
"sync"

"cosmossdk.io/store/tracekv"
"cosmossdk.io/store/types"
Expand All @@ -11,7 +13,11 @@

// storeNameCtxKey is the TraceContext metadata key that identifies
// the store which emitted a given trace.
const storeNameCtxKey = "store_name"
const (
// storeNameCtxKey is the TraceContext metadata key that identifies
// the store which emitted a given trace.
storeNameCtxKey = "store_name"
)

//----------------------------------------
// Store
Expand Down Expand Up @@ -129,9 +135,41 @@
if cms.branched {
panic("cannot Write on branched store")
}
for _, store := range cms.stores {
store.Write()
if err := cms.writeStoresParallel(); err != nil {
panic(err)
}
}

func (cms Store) writeStoresParallel() error {
runnerCount := len(cms.stores)
errChan := make(chan error, runnerCount) // Channel to collect errors from goroutines
var wg sync.WaitGroup
for storeKey, store := range cms.stores {
wg.Add(1)

go func(storeKey types.StoreKey, store types.CacheWrap) {
defer func() {
wg.Done()
if r := recover(); r != nil {
errChan <- fmt.Errorf("panic in Write for store %s: %v", storeKey.Name(), r)
}
}()
store.Write()
}(storeKey, store)
Comment on lines +150 to +158

Check notice

Code scanning / CodeQL

Spawning a Go routine Note

Spawning a Go routine may be a possible source of non-determinism
}

Check warning

Code scanning / CodeQL

Iteration over map Warning

Iteration over map may be a possible source of non-determinism

go func() {
wg.Wait()
close(errChan)
}()
Comment on lines +161 to +164

Check notice

Code scanning / CodeQL

Spawning a Go routine Note

Spawning a Go routine may be a possible source of non-determinism

// Collect errors from goroutines
var allErrors []error
for err := range errChan {
allErrors = append(allErrors, err)
}

return errors.Join(allErrors...)
}

func (cms Store) Discard() {
Expand Down
Loading