Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wendelin.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Kirill Smelkov
wendelin.core
Commits
7be36e9e
Commit
7be36e9e
authored
Jul 16, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
a19787b9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
25 deletions
+52
-25
wcfs/btree.go
wcfs/btree.go
+4
-4
wcfs/zblk.go
wcfs/zblk.go
+1
-1
wcfs/zodb.go
wcfs/zodb.go
+47
-20
No files found.
wcfs/btree.go
View file @
7be36e9e
...
...
@@ -36,7 +36,7 @@ type KEY int64
// are chained together via 'next', so that the entire BTree contents
// can be traversed in sorted order quickly and easily.
type
ZBucket
struct
{
pyobj
*
P
yObject
pyobj
*
p
yObject
next
*
ZBucket
// the bucket with the next-larger keys
keys
[]
KEY
// 'len' keys, in increasing order
...
...
@@ -54,7 +54,7 @@ type zBTreeItem struct {
// See https://github.com/zopefoundation/BTrees/blob/4.5.0-1-gc8bf24e/BTrees/Development.txt#L198
// for details.
type
ZBTree
struct
{
pyobj
*
P
yObject
pyobj
*
p
yObject
// firstbucket points to the bucket containing the smallest key in
// the BTree. This is found by traversing leftmost child pointers
...
...
@@ -239,11 +239,11 @@ func (b *ZBucket) PActivate(ctx context.Context) error {
// ----------------------------------------
func
bucketNew
(
pyobj
*
P
yObject
)
interface
{}
{
func
bucketNew
(
pyobj
*
p
yObject
)
interface
{}
{
return
&
ZBucket
{
pyobj
:
pyobj
}
}
func
btreeNew
(
pyobj
*
P
yObject
)
interface
{}
{
func
btreeNew
(
pyobj
*
p
yObject
)
interface
{}
{
return
&
ZBTree
{
pyobj
:
pyobj
}
}
...
...
wcfs/zblk.go
View file @
7be36e9e
...
...
@@ -39,7 +39,7 @@ import (
// ZBigFile mimics ZBigFile from python.
type
ZBigFile
struct
{
pyobj
*
P
yObject
pyobj
*
p
yObject
blksize
int64
blktab
*
ZBTree
// LOBtree{} blk -> ZBlk*(blkdata)
...
...
wcfs/zodb.go
View file @
7be36e9e
...
...
@@ -16,6 +16,7 @@ package main
import
(
"context"
"fmt"
"sync"
"lab.nexedi.com/kirr/neo/go/zodb"
...
...
@@ -23,16 +24,16 @@ import (
pickle
"github.com/kisielk/og-rek"
)
//
O
bject is common base for in-process representation of ZODB object.
type
O
bject
struct
{
//
o
bject is common base for in-process representation of ZODB object.
type
o
bject
struct
{
jar
*
Connection
oid
zodb
.
Oid
serial
zodb
.
Tid
}
//
P
yObject is common base for in-process representation of ZODB Python objects.
type
P
yObject
struct
{
O
bject
//
p
yObject is common base for in-process representation of ZODB Python objects.
type
p
yObject
struct
{
o
bject
pyclass
pickle
.
Class
// python class of this object
pystate
interface
{}
// object state. python passes this to pyclass.__new__().__setstate__()
...
...
@@ -98,7 +99,7 @@ type Connection struct {
// NOTE2 finalizers don't run on when they are attached to an object in cycle.
// Hopefully we don't have cycles with ZBtree/ZBucket XXX verify this
objmu
sync
.
Mutex
//objtab map[zodb.Oid]interface{} // oid -> WeakRef(
P
yObject) | loadInProgress
//objtab map[zodb.Oid]interface{} // oid -> WeakRef(
p
yObject) | loadInProgress
objtab
map
[
zodb
.
Oid
]
*
WeakRef
}
...
...
@@ -109,7 +110,7 @@ type loadInProgress struct {
ready chan struct{} // closed when loading finishes
// result of the load
pyobj interface{} // XXX ->
P
yObject iface
pyobj interface{} // XXX ->
p
yObject iface
err error
}
*/
...
...
@@ -143,7 +144,10 @@ func (conn *Connection) Get(ctx context.Context, oid zodb.Oid) (interface{} /*Py
return
nil
,
err
// XXX errctx
}
xobj
=
conn
.
get
(
pyclass
,
oid
)
xobj
,
err
=
conn
.
get
(
pyclass
,
oid
)
if
err
!=
nil
{
return
nil
,
err
}
// XXX we are dropping just loaded pystate. Usually Get should be used
// to only load root object, so maybe that is ok.
...
...
@@ -209,6 +213,15 @@ func (conn *Connection) Get(ctx context.Context, oid zodb.Oid) (interface{} /*Py
*/
}
// wrongClassError is the error cause returned when object's class is wrong.
type
wrongClassError
struct
{
want
,
have
pickle
.
Class
}
func
(
e
*
wrongClassError
)
Error
()
string
{
return
fmt
.
Sprintf
(
"wrong class: want %q; have %q"
,
e
.
want
,
e
.
have
)
}
// get returns in-RAM object corresponding to specified ZODB object according to current database view.
//
// If there is already in-RAM object that corresponds to oid, that in-RAM object is returned.
...
...
@@ -219,20 +232,34 @@ func (conn *Connection) Get(ctx context.Context, oid zodb.Oid) (interface{} /*Py
//
// use-case: in ZODB references are (pyclass, oid), so new ghost is created
// without further loading anything.
func
(
conn
*
Connection
)
get
(
pyclass
pickle
.
Class
,
oid
zodb
.
Oid
)
interface
{}
/*PyObject*/
{
func
(
conn
*
Connection
)
get
(
pyclass
pickle
.
Class
,
oid
zodb
.
Oid
)
(
interface
{}
/*PyObject*/
,
error
)
{
conn
.
objmu
.
Lock
()
// XXX -> rlock
wobj
:=
conn
.
objtab
[
oid
]
var
xobj
interface
{}
checkClass
:=
false
if
wobj
!=
nil
{
xobj
=
wobj
.
Get
()
// XXX check pyclass match.
}
if
xobj
==
nil
{
xobj
=
conn
.
newGhost
(
pyclass
,
oid
)
conn
.
objtab
[
oid
]
=
NewWeakRef
(
xobj
)
}
else
{
checkClass
=
true
}
conn
.
objmu
.
Unlock
()
return
xobj
if
checkClass
{
if
cls
:=
xobj
.
PyClass
();
pyclass
!=
cls
{
return
nil
,
&
zodb
.
OpError
{
URL
:
conn
.
stor
.
URL
(),
Op
:
fmt
.
Sprintf
(
"@%s: get"
,
conn
.
at
),
// XXX abuse
Args
:
oid
,
Err
:
&
wrongClassError
{
pyclass
,
cls
},
}
}
}
return
xobj
,
nil
}
...
...
@@ -306,8 +333,8 @@ func (conn *Connection) get(pyclass pickle.Class, oid zodb.Oid) interface{}/*PyO
buf.Release()
return &
P
yObject{
Object: O
bject{jar: conn,oid: oid, serial: serial},
return &
p
yObject{
object: o
bject{jar: conn,oid: oid, serial: serial},
pyclass: pyclass,
pystate: pystate,
}, nil
...
...
@@ -315,7 +342,7 @@ func (conn *Connection) get(pyclass pickle.Class, oid zodb.Oid) interface{}/*PyO
*/
/*
func (conn *Connection) load(ctx context.Context, oid zodb.Oid) (*
P
yObject, error) {
func (conn *Connection) load(ctx context.Context, oid zodb.Oid) (*
p
yObject, error) {
// XXX
}
*/
...
...
@@ -337,20 +364,20 @@ func (conn *Connection) loadpy(ctx context.Context, oid zodb.Oid) (pyclass pickl
}
// path(class) -> new(pyobj)
var
classTab
=
make
(
map
[
string
]
func
(
*
P
yObject
)
interface
{})
var
classTab
=
make
(
map
[
string
]
func
(
*
p
yObject
)
interface
{})
// registerClass registers python class to be transformed to Go instance
// created via classNew.
//
// must be called from global init().
func
registerClass
(
classPath
string
,
classNew
func
(
*
P
yObject
)
interface
{})
{
func
registerClass
(
classPath
string
,
classNew
func
(
*
p
yObject
)
interface
{})
{
classTab
[
classPath
]
=
classNew
}
// newGhost creates new ghost object corresponding to pyclass and oid.
func
(
conn
*
Connection
)
newGhost
(
pyclass
pickle
.
Class
,
oid
zodb
.
Oid
)
interface
{}
{
pyobj
:=
&
P
yObject
{
Object
:
O
bject
{
jar
:
conn
,
oid
:
oid
,
serial
:
0
},
pyobj
:=
&
p
yObject
{
object
:
o
bject
{
jar
:
conn
,
oid
:
oid
,
serial
:
0
},
pyclass
:
pyclass
,
pystate
:
nil
,
}
...
...
@@ -370,7 +397,7 @@ func (conn *Connection) newGhost(pyclass pickle.Class, oid zodb.Oid) interface{}
// PDeactivates transforms object to ghost state.
//
// In ghost state object data is dropped and only oid/pyclass information is left in RAM.
func
(
pyobj
*
P
yObject
)
PDeactivate
()
{
func
(
pyobj
*
p
yObject
)
PDeactivate
()
{
// FIXME if state=modified PDeactivate must be noop.
pyobj
.
pystate
=
nil
...
...
@@ -380,7 +407,7 @@ func (pyobj *PyObject) PDeactivate() {
// PActivate brings object to live state.
//
// If object state is not in RAM - it is loaded from the database.
func
(
pyobj
*
P
yObject
)
PActivate
(
ctx
context
.
Context
)
error
{
func
(
pyobj
*
p
yObject
)
PActivate
(
ctx
context
.
Context
)
error
{
if
pyobj
.
pystate
!=
nil
{
return
nil
// already loaded
}
...
...
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