Commit c3964151 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 8f53b1a6
...@@ -90,7 +90,7 @@ func NeedPy(t testing.TB, modules ...string) { ...@@ -90,7 +90,7 @@ func NeedPy(t testing.TB, modules ...string) {
// ZRawObject represents raw ZODB object state. // ZRawObject represents raw ZODB object state.
type ZRawObject struct { type ZRawObject struct {
Oid zodb.Oid Oid zodb.Oid
Data string // raw serialized zodb data Data []byte // raw serialized zodb data
} }
// ZPyCommitRaw commits new transaction into database @ zurl with raw data specified by objv. // ZPyCommitRaw commits new transaction into database @ zurl with raw data specified by objv.
...@@ -106,7 +106,7 @@ func ZPyCommitRaw(zurl string, at zodb.Tid, objv ...ZRawObject) (_ zodb.Tid, err ...@@ -106,7 +106,7 @@ func ZPyCommitRaw(zurl string, at zodb.Tid, objv ...ZRawObject) (_ zodb.Tid, err
fmt.Fprintf(zin, "extension %q\n", "") fmt.Fprintf(zin, "extension %q\n", "")
for _, obj := range objv { for _, obj := range objv {
fmt.Fprintf(zin, "obj %s %d null:00\n", obj.Oid, len(obj.Data)) fmt.Fprintf(zin, "obj %s %d null:00\n", obj.Oid, len(obj.Data))
zin.WriteString(obj.Data) zin.Write(obj.Data)
zin.WriteString("\n") zin.WriteString("\n")
} }
zin.WriteString("\n") zin.WriteString("\n")
......
...@@ -467,7 +467,7 @@ func (bt *btreeState) PyGetState() interface{} { ...@@ -467,7 +467,7 @@ func (bt *btreeState) PyGetState() interface{} {
// btree with 1 child bucket without oid // btree with 1 child bucket without oid
if len(bt.data) == 1 { if len(bt.data) == 1 {
bucket, ok := bt.data[0].child.(*Bucket) bucket, ok := bt.data[0].child.(*Bucket)
if ok && bucket.POid() == zodb.InvalidOid { // XXX recheck vs "NULL oid" if ok && bucket.POid() == zodb.InvalidOid {
return pickle.Tuple{pickle.Tuple{((*bucketState)(bucket)).PyGetState()}} return pickle.Tuple{pickle.Tuple{((*bucketState)(bucket)).PyGetState()}}
} }
} }
......
...@@ -469,7 +469,7 @@ func (bt *iobtreeState) PyGetState() interface{} { ...@@ -469,7 +469,7 @@ func (bt *iobtreeState) PyGetState() interface{} {
// btree with 1 child bucket without oid // btree with 1 child bucket without oid
if len(bt.data) == 1 { if len(bt.data) == 1 {
bucket, ok := bt.data[0].child.(*IOBucket) bucket, ok := bt.data[0].child.(*IOBucket)
if ok && bucket.POid() == zodb.InvalidOid { // XXX recheck vs "NULL oid" if ok && bucket.POid() == zodb.InvalidOid {
return pickle.Tuple{pickle.Tuple{((*iobucketState)(bucket)).PyGetState()}} return pickle.Tuple{pickle.Tuple{((*iobucketState)(bucket)).PyGetState()}}
} }
} }
......
...@@ -469,7 +469,7 @@ func (bt *lobtreeState) PyGetState() interface{} { ...@@ -469,7 +469,7 @@ func (bt *lobtreeState) PyGetState() interface{} {
// btree with 1 child bucket without oid // btree with 1 child bucket without oid
if len(bt.data) == 1 { if len(bt.data) == 1 {
bucket, ok := bt.data[0].child.(*LOBucket) bucket, ok := bt.data[0].child.(*LOBucket)
if ok && bucket.POid() == zodb.InvalidOid { // XXX recheck vs "NULL oid" if ok && bucket.POid() == zodb.InvalidOid {
return pickle.Tuple{pickle.Tuple{((*lobucketState)(bucket)).PyGetState()}} return pickle.Tuple{pickle.Tuple{((*lobucketState)(bucket)).PyGetState()}}
} }
} }
......
...@@ -27,18 +27,23 @@ import ( ...@@ -27,18 +27,23 @@ import (
_ "lab.nexedi.com/kirr/neo/go/zodb/wks" _ "lab.nexedi.com/kirr/neo/go/zodb/wks"
) )
// import at runtime few things into zodb, that zodb cannot import itself due to cyclic dependency. // import at runtime few things into zodb tests, that zodb cannot import itself
// due to cyclic dependency.
func init() { func init() {
zodb.ZPyCommit = ZPyCommit zodb.ZPyCommit = ZPyCommit
} }
// ZPyCommit commits new transaction with specified objects.
//
// The objects need to be alive, but do not need to be marked as changed.
// The commit is performed via zodb/py.
func ZPyCommit(zurl string, at zodb.Tid, objv ...zodb.IPersistent) (zodb.Tid, error) { func ZPyCommit(zurl string, at zodb.Tid, objv ...zodb.IPersistent) (zodb.Tid, error) {
var rawobjv []xtesting.ZRawObject // raw zodb objects data to commit var rawobjv []xtesting.ZRawObject // raw zodb objects data to commit
for _, obj := range objv { for _, obj := range objv {
rawobj := xtesting.ZRawObject{ rawobj := xtesting.ZRawObject{
Oid: obj.POid(), Oid: obj.POid(),
Data: string(zodb.PSerialize(obj).XData()), Data: zodb.PSerialize(obj).XData(), // not releasing buf, but its ok
} }
rawobjv = append(rawobjv, rawobj) rawobjv = append(rawobjv, rawobj)
} }
......
...@@ -116,8 +116,10 @@ type Stateful interface { ...@@ -116,8 +116,10 @@ type Stateful interface {
// GetState should return state of the in-RAM object as raw data. // GetState should return state of the in-RAM object as raw data.
// //
// XXX called only when state is not dropped. // GetState is called only by persistent machinery and only when object
// XXX buf ownership. // has its state - in other words only on non-ghost objects.
//
// XXX buf ownership?
GetState() *mem.Buf GetState() *mem.Buf
} }
...@@ -125,8 +127,11 @@ type Stateful interface { ...@@ -125,8 +127,11 @@ type Stateful interface {
// pSerialize implements IPersistent. // pSerialize implements IPersistent.
func (obj *Persistent) pSerialize() *mem.Buf { func (obj *Persistent) pSerialize() *mem.Buf {
// XXX locking obj.mu.Lock()
// XXX panic on state == GHOST defer obj.mu.Unlock()
if obj.state == GHOST {
panic(obj.badf("serialize: ghost object"))
}
switch istate := obj.istate().(type) { switch istate := obj.istate().(type) {
case Stateful: case Stateful:
......
...@@ -100,14 +100,15 @@ type IPersistent interface { ...@@ -100,14 +100,15 @@ type IPersistent interface {
// XXX probably don't need this. // XXX probably don't need this.
//PState() ObjectState // in-RAM object state. //PState() ObjectState // in-RAM object state.
// XXX move vvv -> iPersistent? // XXX move vvv -> iPersistent? (-> into persistent.go)
// XXX do we need to put vvv into IPersistent at all?
// pSerialize returns object in serialized form to be saved in the database. // pSerialize returns object in serialized form to be saved in the database.
// //
// pSerialize is non-public method that is exposed and used only by ZODB internally. // pSerialize is non-public method that is exposed and used only by ZODB internally.
// pSerialize is called only on non-ghost objects.
// //
// XXX more text. // XXX more text.
// XXX when called? invariants?
pSerialize() *mem.Buf pSerialize() *mem.Buf
} }
......
...@@ -40,7 +40,9 @@ type PyStateful interface { ...@@ -40,7 +40,9 @@ type PyStateful interface {
// PyGetState should return state of the in-RAM object as Python data. // PyGetState should return state of the in-RAM object as Python data.
// Analog of __getstate__() in Python. // Analog of __getstate__() in Python.
// //
// XXX called only when state is not dropped. // PyGetState is called only by persistent machinery and only when
// object has its state - in other words only on non-ghost objects.
//
// XXX state ownership? // XXX state ownership?
PyGetState() interface{} PyGetState() interface{}
} }
......
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