Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
Commits
0979eab2
Commit
0979eab2
authored
Jan 22, 2019
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
1b190e2b
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
193 additions
and
21 deletions
+193
-21
go/zodb/btree/btree.go.in
go/zodb/btree/btree.go.in
+46
-0
go/zodb/btree/btree_test.go
go/zodb/btree/btree_test.go
+2
-0
go/zodb/btree/ziobtree.go
go/zodb/btree/ziobtree.go
+46
-0
go/zodb/btree/zlobtree.go
go/zodb/btree/zlobtree.go
+46
-0
go/zodb/import_test.go
go/zodb/import_test.go
+3
-15
go/zodb/import_x_test.go
go/zodb/import_x_test.go
+36
-0
go/zodb/persistent.go
go/zodb/persistent.go
+4
-1
go/zodb/persistent_test.go
go/zodb/persistent_test.go
+4
-2
go/zodb/zodbpy.go
go/zodb/zodbpy.go
+6
-3
No files found.
go/zodb/btree/btree.go.in
View file @
0979eab2
...
@@ -345,6 +345,22 @@ func (b *bucketState) DropState() {
...
@@ -345,6 +345,22 @@ func (b *bucketState) DropState() {
b.values = nil
b.values = nil
}
}
// PyGetState implements zodb.PyStateful to get bucket data as pystate.
func (b *bucketState) PyGetState() interface{} {
// XXX assert len(b.keys) == len(b.values) ?
t := make(pickle.Tuple, 0, 2*len(b.keys))
for i := range b.keys {
t = append(t, b.keys[i], b.values[i])
}
t = pickle.Tuple{t}
if b.next != nil {
t = append(t, b.next)
}
return t
}
// PySetState implements zodb.PyStateful to set bucket data from pystate.
// PySetState implements zodb.PyStateful to set bucket data from pystate.
func (b *bucketState) PySetState(pystate interface{}) (err error) {
func (b *bucketState) PySetState(pystate interface{}) (err error) {
t, ok := pystate.(pickle.Tuple)
t, ok := pystate.(pickle.Tuple)
...
@@ -440,6 +456,36 @@ func (t *btreeState) DropState() {
...
@@ -440,6 +456,36 @@ func (t *btreeState) DropState() {
t.data = nil
t.data = nil
}
}
// PyGetState implements zodb.PyStateful to get btree data as pystate.
func (bt *btreeState) PyGetState() interface{} {
// empty btree
if len(bt.data) == 0 {
// XXX assert .firstbucket = nil ?
return pickle.None{}
}
// btree with 1 child bucket without oid
if len(bt.data) == 1 {
bucket, ok := bt.data[0].child.(*Bucket)
if ok && bucket.POid() == zodb.InvalidOid { // XXX recheck vs "NULL oid"
return pickle.Tuple{pickle.Tuple{((*bucketState)(bucket)).PyGetState()}}
}
}
// regular btree
t := make(pickle.Tuple, 0, 2*len(bt.data)-1)
for i, entry := range bt.data {
// key[0] is unused and not saved
if i > 0 {
t = append(t, entry.key)
}
t = append(t, entry.child)
}
t = pickle.Tuple{t}
t = append(t, bt.firstbucket)
return t
}
// 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) {
// empty btree
// empty btree
...
...
go/zodb/btree/btree_test.go
View file @
0979eab2
...
@@ -252,6 +252,8 @@ func TestBTree(t *testing.T) {
...
@@ -252,6 +252,8 @@ func TestBTree(t *testing.T) {
return
firstbucket
return
firstbucket
}
}
// XXX verify PyGetState <-> PySetState is the same.
// XXX verify Entryv ?
// XXX verify Entryv ?
// XXX verify FirstBucket / Next ?
// XXX verify FirstBucket / Next ?
...
...
go/zodb/btree/ziobtree.go
View file @
0979eab2
...
@@ -347,6 +347,22 @@ func (b *iobucketState) DropState() {
...
@@ -347,6 +347,22 @@ func (b *iobucketState) DropState() {
b
.
values
=
nil
b
.
values
=
nil
}
}
// PyGetState implements zodb.PyStateful to get bucket data as pystate.
func
(
b
*
iobucketState
)
PyGetState
()
interface
{}
{
// XXX assert len(b.keys) == len(b.values) ?
t
:=
make
(
pickle
.
Tuple
,
0
,
2
*
len
(
b
.
keys
))
for
i
:=
range
b
.
keys
{
t
=
append
(
t
,
b
.
keys
[
i
],
b
.
values
[
i
])
}
t
=
pickle
.
Tuple
{
t
}
if
b
.
next
!=
nil
{
t
=
append
(
t
,
b
.
next
)
}
return
t
}
// PySetState implements zodb.PyStateful to set bucket data from pystate.
// PySetState implements zodb.PyStateful to set bucket data from pystate.
func
(
b
*
iobucketState
)
PySetState
(
pystate
interface
{})
(
err
error
)
{
func
(
b
*
iobucketState
)
PySetState
(
pystate
interface
{})
(
err
error
)
{
t
,
ok
:=
pystate
.
(
pickle
.
Tuple
)
t
,
ok
:=
pystate
.
(
pickle
.
Tuple
)
...
@@ -442,6 +458,36 @@ func (t *iobtreeState) DropState() {
...
@@ -442,6 +458,36 @@ func (t *iobtreeState) DropState() {
t
.
data
=
nil
t
.
data
=
nil
}
}
// PyGetState implements zodb.PyStateful to get btree data as pystate.
func
(
bt
*
iobtreeState
)
PyGetState
()
interface
{}
{
// empty btree
if
len
(
bt
.
data
)
==
0
{
// XXX assert .firstbucket = nil ?
return
pickle
.
None
{}
}
// btree with 1 child bucket without oid
if
len
(
bt
.
data
)
==
1
{
bucket
,
ok
:=
bt
.
data
[
0
]
.
child
.
(
*
IOBucket
)
if
ok
&&
bucket
.
POid
()
==
zodb
.
InvalidOid
{
// XXX recheck vs "NULL oid"
return
pickle
.
Tuple
{
pickle
.
Tuple
{((
*
iobucketState
)(
bucket
))
.
PyGetState
()}}
}
}
// regular btree
t
:=
make
(
pickle
.
Tuple
,
0
,
2
*
len
(
bt
.
data
)
-
1
)
for
i
,
entry
:=
range
bt
.
data
{
// key[0] is unused and not saved
if
i
>
0
{
t
=
append
(
t
,
entry
.
key
)
}
t
=
append
(
t
,
entry
.
child
)
}
t
=
pickle
.
Tuple
{
t
}
t
=
append
(
t
,
bt
.
firstbucket
)
return
t
}
// PySetState implements zodb.PyStateful to set btree data from pystate.
// PySetState implements zodb.PyStateful to set btree data from pystate.
func
(
bt
*
iobtreeState
)
PySetState
(
pystate
interface
{})
(
err
error
)
{
func
(
bt
*
iobtreeState
)
PySetState
(
pystate
interface
{})
(
err
error
)
{
// empty btree
// empty btree
...
...
go/zodb/btree/zlobtree.go
View file @
0979eab2
...
@@ -347,6 +347,22 @@ func (b *lobucketState) DropState() {
...
@@ -347,6 +347,22 @@ func (b *lobucketState) DropState() {
b
.
values
=
nil
b
.
values
=
nil
}
}
// PyGetState implements zodb.PyStateful to get bucket data as pystate.
func
(
b
*
lobucketState
)
PyGetState
()
interface
{}
{
// XXX assert len(b.keys) == len(b.values) ?
t
:=
make
(
pickle
.
Tuple
,
0
,
2
*
len
(
b
.
keys
))
for
i
:=
range
b
.
keys
{
t
=
append
(
t
,
b
.
keys
[
i
],
b
.
values
[
i
])
}
t
=
pickle
.
Tuple
{
t
}
if
b
.
next
!=
nil
{
t
=
append
(
t
,
b
.
next
)
}
return
t
}
// PySetState implements zodb.PyStateful to set bucket data from pystate.
// PySetState implements zodb.PyStateful to set bucket data from pystate.
func
(
b
*
lobucketState
)
PySetState
(
pystate
interface
{})
(
err
error
)
{
func
(
b
*
lobucketState
)
PySetState
(
pystate
interface
{})
(
err
error
)
{
t
,
ok
:=
pystate
.
(
pickle
.
Tuple
)
t
,
ok
:=
pystate
.
(
pickle
.
Tuple
)
...
@@ -442,6 +458,36 @@ func (t *lobtreeState) DropState() {
...
@@ -442,6 +458,36 @@ func (t *lobtreeState) DropState() {
t
.
data
=
nil
t
.
data
=
nil
}
}
// PyGetState implements zodb.PyStateful to get btree data as pystate.
func
(
bt
*
lobtreeState
)
PyGetState
()
interface
{}
{
// empty btree
if
len
(
bt
.
data
)
==
0
{
// XXX assert .firstbucket = nil ?
return
pickle
.
None
{}
}
// btree with 1 child bucket without oid
if
len
(
bt
.
data
)
==
1
{
bucket
,
ok
:=
bt
.
data
[
0
]
.
child
.
(
*
LOBucket
)
if
ok
&&
bucket
.
POid
()
==
zodb
.
InvalidOid
{
// XXX recheck vs "NULL oid"
return
pickle
.
Tuple
{
pickle
.
Tuple
{((
*
lobucketState
)(
bucket
))
.
PyGetState
()}}
}
}
// regular btree
t
:=
make
(
pickle
.
Tuple
,
0
,
2
*
len
(
bt
.
data
)
-
1
)
for
i
,
entry
:=
range
bt
.
data
{
// key[0] is unused and not saved
if
i
>
0
{
t
=
append
(
t
,
entry
.
key
)
}
t
=
append
(
t
,
entry
.
child
)
}
t
=
pickle
.
Tuple
{
t
}
t
=
append
(
t
,
bt
.
firstbucket
)
return
t
}
// PySetState implements zodb.PyStateful to set btree data from pystate.
// PySetState implements zodb.PyStateful to set btree data from pystate.
func
(
bt
*
lobtreeState
)
PySetState
(
pystate
interface
{})
(
err
error
)
{
func
(
bt
*
lobtreeState
)
PySetState
(
pystate
interface
{})
(
err
error
)
{
// empty btree
// empty btree
...
...
go/zodb/import_test.go
View file @
0979eab2
...
@@ -17,20 +17,8 @@
...
@@ -17,20 +17,8 @@
// See COPYING file for full licensing terms.
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
// See https://www.nexedi.com/licensing for rationale and options.
package
zodb_test
package
zodb
// things imported at runtime via import_x_test due to cyclic dependency
import
(
var
ZPyCommit
func
(
string
,
Tid
,
...
interface
{})
(
Tid
,
error
)
// XXX ZObject
"lab.nexedi.com/kirr/neo/go/zodb"
"lab.nexedi.com/kirr/neo/go/internal/xtesting"
// wks or any other storage cannot be imported from zodb due to cycle
_
"lab.nexedi.com/kirr/neo/go/zodb/wks"
)
// import at runtime few things into zodb, that zodb cannot import itself due to cyclic dependency.
func
init
()
{
//zodb.ZPyCommit = xtesting.ZPyCommit
zodb
.
ZPyCommit
=
func
(
zurl
string
,
at
zodb
.
Tid
,
objv
...
interface
{})
(
zodb
.
Tid
,
error
)
{
return
xtesting
.
ZPyCommit
(
zurl
,
at
)
// XXX + objv
}
}
go/zodb/import_x_test.go
0 → 100644
View file @
0979eab2
// Copyright (C) 2019 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// You can also Link and Combine this program with other software covered by
// the terms of any of the Free Software licenses or any of the Open Source
// Initiative approved licenses and Convey the resulting work. Corresponding
// source of such a combination shall include the source code for all other
// software used.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
package
zodb_test
import
(
"lab.nexedi.com/kirr/neo/go/zodb"
"lab.nexedi.com/kirr/neo/go/internal/xtesting"
// wks or any other storage cannot be imported from zodb due to cycle
_
"lab.nexedi.com/kirr/neo/go/zodb/wks"
)
// import at runtime few things into zodb, that zodb cannot import itself due to cyclic dependency.
func
init
()
{
//zodb.ZPyCommit = xtesting.ZPyCommit
zodb
.
ZPyCommit
=
func
(
zurl
string
,
at
zodb
.
Tid
,
objv
...
interface
{})
(
zodb
.
Tid
,
error
)
{
return
xtesting
.
ZPyCommit
(
zurl
,
at
)
// XXX + objv
}
}
go/zodb/persistent.go
View file @
0979eab2
...
@@ -115,7 +115,10 @@ type Stateful interface {
...
@@ -115,7 +115,10 @@ type Stateful interface {
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.
//GetState() *mem.Buf TODO
//
// XXX called only when state is not dropped.
// XXX buf ownership.
GetState
()
*
mem
.
Buf
}
}
...
...
go/zodb/persistent_test.go
View file @
0979eab2
...
@@ -57,6 +57,10 @@ func (o *myObjectState) PySetState(pystate interface{}) error {
...
@@ -57,6 +57,10 @@ func (o *myObjectState) PySetState(pystate interface{}) error {
return
nil
return
nil
}
}
func
(
o
*
myObjectState
)
PyGetState
()
interface
{}
{
return
o
.
value
}
// Peristent that is not registered to ZODB.
// Peristent that is not registered to ZODB.
type
Unregistered
struct
{
type
Unregistered
struct
{
Persistent
Persistent
...
@@ -173,8 +177,6 @@ func (cc *zcacheControl) WantEvict(obj IPersistent) bool {
...
@@ -173,8 +177,6 @@ func (cc *zcacheControl) WantEvict(obj IPersistent) bool {
return
true
return
true
}
}
var
ZPyCommit
func
(
string
,
Tid
,
...
interface
{})
(
Tid
,
error
)
// XXX ZObject
// Persistent tests with storage.
// Persistent tests with storage.
func
TestPersistentDB
(
t
*
testing
.
T
)
{
func
TestPersistentDB
(
t
*
testing
.
T
)
{
X
:=
exc
.
Raiseif
X
:=
exc
.
Raiseif
...
...
go/zodb/zodbpy.go
View file @
0979eab2
// Copyright (C) 2018 Nexedi SA and Contributors.
// Copyright (C) 2018
-2019
Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
Kirill Smelkov <kirr@nexedi.com>
//
//
// This program is free software: you can Use, Study, Modify and Redistribute
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// it under the terms of the GNU General Public License version 3, or (at your
...
@@ -39,7 +39,10 @@ type PyStateful interface {
...
@@ -39,7 +39,10 @@ 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.
//PyGetState() interface{} TODO
//
// XXX called only when state is not dropped.
// XXX state ownership?
PyGetState
()
interface
{}
}
}
// pySetState decodes raw state as zodb/py serialized stream, and sets decoded
// pySetState decodes raw state as zodb/py serialized stream, and sets decoded
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment