Skip to content

Commit

Permalink
Merge pull request #375 from illia-li/il/add-store-queries_syncer
Browse files Browse the repository at this point in the history
add(store): queries syncer
  • Loading branch information
dkropachev authored Jul 10, 2023
2 parents 8442ad5 + 7c33379 commit c4a4a8f
Showing 1 changed file with 32 additions and 10 deletions.
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{}
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

0 comments on commit c4a4a8f

Please sign in to comment.