Commit 03e0cdef authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent e9b424fc
...@@ -388,6 +388,7 @@ func (c *Client) LastTid(ctx context.Context) (_ zodb.Tid, err error) { ...@@ -388,6 +388,7 @@ func (c *Client) LastTid(ctx context.Context) (_ zodb.Tid, err error) {
reply := proto.AnswerLastTransaction{} reply := proto.AnswerLastTransaction{}
err = mlink.Ask1(&proto.LastTransaction{}, &reply) // XXX Ask += ctx err = mlink.Ask1(&proto.LastTransaction{}, &reply) // XXX Ask += ctx
if err != nil { if err != nil {
// XXX ZODBErrDecode?
return 0, err // XXX err ctx return 0, err // XXX err ctx
} }
return reply.Tid, nil return reply.Tid, nil
...@@ -449,6 +450,9 @@ func (c *Client) _Load(ctx context.Context, xid zodb.Xid) (*mem.Buf, zodb.Tid, e ...@@ -449,6 +450,9 @@ func (c *Client) _Load(ctx context.Context, xid zodb.Xid) (*mem.Buf, zodb.Tid, e
resp := proto.AnswerObject{} resp := proto.AnswerObject{}
err = slink.Ask1(&req, &resp) err = slink.Ask1(&req, &resp)
if err != nil { if err != nil {
if e, ok := err.(*proto.Error); ok {
err = proto.ZODBErrDecode(e)
}
return nil, 0, err // XXX err context return nil, 0, err // XXX err context
} }
......
...@@ -467,7 +467,7 @@ func benchmarkGetObject(b *testing.B, Mnet, Snet, Cnet xnet.Networker, benchit f ...@@ -467,7 +467,7 @@ func benchmarkGetObject(b *testing.B, Mnet, Snet, Cnet xnet.Networker, benchit f
return M.Run(ctx) return M.Run(ctx)
}) })
// determing M serving address XXX better with M api // determining M serving address XXX better with M api
ev := cG.Recv() ev := cG.Recv()
mnode, ok := ev.Event.(*eventNodeTab) mnode, ok := ev.Event.(*eventNodeTab)
if !ok { if !ok {
......
...@@ -1411,12 +1411,14 @@ func (c *Conn) _Expect(pkt *pktBuf, msgv ...proto.Msg) (int, error) { ...@@ -1411,12 +1411,14 @@ func (c *Conn) _Expect(pkt *pktBuf, msgv ...proto.Msg) (int, error) {
return -1, c.err("recv", fmt.Errorf("unexpected message: %v", msgType)) return -1, c.err("recv", fmt.Errorf("unexpected message: %v", msgType))
} }
// Ask sends request and receives response. // Ask sends request and receives a response.
// //
// It expects response to be exactly of resp type and errors otherwise. // It expects response to be either of resp type or proto.Error:
// //
// XXX clarify error semantic (when Error is decoded) // If resp-type message is received, it is decoded inplace and nil is returned.
// XXX do the same as Expect wrt respv ? // If proto.Error message is received, it is returned as error.
//
// Otherwise returned error describes the problem.
func (c *Conn) Ask(req proto.Msg, resp proto.Msg) error { func (c *Conn) Ask(req proto.Msg, resp proto.Msg) error {
err := c.Send(req) err := c.Send(req)
if err != nil { if err != nil {
...@@ -1429,7 +1431,7 @@ func (c *Conn) Ask(req proto.Msg, resp proto.Msg) error { ...@@ -1429,7 +1431,7 @@ func (c *Conn) Ask(req proto.Msg, resp proto.Msg) error {
case 0: case 0:
return nil return nil
case 1: case 1:
return proto.ErrDecode(nerr) return nerr
} }
return err return err
...@@ -1566,7 +1568,7 @@ func (conn *Conn) _Ask1(req proto.Msg, resp proto.Msg) error { ...@@ -1566,7 +1568,7 @@ func (conn *Conn) _Ask1(req proto.Msg, resp proto.Msg) error {
case 0: case 0:
return nil return nil
case 1: case 1:
return proto.ErrDecode(nerr) return nerr
} }
return err return err
......
...@@ -26,15 +26,22 @@ import ( ...@@ -26,15 +26,22 @@ import (
"lab.nexedi.com/kirr/neo/go/zodb" "lab.nexedi.com/kirr/neo/go/zodb"
) )
// XXX name -> zodbErrEncode, zodbErrDecode ?
// XXX should be not in proto/ ? // XXX should be not in proto/ ?
// ErrEncode translates an error into Error packet. // ZODBErrEncode translates a ZODB error into Error packet.
// XXX more text describing relation with zodb errors //
func ErrEncode(err error) *Error { // ZODB errors (e.g. zodb.NoDataError) are specifically encoded, so that on
// receiver side they can be recreated with ErrDecode. If err is zodb.OpError,
// only its inner cause is encoded.
//
// If err is not ZODB error -> it is incoded as "503".
func ZODBErrEncode(err error) *Error {
e, ok := err.(*zodb.OpError)
if ok {
err = e.Err
}
switch err := err.(type) { switch err := err.(type) {
case *Error:
return err
case *zodb.NoDataError: case *zodb.NoDataError:
// XXX abusing message for oid, deletedAt // XXX abusing message for oid, deletedAt
return &Error{ return &Error{
...@@ -52,9 +59,11 @@ func ErrEncode(err error) *Error { ...@@ -52,9 +59,11 @@ func ErrEncode(err error) *Error {
} }
// ErrDecode decodes error from Error packet. // ZODBErrDecode decodes an error from Error packet.
// XXX more text describing relation with zodb errors //
func ErrDecode(e *Error) error { // If it was ZODB error - it is decoded from the packet and returned.
// Otherwise e is returned as is.
func ZODBErrDecode(e *Error) error {
switch e.Code { switch e.Code {
case OID_NOT_FOUND: case OID_NOT_FOUND:
// XXX abusing message for oid, deletedAt // XXX abusing message for oid, deletedAt
......
...@@ -542,8 +542,7 @@ func (stor *Storage) serveClient1(ctx context.Context, req proto.Msg) (resp prot ...@@ -542,8 +542,7 @@ func (stor *Storage) serveClient1(ctx context.Context, req proto.Msg) (resp prot
obj, err := stor.back.Load(ctx, xid) obj, err := stor.back.Load(ctx, xid)
if err != nil { if err != nil {
// translate err to NEO protocol error codes // translate err to NEO protocol error codes
e := err.(*zodb.OpError) // XXX move this to ErrEncode? return proto.ZODBErrEncode(err)
return proto.ErrEncode(e.Err)
} }
// compatibility with py side: // compatibility with py side:
...@@ -562,7 +561,7 @@ func (stor *Storage) serveClient1(ctx context.Context, req proto.Msg) (resp prot ...@@ -562,7 +561,7 @@ func (stor *Storage) serveClient1(ctx context.Context, req proto.Msg) (resp prot
case *proto.LastTransaction: case *proto.LastTransaction:
lastTid, err := stor.back.LastTid(ctx) lastTid, err := stor.back.LastTid(ctx)
if err != nil { if err != nil {
return proto.ErrEncode(err) return proto.ZODBErrEncode(err)
} }
return &proto.AnswerLastTransaction{lastTid} return &proto.AnswerLastTransaction{lastTid}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment