Commit f8696942 authored by Kirill Smelkov's avatar Kirill Smelkov

go/zodb/zeo: Load: loadBefore RPC can return None to indicate non-existing object

Before this patch and with updated DrvTestLoad (see previous patch) it was failing as:

--- FAIL: TestLoad (0.52s)
    --- FAIL: TestLoad/py/msgpack=false (0.25s)
        xtesting.go:306: load 0285cbac258bf265:0000000000000000: returned err unexpected:
            have: /tmp/zeo535364855/1.fs.zeosock: load 0285cbac258bf265:0000000000000000: /tmp/zeo535364855/1.fs.zeosock: call loadBefore: unexpected reply: got ogórek.None{}; expect 3-tuple
            want: /tmp/zeo535364855/1.fs.zeosock: load 0285cbac258bf265:0000000000000000: 0000000000000000: no such object
        xtesting.go:306: load 0285cbac3d0369e5:0000000000000001: returned err unexpected:
            have: /tmp/zeo535364855/1.fs.zeosock: load 0285cbac3d0369e5:0000000000000001: /tmp/zeo535364855/1.fs.zeosock: call loadBefore: unexpected reply: got ogórek.None{}; expect 3-tuple
            want: /tmp/zeo535364855/1.fs.zeosock: load 0285cbac3d0369e5:0000000000000001: 0000000000000001: no such object
        xtesting.go:306: load 0285cbac41b4e832:0000000000000002: returned err unexpected:
            have: /tmp/zeo535364855/1.fs.zeosock: load 0285cbac41b4e832:0000000000000002: /tmp/zeo535364855/1.fs.zeosock: call loadBefore: unexpected reply: got ogórek.None{}; expect 3-tuple
            want: /tmp/zeo535364855/1.fs.zeosock: load 0285cbac41b4e832:0000000000000002: 0000000000000002: no such object
        xtesting.go:306: load 0285cbac4666667f:0000000000000003: returned err unexpected:
            have: /tmp/zeo535364855/1.fs.zeosock: load 0285cbac4666667f:0000000000000003: /tmp/zeo535364855/1.fs.zeosock: call loadBefore: unexpected reply: got ogórek.None{}; expect 3-tuple
            want: /tmp/zeo535364855/1.fs.zeosock: load 0285cbac4666667f:0000000000000003: 0000000000000003: no such object
        xtesting.go:306: load 0285cbac4fc96318:0000000000000004: returned err unexpected:
            have: /tmp/zeo535364855/1.fs.zeosock: load 0285cbac4fc96318:0000000000000004: /tmp/zeo535364855/1.fs.zeosock: call loadBefore: unexpected reply: got ogórek.None{}; expect 3-tuple
            want: /tmp/zeo535364855/1.fs.zeosock: load 0285cbac4fc96318:0000000000000004: 0000000000000004: no such object
        xtesting.go:306: load 0285cbac547ae165:0000000000000005: returned err unexpected:
            have: /tmp/zeo535364855/1.fs.zeosock: load 0285cbac547ae165:0000000000000005: /tmp/zeo535364855/1.fs.zeosock: call loadBefore: unexpected reply: got ogórek.None{}; expect 3-tuple
            want: /tmp/zeo535364855/1.fs.zeosock: load 0285cbac547ae165:0000000000000005: 0000000000000005: no such object
        xtesting.go:306: load 0285cbac628f5c4b:0000000000000006: returned err unexpected:
            have: /tmp/zeo535364855/1.fs.zeosock: load 0285cbac628f5c4b:0000000000000006: /tmp/zeo535364855/1.fs.zeosock: call loadBefore: unexpected reply: got ogórek.None{}; expect 3-tuple
            want: /tmp/zeo535364855/1.fs.zeosock: load 0285cbac628f5c4b:0000000000000006: 0000000000000006: no such object
        xtesting.go:306: load 0285cbaca444447f:0000000000000007: returned err unexpected:
            have: /tmp/zeo535364855/1.fs.zeosock: load 0285cbaca444447f:0000000000000007: /tmp/zeo535364855/1.fs.zeosock: call loadBefore: unexpected reply: got ogórek.None{}; expect 3-tuple
            want: /tmp/zeo535364855/1.fs.zeosock: load 0285cbaca444447f:0000000000000007: 0000000000000007: no such object
        xtesting.go:306: load 0285cbacbbbbbbff:0000000000000008: returned err unexpected:
            have: /tmp/zeo535364855/1.fs.zeosock: load 0285cbacbbbbbbff:0000000000000008: /tmp/zeo535364855/1.fs.zeosock: call loadBefore: unexpected reply: got ogórek.None{}; expect 3-tuple
            want: /tmp/zeo535364855/1.fs.zeosock: load 0285cbacbbbbbbff:0000000000000008: 0000000000000008: no such object
        xtesting.go:306: load 0285cbad80da7498:0000000000000009: returned err unexpected:
            have: /tmp/zeo535364855/1.fs.zeosock: load 0285cbad80da7498:0000000000000009: /tmp/zeo535364855/1.fs.zeosock: call loadBefore: unexpected reply: got ogórek.None{}; expect 3-tuple
            want: /tmp/zeo535364855/1.fs.zeosock: load 0285cbad80da7498:0000000000000009: 0000000000000009: no such object
    --- FAIL: TestLoad/py/msgpack=true (0.26s)
        xtesting.go:306: load 0285cbac258bf265:0000000000000000: returned err unexpected:
            have: /tmp/zeo794664426/1.fs.zeosock: load 0285cbac258bf265:0000000000000000: /tmp/zeo794664426/1.fs.zeosock: call loadBefore: zlink is closed
            want: /tmp/zeo794664426/1.fs.zeosock: load 0285cbac258bf265:0000000000000000: 0000000000000000: no such object
        xtesting.go:306: load 0285cbac3d0369e5:0000000000000001: returned err unexpected:
            have: /tmp/zeo794664426/1.fs.zeosock: load 0285cbac3d0369e5:0000000000000001: /tmp/zeo794664426/1.fs.zeosock: call loadBefore: zlink is closed
            want: /tmp/zeo794664426/1.fs.zeosock: load 0285cbac3d0369e5:0000000000000001: 0000000000000001: no such object
        xtesting.go:306: load 0285cbac41b4e832:0000000000000002: returned err unexpected:
            have: /tmp/zeo794664426/1.fs.zeosock: load 0285cbac41b4e832:0000000000000002: /tmp/zeo794664426/1.fs.zeosock: call loadBefore: zlink is closed
            want: /tmp/zeo794664426/1.fs.zeosock: load 0285cbac41b4e832:0000000000000002: 0000000000000002: no such object
        xtesting.go:306: load 0285cbac4666667f:0000000000000003: returned err unexpected:
            have: /tmp/zeo794664426/1.fs.zeosock: load 0285cbac4666667f:0000000000000003: /tmp/zeo794664426/1.fs.zeosock: call loadBefore: zlink is closed
            want: /tmp/zeo794664426/1.fs.zeosock: load 0285cbac4666667f:0000000000000003: 0000000000000003: no such object
        xtesting.go:306: load 0285cbac4fc96318:0000000000000004: returned err unexpected:
            have: /tmp/zeo794664426/1.fs.zeosock: load 0285cbac4fc96318:0000000000000004: /tmp/zeo794664426/1.fs.zeosock: call loadBefore: zlink is closed
            want: /tmp/zeo794664426/1.fs.zeosock: load 0285cbac4fc96318:0000000000000004: 0000000000000004: no such object
        xtesting.go:306: load 0285cbac547ae165:0000000000000005: returned err unexpected:
            have: /tmp/zeo794664426/1.fs.zeosock: load 0285cbac547ae165:0000000000000005: /tmp/zeo794664426/1.fs.zeosock: call loadBefore: zlink is closed
            want: /tmp/zeo794664426/1.fs.zeosock: load 0285cbac547ae165:0000000000000005: 0000000000000005: no such object
        xtesting.go:306: load 0285cbac628f5c4b:0000000000000006: returned err unexpected:
            have: /tmp/zeo794664426/1.fs.zeosock: load 0285cbac628f5c4b:0000000000000006: /tmp/zeo794664426/1.fs.zeosock: call loadBefore: zlink is closed
            want: /tmp/zeo794664426/1.fs.zeosock: load 0285cbac628f5c4b:0000000000000006: 0000000000000006: no such object
        xtesting.go:306: load 0285cbaca444447f:0000000000000007: returned err unexpected:
            have: /tmp/zeo794664426/1.fs.zeosock: load 0285cbaca444447f:0000000000000007: /tmp/zeo794664426/1.fs.zeosock: call loadBefore: zlink is closed
            want: /tmp/zeo794664426/1.fs.zeosock: load 0285cbaca444447f:0000000000000007: 0000000000000007: no such object
        xtesting.go:306: load 0285cbacbbbbbbff:0000000000000008: returned err unexpected:
            have: /tmp/zeo794664426/1.fs.zeosock: load 0285cbacbbbbbbff:0000000000000008: /tmp/zeo794664426/1.fs.zeosock: call loadBefore: zlink is closed
            want: /tmp/zeo794664426/1.fs.zeosock: load 0285cbacbbbbbbff:0000000000000008: 0000000000000008: no such object
        xtesting.go:306: load 0285cbad80da7498:0000000000000009: returned err unexpected:
            have: /tmp/zeo794664426/1.fs.zeosock: load 0285cbad80da7498:0000000000000009: /tmp/zeo794664426/1.fs.zeosock: call loadBefore: zlink is closed
            want: /tmp/zeo794664426/1.fs.zeosock: load 0285cbad80da7498:0000000000000009: 0000000000000009: no such object
