Skip to content

Commit

Permalink
Improve WaitForPos errors, don't include Result struct in message (#1…
Browse files Browse the repository at this point in the history
…5962)

Signed-off-by: Rafer Hazen <rafer@ralua.com>
  • Loading branch information
rafer committed May 22, 2024
1 parent a1edaee commit 0d8ca1b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
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 [[]] 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 [[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 0d8ca1b

Please sign in to comment.