Skip to content

Commit

Permalink
fix(store): complex diff only at last retry attempt
Browse files Browse the repository at this point in the history
makes 'Check' function return complex diff information only at last retry attempt
  • Loading branch information
illia-li committed Aug 26, 2023
1 parent edb34a9 commit 94b0aea
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/jobs/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ func validation(
attempt := 1
for {
lastErr = err
err = s.Check(ctx, table, stmt.Query, stmt.Values...)
err = s.Check(ctx, table, stmt.Query, attempt == maxAttempts, stmt.Values...)

if err == nil {
if attempt > 1 {
Expand Down
10 changes: 8 additions & 2 deletions pkg/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type storeLoader interface {
type Store interface {
Create(context.Context, qb.Builder, qb.Builder) error
Mutate(context.Context, qb.Builder, ...interface{}) error
Check(context.Context, *typedef.Table, qb.Builder, ...interface{}) error
Check(context.Context, *typedef.Table, qb.Builder, bool, ...interface{}) error
Close() error
}

Expand Down Expand Up @@ -191,7 +191,7 @@ func mutate(ctx context.Context, s storeLoader, builder qb.Builder, values ...in
return nil
}

func (ds delegatingStore) Check(ctx context.Context, table *typedef.Table, builder qb.Builder, values ...interface{}) error {
func (ds delegatingStore) Check(ctx context.Context, table *typedef.Table, builder qb.Builder, detailedDiff bool, values ...interface{}) error {
var testRows, oracleRows []map[string]interface{}
var testErr, oracleErr error
var wg sync.WaitGroup
Expand All @@ -215,6 +215,9 @@ func (ds delegatingStore) Check(ctx context.Context, table *typedef.Table, build
return nil
}
if len(testRows) != len(oracleRows) {
if !detailedDiff {
return fmt.Errorf("rows count differ (test store rows %d, oracle store rows %d, detailed information will be at last attempt)", len(testRows), len(oracleRows))
}
testSet := strset.New(pks(table, testRows)...)
oracleSet := strset.New(pks(table, oracleRows)...)
missingInTest := strset.Difference(oracleSet, testSet).List()
Expand All @@ -225,6 +228,9 @@ func (ds delegatingStore) Check(ctx context.Context, table *typedef.Table, build
if reflect.DeepEqual(testRows, oracleRows) {
return nil
}
if !detailedDiff {
return fmt.Errorf("test and oracle store have difference, detailed information will be at last attempt")
}
sort.SliceStable(testRows, func(i, j int) bool {
return lt(testRows[i], testRows[j])
})
Expand Down

0 comments on commit 94b0aea

Please sign in to comment.