Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
neoppod
Commits
897b9100
Commit
897b9100
authored
Feb 04, 2019
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
35e63fbb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
12 deletions
+30
-12
go/zodb/connection.go
go/zodb/connection.go
+6
-1
go/zodb/persistent_test.go
go/zodb/persistent_test.go
+24
-11
No files found.
go/zodb/connection.go
View file @
897b9100
...
@@ -179,6 +179,11 @@ func (cache *LiveCache) Get(oid Oid) IPersistent {
...
@@ -179,6 +179,11 @@ func (cache *LiveCache) Get(oid Oid) IPersistent {
return
obj
return
obj
}
}
// set sets objects corre ... XXX
func
(
cache
*
LiveCache
)
set
(
oid
Oid
,
obj
IPersistent
)
{
cache
.
objtab
[
oid
]
=
weak
.
NewRef
(
obj
)
}
// SetControl installs c to handle cache decisions.
// SetControl installs c to handle cache decisions.
//
//
// Any previously installed cache control is uninstalled.
// Any previously installed cache control is uninstalled.
...
@@ -199,7 +204,7 @@ func (conn *Connection) get(class string, oid Oid) (IPersistent, error) {
...
@@ -199,7 +204,7 @@ func (conn *Connection) get(class string, oid Oid) (IPersistent, error) {
obj
:=
conn
.
cache
.
Get
(
oid
)
obj
:=
conn
.
cache
.
Get
(
oid
)
if
obj
==
nil
{
if
obj
==
nil
{
obj
=
newGhost
(
class
,
oid
,
conn
)
obj
=
newGhost
(
class
,
oid
,
conn
)
conn
.
cache
.
objtab
[
oid
]
=
weak
.
NewRef
(
obj
)
conn
.
cache
.
objtab
[
oid
]
=
weak
.
NewRef
(
obj
)
// XXX -> conn.cache.set(oid, obj)
checkClass
=
false
checkClass
=
false
}
}
conn
.
cache
.
Unlock
()
conn
.
cache
.
Unlock
()
...
...
go/zodb/persistent_test.go
View file @
897b9100
...
@@ -25,6 +25,7 @@ import (
...
@@ -25,6 +25,7 @@ import (
"io/ioutil"
"io/ioutil"
"os"
"os"
"reflect"
"reflect"
// "runtime"
"testing"
"testing"
"lab.nexedi.com/kirr/neo/go/transaction"
"lab.nexedi.com/kirr/neo/go/transaction"
...
@@ -201,11 +202,6 @@ type tPersistentDB struct {
...
@@ -201,11 +202,6 @@ type tPersistentDB struct {
txn
transaction
.
Transaction
txn
transaction
.
Transaction
ctx
context
.
Context
ctx
context
.
Context
conn
*
Connection
conn
*
Connection
//obj1
//obj2
// XXX + at here?
}
}
// Get gets oid from t.conn and asserts it type.
// Get gets oid from t.conn and asserts it type.
...
@@ -237,7 +233,7 @@ func (t *tPersistentDB) PActivate(obj IPersistent) {
...
@@ -237,7 +233,7 @@ func (t *tPersistentDB) PActivate(obj IPersistent) {
// checkObj checks state of obj and that obj ∈ t.conn.
// checkObj checks state of obj and that obj ∈ t.conn.
//
//
// if object is !GHOST - it also verifies its value.
// if object is !GHOST - it also verifies its value.
func
(
t
*
tPersistentDB
)
checkObj
(
obj
*
MyObject
,
oid
Oid
,
serial
Tid
,
state
ObjectState
,
refcnt
int32
,
value
v
...
string
)
{
func
(
t
*
tPersistentDB
)
checkObj
(
obj
*
MyObject
,
oid
Oid
,
serial
Tid
,
state
ObjectState
,
refcnt
int32
,
value
Ok
...
string
)
{
t
.
Helper
()
t
.
Helper
()
// any object with live pointer to it must be also in conn's cache.
// any object with live pointer to it must be also in conn's cache.
...
@@ -258,16 +254,16 @@ func (t *tPersistentDB) checkObj(obj *MyObject, oid Oid, serial Tid, state Objec
...
@@ -258,16 +254,16 @@ func (t *tPersistentDB) checkObj(obj *MyObject, oid Oid, serial Tid, state Objec
_checkObj
(
t
.
T
,
obj
,
t
.
conn
,
oid
,
serial
,
state
,
refcnt
,
/*loading*/
nil
)
_checkObj
(
t
.
T
,
obj
,
t
.
conn
,
oid
,
serial
,
state
,
refcnt
,
/*loading*/
nil
)
if
state
==
GHOST
{
if
state
==
GHOST
{
if
len
(
value
v
)
!=
0
{
if
len
(
value
Ok
)
!=
0
{
panic
(
"t.checkObj(GHOST) must come without value"
)
panic
(
"t.checkObj(GHOST) must come without value"
)
}
}
return
return
}
}
if
len
(
value
v
)
!=
1
{
if
len
(
value
Ok
)
!=
1
{
panic
(
"t.checkObj(!GHOST) must come with one value"
)
panic
(
"t.checkObj(!GHOST) must come with one value"
)
}
}
value
:=
value
v
[
0
]
value
:=
value
Ok
[
0
]
if
obj
.
value
!=
value
{
if
obj
.
value
!=
value
{
t
.
Fatalf
(
"obj.value mismatch: have %q; want %q"
,
obj
.
value
,
value
)
t
.
Fatalf
(
"obj.value mismatch: have %q; want %q"
,
obj
.
value
,
value
)
}
}
...
@@ -275,6 +271,7 @@ func (t *tPersistentDB) checkObj(obj *MyObject, oid Oid, serial Tid, state Objec
...
@@ -275,6 +271,7 @@ func (t *tPersistentDB) checkObj(obj *MyObject, oid Oid, serial Tid, state Objec
// Resync resyncs t to new transaction @at.
// Resync resyncs t to new transaction @at.
func
(
t
*
tPersistentDB
)
Resync
(
at
Tid
)
{
func
(
t
*
tPersistentDB
)
Resync
(
at
Tid
)
{
t
.
Helper
()
db
:=
t
.
conn
.
db
// XXX -> t.db ?
db
:=
t
.
conn
.
db
// XXX -> t.db ?
txn
,
ctx
:=
transaction
.
New
(
context
.
Background
())
txn
,
ctx
:=
transaction
.
New
(
context
.
Background
())
...
@@ -290,6 +287,7 @@ func (t *tPersistentDB) Resync(at Tid) {
...
@@ -290,6 +287,7 @@ func (t *tPersistentDB) Resync(at Tid) {
// Abort aborts t's connection and verifies it becomes !live.
// Abort aborts t's connection and verifies it becomes !live.
func
(
t
*
tPersistentDB
)
Abort
()
{
func
(
t
*
tPersistentDB
)
Abort
()
{
t
.
Helper
()
assert
.
Equal
(
t
,
t
.
conn
.
txn
,
t
.
txn
)
assert
.
Equal
(
t
,
t
.
conn
.
txn
,
t
.
txn
)
t
.
txn
.
Abort
()
t
.
txn
.
Abort
()
assert
.
Equal
(
t
,
t
.
conn
.
txn
,
nil
)
assert
.
Equal
(
t
,
t
.
conn
.
txn
,
nil
)
...
@@ -463,12 +461,28 @@ func TestPersistentDB(t0 *testing.T) {
...
@@ -463,12 +461,28 @@ func TestPersistentDB(t0 *testing.T) {
t
.
checkObj
(
obj1
,
101
,
InvalidTid
,
GHOST
,
0
)
t
.
checkObj
(
obj1
,
101
,
InvalidTid
,
GHOST
,
0
)
t
.
checkObj
(
obj2
,
102
,
at2
,
UPTODATE
,
0
,
"kitty"
)
t
.
checkObj
(
obj2
,
102
,
at2
,
UPTODATE
,
0
,
"kitty"
)
// TODO live cache must not drop pinned entries after GC
/*
obj1 = nil
obj2 = nil
for i := 0; i < 10; i++ {
runtime.GC() // need only 2 runs since cache uses finalizers
}
xobj1 := t.conn.Cache().Get(101)
xobj2 := t.conn.Cache().Get(102)
assert.Equal(xobj1, nil)
assert.NotEqual(xobj2, nil)
obj2 = xobj2.(*MyObject)
t.checkObj(obj2, 102, at2, UPTODATE, 0, "kitty")
*/
// finish tnx3 and txn2 - conn1 and conn2 go back to db pool
// finish tnx3 and txn2 - conn1 and conn2 go back to db pool
t
.
Abort
()
t
.
Abort
()
t2
.
Abort
()
t2
.
Abort
()
assert
.
Equal
(
db
.
pool
,
[]
*
Connection
{
t1
.
conn
,
t2
.
conn
})
assert
.
Equal
(
db
.
pool
,
[]
*
Connection
{
t1
.
conn
,
t2
.
conn
})
// open new connection in nopool mode to verify resync
// open new connection in nopool mode to verify resync
t4
:=
testopen
(
&
ConnOptions
{
NoPool
:
true
})
t4
:=
testopen
(
&
ConnOptions
{
NoPool
:
true
})
t
=
t4
t
=
t4
...
@@ -573,7 +587,6 @@ func TestPersistentDB(t0 *testing.T) {
...
@@ -573,7 +587,6 @@ func TestPersistentDB(t0 *testing.T) {
// XXX DB.Open with at on and +-1 δtail edges
// XXX DB.Open with at on and +-1 δtail edges
// XXX cache dropping entries after GC
// XXX Get(txn = different) -> panic
// XXX Get(txn = different) -> panic
}
}
...
...
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