parent 4acadb94
...@@ -421,3 +421,37 @@ func (e encoding) asString(xs interface{}) (string, bool) { ...@@ -421,3 +421,37 @@ func (e encoding) asString(xs interface{}) (string, bool) {
} }
} }
} }
// None returns object that represents None in encoding e.
func (e encoding) None() interface{} {
switch e {
default:
panic("bug")
// pickle: None
case 'Z':
return pickle.None{}
// msgpack: nil
case 'M':
return nil
}
}
// isNone verifies whether object corresponds to None encoded via encoding e.
func (e encoding) isNone(xv interface{}) bool {
switch e {
default:
panic("bug")
case 'Z':
// pickle: None
_, ok := xv.(pickle.None)
return ok
// msgpack: nil
case 'M':
return (xv == nil)
}
}
...@@ -98,9 +98,12 @@ func (z *zeo) Load(ctx context.Context, xid zodb.Xid) (buf *mem.Buf, serial zodb ...@@ -98,9 +98,12 @@ func (z *zeo) Load(ctx context.Context, xid zodb.Xid) (buf *mem.Buf, serial zodb
} }
// (data, serial, next_serial | None) // (data, serial, next_serial | None)
if enc.isNone(xres) {
return nil, 0, &zodb.NoObjectError{Oid: xid.Oid}
}
res, ok := enc.asTuple(xres) res, ok := enc.asTuple(xres)
if !ok || len(res) != 3 { if !ok || len(res) != 3 {
return nil, 0, rpc.ereplyf("got %#v; expect 3-tuple", xres) return nil, 0, rpc.ereplyf("got %#v; expect 3-tuple | None", xres)
} }
data, ok1 := enc.asBytes(res[0]) data, ok1 := enc.asBytes(res[0])
......
...@@ -132,7 +132,7 @@ func (zl *zLink) shutdown(err error) { ...@@ -132,7 +132,7 @@ func (zl *zLink) shutdown(err error) {
zl.callMu.Unlock() zl.callMu.Unlock()
for _, rxc := range callTab { for _, rxc := range callTab {
rxc <- msg{arg: nil} // notify link was closed XXX ok? or err explicitly? close(rxc) // notify link was closed
} }
}) })
} }
...@@ -276,14 +276,14 @@ func (zl *zLink) Call(ctx context.Context, method string, argv ...interface{}) ( ...@@ -276,14 +276,14 @@ func (zl *zLink) Call(ctx context.Context, method string, argv ...interface{}) (
case <-ctx.Done(): case <-ctx.Done():
return msg{}, ctx.Err() return msg{}, ctx.Err()
case reply = <-rxc: case reply, ok := <-rxc:
if reply.arg == nil { if !ok {
// we were woken up because of shutdown // we were woken up because of shutdown
return msg{}, errLinkClosed return msg{}, errLinkClosed
} }
}
return reply, nil return reply, nil
}
} }
// reply sends reply to a call received with msgid. // reply sends reply to a call received with msgid.
......
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