Skip to content

Commit

Permalink
CherryPick(#15962): Improve WaitForPos errors, don't include Result s…
Browse files Browse the repository at this point in the history
…truct in message (#5239)

* cherry pick of 15962

* Fix conflicts

Signed-off-by: Matt Lord <mattalord@gmail.com>

---------

Signed-off-by: Matt Lord <mattalord@gmail.com>
Co-authored-by: Matt Lord <mattalord@gmail.com>
  • Loading branch information
planetscale-actions-bot and mattlord authored May 23, 2024
1 parent dcd1a3c commit 815495a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
11 changes: 11 additions & 0 deletions go/vt/vttablet/endtoend/vstreamer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"errors"
"fmt"
"strings"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -65,6 +66,7 @@ func TestSchemaVersioning(t *testing.T) {

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
wg := sync.WaitGroup{}
tsv.EnableHistorian(true)
tsv.SetTracking(true)
time.Sleep(100 * time.Millisecond) // wait for _vt tables to be created
Expand Down Expand Up @@ -155,7 +157,9 @@ func TestSchemaVersioning(t *testing.T) {
}
return nil
}
wg.Add(1)
go func() {
defer wg.Done()
defer close(eventCh)
req := &binlogdatapb.VStreamRequest{Target: target, Position: "current", TableLastPKs: nil, Filter: filter}
if err := tsv.VStream(ctx, req, send); err != nil {
Expand Down Expand Up @@ -186,6 +190,7 @@ func TestSchemaVersioning(t *testing.T) {
}
runCases(ctx, t, cases, eventCh)
cancel()
wg.Wait()

log.Infof("\n\n\n=============================================== PAST EVENTS WITH TRACK VERSIONS START HERE ======================\n\n\n")
ctx, cancel = context.WithCancel(context.Background())
Expand Down Expand Up @@ -214,7 +219,9 @@ func TestSchemaVersioning(t *testing.T) {
}
return nil
}
wg.Add(1)
go func() {
defer wg.Done()
defer close(eventCh)
req := &binlogdatapb.VStreamRequest{Target: target, Position: startPos, TableLastPKs: nil, Filter: filter}
if err := tsv.VStream(ctx, req, send); err != nil {
Expand Down Expand Up @@ -257,6 +264,7 @@ func TestSchemaVersioning(t *testing.T) {
expectLogs(ctx, t, "Past stream", eventCh, output)

cancel()
wg.Wait()

log.Infof("\n\n\n=============================================== PAST EVENTS WITHOUT TRACK VERSIONS START HERE ======================\n\n\n")
tsv.EnableHistorian(false)
Expand Down Expand Up @@ -286,7 +294,9 @@ func TestSchemaVersioning(t *testing.T) {
}
return nil
}
wg.Add(1)
go func() {
defer wg.Done()
defer close(eventCh)
req := &binlogdatapb.VStreamRequest{Target: target, Position: startPos, TableLastPKs: nil, Filter: filter}
if err := tsv.VStream(ctx, req, send); err != nil {
Expand Down Expand Up @@ -331,6 +341,7 @@ func TestSchemaVersioning(t *testing.T) {

expectLogs(ctx, t, "Past stream", eventCh, output)
cancel()
wg.Wait()

client := framework.NewClient()
client.Execute("drop table vitess_version", nil)
Expand Down
6 changes: 4 additions & 2 deletions go/vt/vttablet/tabletmanager/vreplication/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -790,8 +790,10 @@ func (vre *Engine) WaitForPos(ctx context.Context, id int32, pos string) error {
}
case len(qr.Rows) == 0:
return fmt.Errorf("vreplication stream %d not found", id)
case len(qr.Rows) > 1 || len(qr.Rows[0]) != 3:
return fmt.Errorf("unexpected result: %v", qr)
case len(qr.Rows) > 1:
return fmt.Errorf("vreplication stream received more rows than expected, got %d instead of 1", len(qr.Rows))
case len(qr.Rows[0]) != 3:
return fmt.Errorf("vreplication stream received an unexpected number of columns, got %d instead of 3", len(qr.Rows[0]))
}

// When err is not nil then we got a retryable error and will loop again.
Expand Down
5 changes: 3 additions & 2 deletions go/vt/vttablet/tabletmanager/vreplication/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,8 @@ func TestWaitForPosError(t *testing.T) {

dbClient.ExpectRequest("select pos, state, message from _vt.vreplication where id=1", &sqltypes.Result{Rows: [][]sqltypes.Value{{}}}, nil)
err = vre.WaitForPos(context.Background(), 1, "MariaDB/0-1-1084")
want = "unexpected result: &{[] 0 0 map[] 0 [[]] 0 }"
want = "vreplication stream received an unexpected number of columns, got 0 instead of 3"

assert.EqualError(t, err, want, "WaitForPos:")

dbClient.ExpectRequest("select pos, state, message from _vt.vreplication where id=1", &sqltypes.Result{Rows: [][]sqltypes.Value{{
Expand All @@ -435,7 +436,7 @@ func TestWaitForPosError(t *testing.T) {
sqltypes.NewVarBinary("MariaDB/0-1-1083"),
}}}, nil)
err = vre.WaitForPos(context.Background(), 1, "MariaDB/0-1-1084")
want = `unexpected result: &{[] 0 0 map[] 0 [[VARBINARY("MariaDB/0-1-1083")] [VARBINARY("MariaDB/0-1-1083")]] 0 }`
want = "vreplication stream received more rows than expected, got 2 instead of 1"
assert.EqualError(t, err, want, "WaitForPos:")
}

Expand Down

0 comments on commit 815495a

Please sign in to comment.