зеркало из https://github.com/github/vitess-gh.git
vtgateconn correctly receieves errors when they're sent in the RPC response for Execute*, tests pass
This commit is contained in:
Родитель
86e72b84a3
Коммит
bee894035b
|
@ -17,6 +17,7 @@ import (
|
|||
"github.com/youtube/vitess/go/vt/rpc"
|
||||
tproto "github.com/youtube/vitess/go/vt/tabletserver/proto"
|
||||
"github.com/youtube/vitess/go/vt/topo"
|
||||
"github.com/youtube/vitess/go/vt/vterrors"
|
||||
"github.com/youtube/vitess/go/vt/vtgate/proto"
|
||||
"github.com/youtube/vitess/go/vt/vtgate/vtgateconn"
|
||||
"golang.org/x/net/context"
|
||||
|
@ -61,6 +62,9 @@ func (conn *vtgateConn) Execute(ctx context.Context, query string, bindVars map[
|
|||
if result.Error != "" {
|
||||
return nil, result.Session, errors.New(result.Error)
|
||||
}
|
||||
if err := vterrors.FromRPCError(result.Err); err != nil {
|
||||
return nil, result.Session, err
|
||||
}
|
||||
return result.Result, result.Session, nil
|
||||
}
|
||||
|
||||
|
@ -85,6 +89,9 @@ func (conn *vtgateConn) ExecuteShard(ctx context.Context, query string, keyspace
|
|||
if result.Error != "" {
|
||||
return nil, result.Session, errors.New(result.Error)
|
||||
}
|
||||
if err := vterrors.FromRPCError(result.Err); err != nil {
|
||||
return nil, result.Session, err
|
||||
}
|
||||
return result.Result, result.Session, nil
|
||||
}
|
||||
|
||||
|
@ -109,6 +116,9 @@ func (conn *vtgateConn) ExecuteKeyspaceIds(ctx context.Context, query string, ke
|
|||
if result.Error != "" {
|
||||
return nil, result.Session, errors.New(result.Error)
|
||||
}
|
||||
if err := vterrors.FromRPCError(result.Err); err != nil {
|
||||
return nil, result.Session, err
|
||||
}
|
||||
return result.Result, result.Session, nil
|
||||
}
|
||||
|
||||
|
@ -133,6 +143,9 @@ func (conn *vtgateConn) ExecuteKeyRanges(ctx context.Context, query string, keys
|
|||
if result.Error != "" {
|
||||
return nil, result.Session, errors.New(result.Error)
|
||||
}
|
||||
if err := vterrors.FromRPCError(result.Err); err != nil {
|
||||
return nil, result.Session, err
|
||||
}
|
||||
return result.Result, result.Session, nil
|
||||
}
|
||||
|
||||
|
@ -158,6 +171,9 @@ func (conn *vtgateConn) ExecuteEntityIds(ctx context.Context, query string, keys
|
|||
if result.Error != "" {
|
||||
return nil, result.Session, errors.New(result.Error)
|
||||
}
|
||||
if err := vterrors.FromRPCError(result.Err); err != nil {
|
||||
return nil, result.Session, err
|
||||
}
|
||||
return result.Result, result.Session, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,12 @@ func (queryResult *QueryResult) MarshalBson(buf *bytes2.ChunkedWriter, key strin
|
|||
(*queryResult.Session).MarshalBson(buf, "Session")
|
||||
}
|
||||
bson.EncodeString(buf, "Error", queryResult.Error)
|
||||
// *mproto.RPCError
|
||||
if queryResult.Err == nil {
|
||||
bson.EncodePrefix(buf, bson.Null, "Err")
|
||||
} else {
|
||||
(*queryResult.Err).MarshalBson(buf, "Err")
|
||||
}
|
||||
|
||||
lenWriter.Close()
|
||||
}
|
||||
|
@ -65,6 +71,12 @@ func (queryResult *QueryResult) UnmarshalBson(buf *bytes.Buffer, kind byte) {
|
|||
}
|
||||
case "Error":
|
||||
queryResult.Error = bson.DecodeString(buf, kind)
|
||||
case "Err":
|
||||
// *mproto.RPCError
|
||||
if kind != bson.Null {
|
||||
queryResult.Err = new(mproto.RPCError)
|
||||
(*queryResult.Err).UnmarshalBson(buf, kind)
|
||||
}
|
||||
default:
|
||||
bson.Skip(buf, kind)
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче