Commit ae2044cd authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent db65b87d
......@@ -75,7 +75,7 @@ type ZBTree struct {
//
// It loads intermediate BTree nodes from database on demand as needed.
func (t *ZBTree) Get(ctx context.Context, key KEY) (_ interface{}, _ bool, err error) {
defer xerr.Contextf(&err, "btree(%s): get %s") // XXX + url?
defer xerr.Contextf(&err, "btree(%s): get %s", t.POid(), key) // XXX + url?
err = t.PActivate(ctx)
if err != nil {
return nil, false, err
......@@ -115,7 +115,7 @@ func (t *ZBTree) Get(ctx context.Context, key KEY) (_ interface{}, _ bool, err e
// Get searches Bucket by key.
func (b *ZBucket) Get(ctx context.Context, key KEY) (_ interface{}, _ bool, err error) {
defer xerr.Contextf(&err, "bucket(%s): get %s") // XXX + url?
defer xerr.Contextf(&err, "bucket(%s): get %s", b.POid(), key) // XXX + url?
err = b.PActivate(ctx)
if err != nil {
return nil, false, err
......@@ -249,13 +249,8 @@ func (b *ZBucket) PySetState(pystate interface{}) error {
// ---- register classes to ZODB ----
func bucketNew(pyobj *pyObject) PyObject {
return &ZBucket{pyObject: pyobj}
}
func btreeNew(pyobj *pyObject) PyObject {
return &ZBTree{pyObject: pyobj}
}
func bucketNew(pyobj *pyObject) PyObject { return &ZBucket{pyObject: pyobj} }
func btreeNew(pyobj *pyObject) PyObject { return &ZBTree{pyObject: pyobj} }
func init() {
registerPyClass("zodb.BTree.LOBucket", bucketNew)
......
......@@ -25,73 +25,89 @@ import (
//"context"
//"lab.nexedi.com/kirr/neo/go/zodb"
//pickle "github.com/kisielk/og-rek"
pickle "github.com/kisielk/og-rek"
)
// module of Wendelin ZODB py objects
const zwendelin = "wendelin.bigfile.file_zodb"
// // loadZBlk0 loads data stored in ZBlk0 object
// func loadZBlk0(ctx context.Context, oid zodb.Oid) (data []byte, err error) {
// ...
// }
// ---- ZBlk0 ----
// ZBlk0 mimics ZBlk0 from python.
type ZBlk0 struct {
*pyObject
// XXX start from loading ZBigFile btree
blkdata string
}
// ZBigFile mimics ZBigFile from python.
type ZBigFile struct {
*pyObject
func (zb *ZBlk0) DropState() {
zb.blkdata = ""
}
blksize int64
blktab *ZBTree // LOBtree{} blk -> ZBlk*(blkdata)
func (zb *ZBlk0) PySetState(pystate interface{}) error {
blkdata, ok := pystate.(string)
if !ok {
// XXX
}
zb.blkdata = blkdata
return nil
}
// module of Wendelin ZODB py objects
const zwendelin = "wendelin.bigfile.file_zodb"
// ---- ZBlk1 ---
/*
// loadZBigFile loads ZBigFile object from specified oid.
func (conn *zpyconn) loadZBigFile(ctx context.Context, oid zodb.Oid) (*ZBigFile, error) {
// ZBigFile
// .blksize xint
// .blktab LOBtree{} blk -> ZBlk*(blkdata)
// ZData mimics ZData from python.
type ZData struct {
*pyObject
pyobj, err := zpyconn.Load(ctx, oid)
if err != nil {
return nil, err // XXX errctx
}
data string
}
if pyobj.PyClass.Path() != zwendelin + ".ZBigFile" {
return nil, XXX_class_missmatch // XXX
}
func (zd *ZData) DropState() {
zd.data = ""
}
// decode pystate
t, ok := pyobj.PyState.(pickle.Tuple)
if !ok || len(t) != 2 {
// XXX expected (.blksize, blktab)
func (zd *ZData) PySetState(pystate interface{}) error {
data, ok := pystate.(string)
if !ok {
// XXX
}
blksize, ok = pickletools.Xint64(t[0])
// XXX if !ok
zd.data = data
return nil
}
tabref, ok := t[1].(pickle.Ref)
// XXX if !ok
// ZBlk1 mimics ZBlk1 from python.
type ZBlk1 struct {
*pyObject
t, ok = tabref.Pid.(pickle.Tuple)
if !ok || len(t) != 2 {
// XXX expected (oid, LOBTree)
}
chunktab *ZBTree // {} offset -> ZData(chunk)
}
taboid, err = decodeOID(t[0])
// XXX err
func (zb *ZBlk1) DropState() {
zb.chunktab = nil
}
lobtreeClass := pickle.Class{Module: "BTrees.LOBTree", Name: "LOBTree"}
if t[1] != lobtreeClass {
// XXX err
func (zb *ZBlk1) PySetState(pystate interface{}) error {
chunktab, ok := pystate.(*ZBTree)
if !ok {
// XXX
}
// XXX ok
zb.chunktab = chunktab
return nil
}
// ----------------------------------------
// ZBigFile mimics ZBigFile from python.
type ZBigFile struct {
*pyObject
blksize int64
blktab *ZBTree // LOBtree{} blk -> ZBlk*(blkdata)
}
*/
// DropState implements Stateful.
......@@ -100,70 +116,46 @@ func (bf *ZBigFile) DropState() {
bf.blktab = nil
}
// PySetState implements PyStateful.
func (bf *ZBigFile) PySetState(pystate interface{}) (err error) {
panic("TODO")
/* XXX reenable (pickletools)
if bf.blktab != nil {
return nil
}
err = bf.pyObject.PActivate(ctx)
if err != nil {
return err
}
defer func() {
if err != nil {
// decoding went wrong
}
}()
// ZBigFile
// .blksize xint
// .blktab LOBtree{} blk -> ZBlk*(blkdata)
//
// state: (.blksize, .blktab)
// decode pystate
t, ok := bf.pyObject.pystate.(pickle.Tuple)
t, ok := pystate.(pickle.Tuple)
if !ok || len(t) != 2 {
// XXX expected (.blksize, blktab)
// XXX
}
blksize, ok := pickletools.Xint64(t[0])
// XXX if !ok
// blksize, ok := pickletools.Xint64(t[0]) // XXX reenable (pickletools)
if !ok {
// XXX
}
blktab, ok := t[1].(*ZBTree)
// XXX if !ok
if !ok {
// XXX
}
bf.blksize = blksize
bf.blksize = 0 // XXX blksize
bf.blktab = blktab
return nil
*/
}
// XXX -> newGhost
/*
tabref, ok := t[1].(pickle.Ref)
// XXX if !ok
t, ok = tabref.Pid.(pickle.Tuple)
if !ok || len(t) != 2 {
// XXX expected (oid, LOBTree)
}
taboid, err = decodeOID(t[0])
// XXX err
lobtreeClass := pickle.Class{Module: "BTrees.LOBTree", Name: "LOBTree"}
if t[1] != lobtreeClass {
// XXX err
}
*/
// ----------------------------------------
func zbigfileNew(pyobj *pyObject) PyObject {
return &ZBigFile{pyObject: pyobj}
}
func zblk0New(base *pyObject) PyObject { return &ZBlk0{pyObject: base} }
func zblk1New(base *pyObject) PyObject { return &ZBlk1{pyObject: base} }
func zdataNew(base *pyObject) PyObject { return &ZData{pyObject: base} }
func zbigfileNew(pyobj *pyObject) PyObject { return &ZBigFile{pyObject: pyobj} }
func init() {
registerPyClass(zwendelin + ".ZBlk", zblk0New)
registerPyClass(zwendelin + ".ZBlk0", zblk0New)
registerPyClass(zwendelin + ".ZBlk1", zblk1New)
registerPyClass(zwendelin + ".ZData", zdataNew)
registerPyClass(zwendelin + ".ZBigFile", zbigfileNew)
}
......@@ -102,6 +102,7 @@ var pyClassTab = make(map[string]pyClassNewFunc)
// must be called from global init().
func registerPyClass(pyClassPath string, classNew pyClassNewFunc) {
pyClassTab[pyClassPath] = classNew
// XXX + register so that zodb.PyData decode handles pyClassPath
}
// newGhost creates new ghost object corresponding to pyclass and oid.
......
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