Commit a0db1dd4 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 6368ccd4
...@@ -177,8 +177,6 @@ func (b *bucketState) DropState() { ...@@ -177,8 +177,6 @@ func (b *bucketState) DropState() {
// PySetState implements PyStateful to set bucket data from pystate. // PySetState implements PyStateful to set bucket data from pystate.
func (b *bucketState) PySetState(pystate interface{}) (err error) { func (b *bucketState) PySetState(pystate interface{}) (err error) {
defer xerr.Contextf(&err, "bucket(%s): setstate", b.POid())
t, ok := pystate.(pickle.Tuple) t, ok := pystate.(pickle.Tuple)
if !ok { if !ok {
return fmt.Errorf("top: expect (...); got %T", pystate) return fmt.Errorf("top: expect (...); got %T", pystate)
...@@ -264,8 +262,6 @@ func (t *btreeState) DropState() { ...@@ -264,8 +262,6 @@ func (t *btreeState) DropState() {
// PySetState implements zodb.PyStateful to set btree data from pystate. // PySetState implements zodb.PyStateful to set btree data from pystate.
func (bt *btreeState) PySetState(pystate interface{}) (err error) { func (bt *btreeState) PySetState(pystate interface{}) (err error) {
defer xerr.Contextf(&err, "btree(%s): setstate", bt.POid())
// empty btree // empty btree
if _, ok := pystate.(pickle.None); ok { if _, ok := pystate.(pickle.None); ok {
bt.firstbucket = nil bt.firstbucket = nil
......
...@@ -21,6 +21,7 @@ import ( ...@@ -21,6 +21,7 @@ import (
"sync" "sync"
"lab.nexedi.com/kirr/go123/mem" "lab.nexedi.com/kirr/go123/mem"
"lab.nexedi.com/kirr/go123/xerr"
) )
// IPersistent is the interface that every in-RAM object representing any database object implements. // IPersistent is the interface that every in-RAM object representing any database object implements.
...@@ -187,6 +188,9 @@ type Stateful interface { ...@@ -187,6 +188,9 @@ type Stateful interface {
// //
// state ownership is not passed to SetState, so if state needs to be // state ownership is not passed to SetState, so if state needs to be
// retained after SetState returns it needs to be incref'ed. // retained after SetState returns it needs to be incref'ed.
//
// The error returned does not need to have object/setstate prefix -
// persistent machinery is adding such prefix automatically.
SetState(state *mem.Buf) error SetState(state *mem.Buf) error
// GetState should return state of the in-RAM object as raw data. // GetState should return state of the in-RAM object as raw data.
...@@ -240,10 +244,13 @@ func (obj *Persistent) PActivate(ctx context.Context) (err error) { ...@@ -240,10 +244,13 @@ func (obj *Persistent) PActivate(ctx context.Context) (err error) {
if err == nil { if err == nil {
switch istate := obj.istate().(type) { switch istate := obj.istate().(type) {
case Stateful: case Stateful:
err = istate.SetState(state) // XXX err ctx err = istate.SetState(state)
xerr.Contextf(&err, "%s(%s): setstate", obj.zclass.class, obj.oid)
case PyStateful: case PyStateful:
err = pySetState(istate, obj.zclass.class, state, obj.jar) // XXX err ctx err = pySetState(istate, obj.zclass.class, state, obj.jar)
xerr.Contextf(&err, "%s(%s): pysetstate", obj.zclass.class, obj.oid)
default: default:
panic("!stateful instance") panic("!stateful instance")
......
...@@ -28,7 +28,11 @@ import ( ...@@ -28,7 +28,11 @@ import (
// exchanged as Python data. // exchanged as Python data.
type PyStateful interface { type PyStateful interface {
// PySetState should set state of the in-RAM object from Python data. // PySetState should set state of the in-RAM object from Python data.
// Analog of __setstate__() in Python. //
// It is analog of __setstate__() in Python.
//
// The error returned does not need to have object/setstate prefix -
// persistent machinery is adding such prefix automatically.
PySetState(pystate interface{}) error PySetState(pystate interface{}) error
// PyGetState should return state of the in-RAM object as Python data. // PyGetState should return state of the in-RAM object as Python data.
...@@ -44,7 +48,7 @@ type PyStateful interface { ...@@ -44,7 +48,7 @@ type PyStateful interface {
func pySetState(obj PyStateful, objClass string, state *mem.Buf, jar *Connection) error { func pySetState(obj PyStateful, objClass string, state *mem.Buf, jar *Connection) error {
pyclass, pystate, err := PyData(state.Data).decode(jar) pyclass, pystate, err := PyData(state.Data).decode(jar)
if err != nil { if err != nil {
return err // XXX err ctx return err
} }
class := pyclassPath(pyclass) class := pyclassPath(pyclass)
...@@ -52,10 +56,10 @@ func pySetState(obj PyStateful, objClass string, state *mem.Buf, jar *Connection ...@@ -52,10 +56,10 @@ func pySetState(obj PyStateful, objClass string, state *mem.Buf, jar *Connection
if class != objClass { if class != objClass {
// complain that pyclass changed // complain that pyclass changed
// (both ref and object data use pyclass so it indeed can be different) // (both ref and object data use pyclass so it indeed can be different)
return &wrongClassError{want: objClass, have: class} // XXX + err ctx return &wrongClassError{want: objClass, have: class}
} }
return obj.PySetState(pystate) // XXX err ctx = ok? return obj.PySetState(pystate)
} }
// TODO pyGetState // TODO pyGetState
......
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