From 2905629e2d17435f40f6ed3cd54887dca1671551 Mon Sep 17 00:00:00 2001 From: Drew Kimball Date: Sat, 22 Apr 2023 19:11:32 +0000 Subject: [PATCH] workload/tpcc: move tpcc error checks before length checks Some of the TPCC consistency checks ensure that the number of rows returned by two queries is the same. This is done by checking that if one of the iterators returns false, they both do. However, if one of the iterators encounters an error, it will return false even though there are still rows left. This could cause the consistency check to seem as if it failed with incorrect results: ``` Error: check failed: 3.3.2.4: at 1682088974198157583.0000000000: length of order.sum(o_ol_cnt) != order_line.count(*) ``` when really one of the iterators just encountered an error. This patch moves the error-checking before the length checking, so that the correct error message is returned. Fixes #102004 Release note: None --- pkg/workload/tpcc/checks.go | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/pkg/workload/tpcc/checks.go b/pkg/workload/tpcc/checks.go index a4d99f612b3c..a58771ad0e15 100644 --- a/pkg/workload/tpcc/checks.go +++ b/pkg/workload/tpcc/checks.go @@ -147,15 +147,27 @@ ORDER BY i, order, newOrder, district-1) } } + if err := districtRows.Err(); err != nil { + retErr = errors.CombineErrors(retErr, errors.Wrap(err, "on district")) + } + if err := newOrderRows.Err(); err != nil { + retErr = errors.CombineErrors(retErr, errors.Wrap(err, "on new_order")) + } + if err := orderRows.Err(); err != nil { + retErr = errors.CombineErrors(retErr, errors.Wrap(err, "on order")) + } + // Return the error before performing the remaining checks, because they are + // expected to fail if something else has already gone wrong. + if retErr != nil { + return retErr + } if districtRows.Next() || newOrderRows.Next() || orderRows.Next() { return errors.New("length mismatch between rows") } if i == 0 { return errors.Errorf("zero rows") } - retErr = errors.CombineErrors(retErr, districtRows.Err()) - retErr = errors.CombineErrors(retErr, newOrderRows.Err()) - return errors.CombineErrors(retErr, orderRows.Err()) + return nil } func check3323(db *gosql.DB, asOfSystemTime string) error { @@ -243,18 +255,18 @@ ORDER BY return errors.Errorf("order.sum(o_ol_cnt): %d != order_line.count(*): %d", left, right) } } - if leftRows.Next() || rightRows.Next() { - return errors.Errorf("at %s: length of order.sum(o_ol_cnt) != order_line.count(*)", ts) - } - if i == 0 { - return errors.Errorf("0 rows returned") - } if err := leftRows.Err(); err != nil { return errors.Wrap(err, "on `order`") } if err := rightRows.Err(); err != nil { return errors.Wrap(err, "on `order_line`") } + if leftRows.Next() || rightRows.Next() { + return errors.Errorf("at %s: length of order.sum(o_ol_cnt) != order_line.count(*)", ts) + } + if i == 0 { + return errors.Errorf("0 rows returned") + } return nil }