Skip to content

Commit

Permalink
vtgate client: minor behavior change for rollback
Browse files Browse the repository at this point in the history
Rollback should not return an error if we're not in a
transaction. Many frameworks generally perform a rollback
for good measure. So, returning an error just causes confusion.
  • Loading branch information
sougou committed Mar 11, 2015
1 parent 5d61cab commit 5fb6f92
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go/vt/vtgate/gorpcvtgateconn/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (tx *vtgateTx) Commit(ctx context.Context) error {

func (tx *vtgateTx) Rollback(ctx context.Context) error {
if tx.session == nil {
return errors.New("rollback: not in transaction")
return nil
}
defer func() { tx.session = nil }()
return tx.conn.rpcConn.Call(ctx, "VTGate.Rollback", tx.session, &rpc.Unused{})
Expand Down
5 changes: 2 additions & 3 deletions go/vt/vtgate/vtgateconntest/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,8 @@ func testTxFail(t *testing.T, conn vtgateconn.VTGateConn) {
}

err = tx.Rollback(ctx)
want = "rollback: not in transaction"
if err == nil || err.Error() != want {
t.Errorf("Rollback: %v, want %v", err, want)
if err != nil {
t.Error(err)
}

tx, err = conn.Begin(ctx)
Expand Down

0 comments on commit 5fb6f92

Please sign in to comment.