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

add(store): queries syncer #375

Merged
merged 2 commits into from
Jul 10, 2023
Merged
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
42 changes: 32 additions & 10 deletions pkg/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"math/big"
"os"
"sort"
"sync"
"time"

"go.uber.org/zap"
Expand Down Expand Up @@ -161,12 +162,25 @@ func (ds delegatingStore) Create(ctx context.Context, testBuilder, oracleBuilder
}

func (ds delegatingStore) Mutate(ctx context.Context, builder qb.Builder, values ...interface{}) error {
if err := mutate(ctx, ds.oracleStore, builder, values...); err != nil {
var testErr error
var wg sync.WaitGroup
wg.Add(1)
go func() {
testErr = mutate(ctx, ds.testStore, builder, values...)
wg.Done()
}()
if oracleErr := mutate(ctx, ds.oracleStore, builder, values...); oracleErr != nil {
// Oracle failed, transition cannot take place
ds.logger.Info("oracle failed mutation, transition to next state impossible so continuing with next mutation", zap.Error(err))
return nil
ds.logger.Info("oracle store failed mutation, transition to next state impossible so continuing with next mutation", zap.Error(oracleErr))
return oracleErr
}
wg.Wait()
if testErr != nil {
// Test store failed, transition cannot take place
ds.logger.Info("test store failed mutation, transition to next state impossible so continuing with next mutation", zap.Error(testErr))
return testErr
}
return mutate(ctx, ds.testStore, builder, values...)
return nil
}

func mutate(ctx context.Context, s storeLoader, builder qb.Builder, values ...interface{}) error {
Expand All @@ -177,13 +191,21 @@ func mutate(ctx context.Context, s storeLoader, builder qb.Builder, values ...in
}

func (ds delegatingStore) Check(ctx context.Context, table *typedef.Table, builder qb.Builder, values ...interface{}) error {
testRows, err := ds.testStore.load(ctx, builder, values)
if err != nil {
return errors.Wrapf(err, "unable to load check data from the test store")
var testRows, oracleRows []map[string]interface{}
illia-li marked this conversation as resolved.
Show resolved Hide resolved
var testErr, oracleErr error
var wg sync.WaitGroup
wg.Add(1)
go func() {
testRows, testErr = ds.testStore.load(ctx, builder, values)
wg.Done()
}()
oracleRows, oracleErr = ds.oracleStore.load(ctx, builder, values)
if oracleErr != nil {
return errors.Wrapf(oracleErr, "unable to load check data from the oracle store")
}
oracleRows, err := ds.oracleStore.load(ctx, builder, values)
if err != nil {
return errors.Wrapf(err, "unable to load check data from the oracle store")
wg.Wait()
if testErr != nil {
return errors.Wrapf(testErr, "unable to load check data from the test store")
}
if !ds.validations {
return nil
Expand Down