Commit bf816c40 authored by Kirill Smelkov's avatar Kirill Smelkov

wcfs: zdata: Fix loading ZBlk data saved on py3

Previously TestZBlk was xfailing as e.g.

        --- FAIL: TestZBlk/py3_pickle3 (0.00s)
    panic: ZBlk0(0000000000000002): loadBlkData: wendelin.bigfile.file_zodb.ZBlk0(0000000000000002): activate: pysetstate: expect str; got ogórek.Bytes [recovered]
            panic: ZBlk0(0000000000000002): loadBlkData: wendelin.bigfile.file_zodb.ZBlk0(0000000000000002): activate: pysetstate: expect str; got ogórek.Bytes

because on py3 ZBlk data is saved as bytes while zblk.go code was trying
to decode it as bytestring (str from py2).

-> Fix that by adjusting ZBlk/go to follow py3 model with ZBlk data being
   considered to be bytes but also accepting bytestr from py2 for that.

Now on go side loading ZBlk works for all py2_pickle{1,2,3} and
py3_pickle3 data.
parent f237dc35
...@@ -29,7 +29,7 @@ package zdata ...@@ -29,7 +29,7 @@ package zdata
// .blktab LOBtree{} blk -> ZBlk*(blkdata) // .blktab LOBtree{} blk -> ZBlk*(blkdata)
// //
// ZBlk0 (aliased as ZBlk) // ZBlk0 (aliased as ZBlk)
// str with trailing '\0' removed. // bytes|bytestr with trailing '\0' removed.
// //
// ZBlk1 // ZBlk1
// .chunktab IOBtree{} offset -> ZData(chunk) // .chunktab IOBtree{} offset -> ZData(chunk)
...@@ -79,7 +79,7 @@ type ZBlk0 struct { ...@@ -79,7 +79,7 @@ type ZBlk0 struct {
zodb.Persistent zodb.Persistent
// NOTE py source uses bytes(buf) but on python2 it still results in str // NOTE py source uses bytes(buf) but on python2 it still results in str
blkdata pickle.ByteString blkdata pickle.Bytes
} }
type zBlk0State ZBlk0 // hide state methods from public API type zBlk0State ZBlk0 // hide state methods from public API
...@@ -96,9 +96,9 @@ func (zb *zBlk0State) PyGetState() interface{} { ...@@ -96,9 +96,9 @@ func (zb *zBlk0State) PyGetState() interface{} {
// PySetState implements zodb.PyStateful. // PySetState implements zodb.PyStateful.
func (zb *zBlk0State) PySetState(pystate interface{}) error { func (zb *zBlk0State) PySetState(pystate interface{}) error {
blkdata, ok := pystate.(pickle.ByteString) blkdata, err := pickle.AsBytes(pystate)
if !ok { if err != nil {
return fmt.Errorf("expect str; got %s", xzodb.TypeOf(pystate)) return err
} }
zb.blkdata = blkdata zb.blkdata = blkdata
...@@ -125,7 +125,7 @@ type ZData struct { ...@@ -125,7 +125,7 @@ type ZData struct {
zodb.Persistent zodb.Persistent
// NOTE py source uses bytes(buf) but on python2 it still results in str // NOTE py source uses bytes(buf) but on python2 it still results in str
data pickle.ByteString data pickle.Bytes
} }
type zDataState ZData // hide state methods from public API type zDataState ZData // hide state methods from public API
...@@ -142,9 +142,9 @@ func (zd *zDataState) PyGetState() interface{} { ...@@ -142,9 +142,9 @@ func (zd *zDataState) PyGetState() interface{} {
// PySetState implements zodb.PyStateful. // PySetState implements zodb.PyStateful.
func (zd *zDataState) PySetState(pystate interface{}) error { func (zd *zDataState) PySetState(pystate interface{}) error {
data, ok := pystate.(pickle.ByteString) data, err := pickle.AsBytes(pystate)
if !ok { if err != nil {
return fmt.Errorf("expect str; got %s", xzodb.TypeOf(pystate)) return err
} }
zd.data = data zd.data = data
......
...@@ -67,9 +67,6 @@ func TestZBlk(t *testing.T) { ...@@ -67,9 +67,6 @@ func TestZBlk(t *testing.T) {
for _, zkind := range zkindv { for _, zkind := range zkindv {
z := zblkTestDataRegistry[zkind] z := zblkTestDataRegistry[zkind]
t.Run(zkind, func(t *testing.T) { t.Run(zkind, func(t *testing.T) {
if zkind == "py3_pickle3" {
t.Skip("xfail")
}
_TestZBlk(t, z) _TestZBlk(t, z)
}) })
} }
......
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