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
1ddb801a
Commit
1ddb801a
authored
Feb 04, 2019
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
94b56440
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
190 additions
and
230 deletions
+190
-230
go/zodb/persistent_test.go
go/zodb/persistent_test.go
+190
-230
No files found.
go/zodb/persistent_test.go
View file @
1ddb801a
...
@@ -31,7 +31,7 @@ import (
...
@@ -31,7 +31,7 @@ import (
"lab.nexedi.com/kirr/go123/exc"
"lab.nexedi.com/kirr/go123/exc"
"lab.nexedi.com/kirr/go123/mem"
"lab.nexedi.com/kirr/go123/mem"
"github.com/stretchr/testify/require"
assert
"github.com/stretchr/testify/require"
)
)
// test Persistent type.
// test Persistent type.
...
@@ -109,7 +109,7 @@ func _checkObj(t testing.TB, obj IPersistent, jar *Connection, oid Oid, serial T
...
@@ -109,7 +109,7 @@ func _checkObj(t testing.TB, obj IPersistent, jar *Connection, oid Oid, serial T
badf
(
"invalid state: %s ; want %s"
,
pbase
.
state
,
state
)
badf
(
"invalid state: %s ; want %s"
,
pbase
.
state
,
state
)
}
}
if
pbase
.
refcnt
!=
refcnt
{
if
pbase
.
refcnt
!=
refcnt
{
badf
(
"invalid refcnt: %
s ; want %s
"
,
pbase
.
refcnt
,
refcnt
)
badf
(
"invalid refcnt: %
d ; want %d
"
,
pbase
.
refcnt
,
refcnt
)
}
}
if
pbase
.
instance
!=
obj
{
if
pbase
.
instance
!=
obj
{
badf
(
"base.instance != obj"
)
badf
(
"base.instance != obj"
)
...
@@ -134,7 +134,7 @@ func tCheckObj(t testing.TB) func(IPersistent, *Connection, Oid, Tid, ObjectStat
...
@@ -134,7 +134,7 @@ func tCheckObj(t testing.TB) func(IPersistent, *Connection, Oid, Tid, ObjectStat
// basic Persistent tests without storage.
// basic Persistent tests without storage.
func
TestPersistentBasic
(
t
*
testing
.
T
)
{
func
TestPersistentBasic
(
t
*
testing
.
T
)
{
assert
:=
require
.
New
(
t
)
assert
:=
assert
.
New
(
t
)
checkObj
:=
tCheckObj
(
t
)
checkObj
:=
tCheckObj
(
t
)
// unknown type -> Broken
// unknown type -> Broken
...
@@ -191,32 +191,75 @@ func (cc *zcacheControl) WantEvict(obj IPersistent) bool {
...
@@ -191,32 +191,75 @@ func (cc *zcacheControl) WantEvict(obj IPersistent) bool {
return
true
return
true
}
}
/*
// ---- TestPersistentDB ----
type testenv struct {
// tPersistentDB represents one testing environment inside TestPersistentDB.
type
tPersistentDB
struct
{
*
testing
.
T
*
testing
.
T
ctx
// a transaction and DB connection opened under it
txn
txn
transaction
.
Transaction
ctx
context
.
Context
conn
*
Connection
obj1
//
obj1
obj2
//
obj2
// XXX + at here?
// XXX + at here?
}
}
testopen := func(opt *ConnOptions) *testenv {
// Get gets oid from t.conn and asserts it type.
t0.Helper()
func
(
t
*
tPersistentDB
)
Get
(
oid
Oid
)
*
MyObject
{
// XXX create txn,ctx
t
.
Helper
()
// XXX db.Open with opt
xobj
,
err
:=
t
.
conn
.
Get
(
t
.
ctx
,
oid
)
// assert conn.At == ?
if
err
!=
nil
{
// conn.db == db
t
.
Fatal
(
err
)
// conn.txn == txn
}
return &testenv{
T: t0,
zclass
:=
ClassOf
(
xobj
)
...
zmy
:=
"t.zodb.MyObject"
if
zclass
!=
zmy
{
t
.
Fatalf
(
"get %d: got %s; want %s"
,
oid
,
zclass
,
zmy
)
}
return
xobj
.
(
*
MyObject
)
}
// PActivate activates obj in t environment.
func
(
t
*
tPersistentDB
)
PActivate
(
obj
IPersistent
)
{
t
.
Helper
()
err
:=
obj
.
PActivate
(
t
.
ctx
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
}
}
*/
// XXX
func
(
t
*
tPersistentDB
)
checkObj
(
obj
IPersistent
,
oid
Oid
,
serial
Tid
,
state
ObjectState
,
refcnt
int32
,
loading
*
loadState
)
{
t
.
Helper
()
_checkObj
(
t
.
T
,
obj
,
t
.
conn
,
oid
,
serial
,
state
,
refcnt
,
loading
)
}
// Resync resyncs t to new transaction @at.
func
(
t
*
tPersistentDB
)
Resync
(
at
Tid
)
{
db
:=
t
.
conn
.
db
// XXX -> t.db ?
txn
,
ctx
:=
transaction
.
New
(
context
.
Background
())
t
.
conn
.
Resync
(
txn
,
at
)
t
.
txn
=
txn
t
.
ctx
=
ctx
assert
.
Equal
(
t
,
t
.
conn
.
db
,
db
)
assert
.
Equal
(
t
,
t
.
conn
.
txn
,
t
.
txn
)
}
// Abort aborts t's connection and verifies it becomes !live.
func
(
t
*
tPersistentDB
)
Abort
()
{
assert
.
Equal
(
t
,
t
.
conn
.
txn
,
t
.
txn
)
t
.
txn
.
Abort
()
assert
.
Equal
(
t
,
t
.
conn
.
txn
,
nil
)
}
// Persistent tests with storage.
// Persistent tests with storage.
...
@@ -225,10 +268,9 @@ testopen := func(opt *ConnOptions) *testenv {
...
@@ -225,10 +268,9 @@ testopen := func(opt *ConnOptions) *testenv {
//
//
// XXX test for cache=y/n (raw data cache)
// XXX test for cache=y/n (raw data cache)
// XXX test both txn.Abort() and conn.Resync()
// XXX test both txn.Abort() and conn.Resync()
func
TestPersistentDB
(
t
*
testing
.
T
)
{
func
TestPersistentDB
(
t
0
*
testing
.
T
)
{
X
:=
exc
.
Raiseif
X
:=
exc
.
Raiseif
assert
:=
require
.
New
(
t
)
assert
:=
assert
.
New
(
t0
)
checkObj
:=
tCheckObj
(
t
)
work
,
err
:=
ioutil
.
TempDir
(
""
,
"t-persistent"
);
X
(
err
)
work
,
err
:=
ioutil
.
TempDir
(
""
,
"t-persistent"
);
X
(
err
)
defer
func
()
{
defer
func
()
{
...
@@ -248,111 +290,73 @@ func TestPersistentDB(t *testing.T) {
...
@@ -248,111 +290,73 @@ func TestPersistentDB(t *testing.T) {
stor
,
err
:=
OpenStorage
(
ctx
,
zurl
,
&
OpenOptions
{
ReadOnly
:
true
});
X
(
err
)
stor
,
err
:=
OpenStorage
(
ctx
,
zurl
,
&
OpenOptions
{
ReadOnly
:
true
});
X
(
err
)
db
:=
NewDB
(
stor
)
db
:=
NewDB
(
stor
)
/*
testopen
:=
func
(
opt
*
ConnOptions
)
*
tPersistentDB
{
t := testopen(&ConnOptions)
t0
.
Helper
()
t.conn.Cache().SetControl(...)
t.get() // .conn.Get() + assert type + assign .objX
t.check("ghost", "ghost") // ?
t.checkObj(1, InvalidTid, GHOST, 0, nil)
t.checkObj(2, InvalidTid, GHOST, 0, nil)
t.pactivate()
t.check(at1, at1, "hello:1", "world:1")
t.pactivate(
)
txn
,
ctx
:=
transaction
.
New
(
context
.
Background
()
)
t.check(at1, at1, "hello:2", "world:2"
)
conn
,
err
:=
db
.
Open
(
ctx
,
opt
);
X
(
err
)
t.pdeactivate()
assert
.
Equal
(
conn
.
db
,
db
)
t.check(at1, at1, "hello:1", "world:1")
assert
.
Equal
(
conn
.
txn
,
txn
)
// deactivate: state dropped for obj1, obj2 stays in live cache
t.pdeactivate()
t.check(ø, at1, "GHOST:0", "world:0")
t2 := testopen(&ConnOptions{})
return
&
tPersistentDB
{
assert.Equal(db.pool, []*Connection(nil))
T
:
t0
,
t2.get()
txn
:
txn
,
t2.check(ø, ø, "ghost:0", "ghost:0")
ctx
:
ctx
,
conn
:
conn
,
t2.pactivate()
}
t2.check(at1, at2, "hello", "kitty")
}
t2.pdeactivate()
// conn1 stays at older view for now
t.check(ø, ø, "ghost:0", "ghost:0")
t.pactivate()
t.check(at1, at1, "hello:1", "world:1")
// conn1 deactivate: obj2 stays in conn1 live cache with old state
t.pdeactivate()
t.check(ø, at1, "ghost:0", "world:0")
t.abort() // t.conn.txn == t.txn; t.txn.Abort(); t.conn.txn == nil
assert.Equal(db.pool, []*Connection{t.conn})
checkObj(obj1, conn1, 101, InvalidTid, GHOST, 0, nil)
checkObj(obj2, conn1, 102, at1, UPTODATE, 0, nil)
*/
t
xn1
,
ctx1
:=
transaction
.
New
(
ctx
)
t
1
:=
testopen
(
&
ConnOptions
{}
)
conn1
,
err
:=
db
.
Open
(
ctx1
,
&
ConnOptions
{});
X
(
err
)
t
:=
t1
assert
.
Equal
(
conn1
.
At
(),
at1
)
assert
.
Equal
(
t
.
conn
.
At
(),
at1
)
assert
.
Equal
(
db
.
pool
,
[]
*
Connection
(
nil
))
assert
.
Equal
(
db
.
pool
,
[]
*
Connection
(
nil
))
assert
.
Equal
(
conn1
.
db
,
db
)
assert
.
Equal
(
conn1
.
txn
,
txn1
)
// do not evict obj2 from live cache. obj1 is ok to be evicted.
// do not evict obj2 from live cache. obj1 is ok to be evicted.
zcache1
:=
conn1
.
Cache
()
zcache1
:=
t
.
conn
.
Cache
()
zcache1
.
SetControl
(
&
zcacheControl
{[]
Oid
{
_obj2
.
oid
}})
zcache1
.
SetControl
(
&
zcacheControl
{[]
Oid
{
_obj2
.
oid
}})
// FIXME test that live cache keeps objects live even if we drop all
// FIXME test that live cache keeps objects live even if we drop all
// regular pointers to it and do GC.
// regular pointers to it and do GC.
// get objects and assert their type
// get objects and assert their type
xobj1
,
err
:=
conn1
.
Get
(
ctx1
,
101
);
X
(
err
)
xobj2
,
err
:=
conn1
.
Get
(
ctx1
,
102
);
X
(
err
)
assert
.
Equal
(
ClassOf
(
xobj1
),
"t.zodb.MyObject"
)
assert
.
Equal
(
ClassOf
(
xobj2
),
"t.zodb.MyObject"
)
// XXX objX -> c1objX ?
// XXX objX -> c1objX ?
obj1
:=
t
.
Get
(
101
)
obj2
:=
t
.
Get
(
102
)
obj1
:=
xobj1
.
(
*
MyObject
)
t
.
checkObj
(
obj1
,
101
,
InvalidTid
,
GHOST
,
0
,
nil
)
obj2
:=
xobj2
.
(
*
MyObject
)
t
.
checkObj
(
obj2
,
102
,
InvalidTid
,
GHOST
,
0
,
nil
)
checkObj
(
obj1
,
conn1
,
101
,
InvalidTid
,
GHOST
,
0
,
nil
)
checkObj
(
obj2
,
conn1
,
102
,
InvalidTid
,
GHOST
,
0
,
nil
)
// activate: jar has to load, state changes -> uptodate
// activate: jar has to load, state changes -> uptodate
err
=
obj1
.
PActivate
(
ctx1
);
X
(
err
)
t
.
PActivate
(
obj1
)
err
=
obj2
.
PActivate
(
ctx1
);
X
(
err
)
t
.
PActivate
(
obj2
)
checkObj
(
obj1
,
conn
1
,
101
,
at1
,
UPTODATE
,
1
,
nil
)
t
.
checkObj
(
obj
1
,
101
,
at1
,
UPTODATE
,
1
,
nil
)
checkObj
(
obj2
,
conn1
,
102
,
at1
,
UPTODATE
,
1
,
nil
)
t
.
checkObj
(
obj2
,
102
,
at1
,
UPTODATE
,
1
,
nil
)
assert
.
Equal
(
obj1
.
value
,
"hello"
)
assert
.
Equal
(
obj1
.
value
,
"hello"
)
assert
.
Equal
(
obj2
.
value
,
"world"
)
assert
.
Equal
(
obj2
.
value
,
"world"
)
// activate again: refcnt++
// activate again: refcnt++
err
=
obj1
.
PActivate
(
ctx1
);
X
(
err
)
t
.
PActivate
(
obj1
)
err
=
obj2
.
PActivate
(
ctx1
);
X
(
err
)
t
.
PActivate
(
obj2
)
checkObj
(
obj1
,
conn
1
,
101
,
at1
,
UPTODATE
,
2
,
nil
)
t
.
checkObj
(
obj
1
,
101
,
at1
,
UPTODATE
,
2
,
nil
)
checkObj
(
obj2
,
conn1
,
102
,
at1
,
UPTODATE
,
2
,
nil
)
t
.
checkObj
(
obj2
,
102
,
at1
,
UPTODATE
,
2
,
nil
)
// deactivate: refcnt--
// deactivate: refcnt--
obj1
.
PDeactivate
()
obj1
.
PDeactivate
()
obj2
.
PDeactivate
()
obj2
.
PDeactivate
()
checkObj
(
obj1
,
conn
1
,
101
,
at1
,
UPTODATE
,
1
,
nil
)
t
.
checkObj
(
obj
1
,
101
,
at1
,
UPTODATE
,
1
,
nil
)
checkObj
(
obj2
,
conn1
,
102
,
at1
,
UPTODATE
,
1
,
nil
)
t
.
checkObj
(
obj2
,
102
,
at1
,
UPTODATE
,
1
,
nil
)
// deactivate: state dropped for obj1, obj2 stays in live cache
// deactivate: state dropped for obj1, obj2 stays in live cache
obj1
.
PDeactivate
()
obj1
.
PDeactivate
()
obj2
.
PDeactivate
()
obj2
.
PDeactivate
()
checkObj
(
obj1
,
conn
1
,
101
,
InvalidTid
,
GHOST
,
0
,
nil
)
t
.
checkObj
(
obj
1
,
101
,
InvalidTid
,
GHOST
,
0
,
nil
)
checkObj
(
obj2
,
conn1
,
102
,
at1
,
UPTODATE
,
0
,
nil
)
t
.
checkObj
(
obj2
,
102
,
at1
,
UPTODATE
,
0
,
nil
)
// invalidate: obj2 state dropped
// invalidate: obj2 state dropped
obj1
.
PInvalidate
()
obj1
.
PInvalidate
()
obj2
.
PInvalidate
()
obj2
.
PInvalidate
()
checkObj
(
obj1
,
conn1
,
101
,
InvalidTid
,
GHOST
,
0
,
nil
)
t
.
checkObj
(
obj1
,
101
,
InvalidTid
,
GHOST
,
0
,
nil
)
checkObj
(
obj2
,
conn1
,
102
,
InvalidTid
,
GHOST
,
0
,
nil
)
t
.
checkObj
(
obj2
,
102
,
InvalidTid
,
GHOST
,
0
,
nil
)
// commit change to obj2 from external process
// commit change to obj2 from external process
_obj2
.
value
=
"kitty"
_obj2
.
value
=
"kitty"
...
@@ -360,28 +364,19 @@ func TestPersistentDB(t *testing.T) {
...
@@ -360,28 +364,19 @@ func TestPersistentDB(t *testing.T) {
// new db connection should see the change
// new db connection should see the change
// XXX currently there is a race because db.Open does not do proper Sync
// XXX currently there is a race because db.Open does not do proper Sync
txn2
,
ctx2
:=
transaction
.
New
(
ctx
)
t2
:=
testopen
(
&
ConnOptions
{})
conn2
,
err
:=
db
.
Open
(
ctx2
,
&
ConnOptions
{});
X
(
err
)
assert
.
Equal
(
t2
.
conn
.
At
(),
at2
)
assert
.
Equal
(
conn2
.
At
(),
at2
)
assert
.
Equal
(
db
.
pool
,
[]
*
Connection
(
nil
))
assert
.
Equal
(
db
.
pool
,
[]
*
Connection
(
nil
))
assert
.
Equal
(
conn2
.
db
,
db
)
assert
.
Equal
(
conn2
.
txn
,
txn2
)
xc2obj1
,
err
:=
conn2
.
Get
(
ctx2
,
101
);
X
(
err
)
xc2obj2
,
err
:=
conn2
.
Get
(
ctx2
,
102
);
X
(
err
)
assert
.
Equal
(
ClassOf
(
xc2obj1
),
"t.zodb.MyObject"
)
assert
.
Equal
(
ClassOf
(
xc2obj2
),
"t.zodb.MyObject"
)
c2obj1
:=
xc2obj1
.
(
*
MyObject
)
c2obj1
:=
t2
.
Get
(
101
)
c2obj2
:=
xc2obj2
.
(
*
MyObject
)
c2obj2
:=
t2
.
Get
(
102
)
checkObj
(
c2obj1
,
conn2
,
101
,
InvalidTid
,
GHOST
,
0
,
nil
)
t2
.
checkObj
(
c2obj1
,
101
,
InvalidTid
,
GHOST
,
0
,
nil
)
checkObj
(
c2obj2
,
conn
2
,
102
,
InvalidTid
,
GHOST
,
0
,
nil
)
t2
.
checkObj
(
c2obj
2
,
102
,
InvalidTid
,
GHOST
,
0
,
nil
)
err
=
c2obj1
.
PActivate
(
ctx2
);
X
(
err
)
t2
.
PActivate
(
c2obj1
)
err
=
c2obj2
.
PActivate
(
ctx2
);
X
(
err
)
t2
.
PActivate
(
c2obj2
)
checkObj
(
c2obj1
,
conn2
,
101
,
at1
,
UPTODATE
,
1
,
nil
)
t2
.
checkObj
(
c2obj1
,
101
,
at1
,
UPTODATE
,
1
,
nil
)
checkObj
(
c2obj2
,
conn
2
,
102
,
at2
,
UPTODATE
,
1
,
nil
)
t2
.
checkObj
(
c2obj
2
,
102
,
at2
,
UPTODATE
,
1
,
nil
)
assert
.
Equal
(
c2obj1
.
value
,
"hello"
)
assert
.
Equal
(
c2obj1
.
value
,
"hello"
)
assert
.
Equal
(
c2obj2
.
value
,
"kitty"
)
assert
.
Equal
(
c2obj2
.
value
,
"kitty"
)
c2obj1
.
PDeactivate
()
c2obj1
.
PDeactivate
()
...
@@ -389,181 +384,146 @@ func TestPersistentDB(t *testing.T) {
...
@@ -389,181 +384,146 @@ func TestPersistentDB(t *testing.T) {
// conn1 stays at older view for now
// conn1 stays at older view for now
checkObj
(
obj1
,
conn
1
,
101
,
InvalidTid
,
GHOST
,
0
,
nil
)
t1
.
checkObj
(
obj
1
,
101
,
InvalidTid
,
GHOST
,
0
,
nil
)
checkObj
(
obj2
,
conn1
,
102
,
InvalidTid
,
GHOST
,
0
,
nil
)
t1
.
checkObj
(
obj2
,
102
,
InvalidTid
,
GHOST
,
0
,
nil
)
err
=
obj1
.
PActivate
(
ctx1
);
X
(
err
)
t1
.
PActivate
(
obj1
)
err
=
obj2
.
PActivate
(
ctx1
);
X
(
err
)
t1
.
PActivate
(
obj2
)
checkObj
(
obj1
,
conn
1
,
101
,
at1
,
UPTODATE
,
1
,
nil
)
t1
.
checkObj
(
obj
1
,
101
,
at1
,
UPTODATE
,
1
,
nil
)
checkObj
(
obj2
,
conn1
,
102
,
at1
,
UPTODATE
,
1
,
nil
)
t1
.
checkObj
(
obj2
,
102
,
at1
,
UPTODATE
,
1
,
nil
)
assert
.
Equal
(
obj1
.
value
,
"hello"
)
assert
.
Equal
(
obj1
.
value
,
"hello"
)
assert
.
Equal
(
obj2
.
value
,
"world"
)
assert
.
Equal
(
obj2
.
value
,
"world"
)
// conn1 deactivate: obj2 stays in conn1 live cache with old state
// conn1 deactivate: obj2 stays in conn1 live cache with old state
obj1
.
PDeactivate
()
obj1
.
PDeactivate
()
obj2
.
PDeactivate
()
obj2
.
PDeactivate
()
checkObj
(
obj1
,
conn
1
,
101
,
InvalidTid
,
GHOST
,
0
,
nil
)
t1
.
checkObj
(
obj
1
,
101
,
InvalidTid
,
GHOST
,
0
,
nil
)
checkObj
(
obj2
,
conn1
,
102
,
at1
,
UPTODATE
,
0
,
nil
)
t1
.
checkObj
(
obj2
,
102
,
at1
,
UPTODATE
,
0
,
nil
)
// txn1 completes - conn1 goes back to db pool
// txn1 completes - conn1 goes back to db pool
assert
.
Equal
(
conn1
.
txn
,
txn1
)
t1
.
Abort
()
txn1
.
Abort
()
assert
.
Equal
(
db
.
pool
,
[]
*
Connection
{
t1
.
conn
})
assert
.
Equal
(
conn1
.
txn
,
nil
)
assert
.
Equal
(
db
.
pool
,
[]
*
Connection
{
conn1
})
// open new connection - it should be conn1 but at updated database view
// open new connection - it should be conn1 but at updated database view
txn3
,
ctx3
:=
transaction
.
New
(
ctx
)
t3
:=
testopen
(
&
ConnOptions
{})
assert
.
NotEqual
(
txn3
,
txn1
)
assert
.
Equal
(
t3
.
conn
,
t1
.
conn
)
// XXX is
conn3
,
err
:=
db
.
Open
(
ctx3
,
&
ConnOptions
{});
X
(
err
)
t
=
t3
assert
.
Equal
(
conn3
,
conn1
)
// XXX is
assert
.
Equal
(
t
.
conn
.
At
(),
at2
)
assert
.
Equal
(
conn1
.
At
(),
at2
)
assert
.
Equal
(
conn1
.
db
,
db
)
assert
.
Equal
(
conn1
.
txn
,
txn3
)
assert
.
Equal
(
db
.
pool
,
[]
*
Connection
{})
assert
.
Equal
(
db
.
pool
,
[]
*
Connection
{})
ctx1
=
ctx3
// not to use ctx3 below
ctx3
=
nil
// obj2 should be invalidated
// obj2 should be invalidated
assert
.
Equal
(
conn1
.
Cache
()
.
Get
(
101
),
obj1
)
// XXX is
assert
.
Equal
(
t
.
conn
.
Cache
()
.
Get
(
101
),
obj1
)
// XXX is
assert
.
Equal
(
conn1
.
Cache
()
.
Get
(
102
),
obj2
)
// XXX is
assert
.
Equal
(
t
.
conn
.
Cache
()
.
Get
(
102
),
obj2
)
// XXX is
checkObj
(
obj1
,
conn
1
,
101
,
InvalidTid
,
GHOST
,
0
,
nil
)
t
.
checkObj
(
obj
1
,
101
,
InvalidTid
,
GHOST
,
0
,
nil
)
checkObj
(
obj2
,
conn1
,
102
,
InvalidTid
,
GHOST
,
0
,
nil
)
t
.
checkObj
(
obj2
,
102
,
InvalidTid
,
GHOST
,
0
,
nil
)
// obj2 data should be new
// obj2 data should be new
xobj1
,
err
=
conn1
.
Get
(
ctx1
,
101
);
X
(
err
)
assert
.
Exactly
(
obj1
,
t
.
Get
(
101
))
// XXX is
xobj2
,
err
=
conn1
.
Get
(
ctx1
,
102
);
X
(
err
)
assert
.
Exactly
(
obj2
,
t
.
Get
(
102
))
// XXX is
assert
.
Exactly
(
obj1
,
xobj1
)
// XXX is
t
.
PActivate
(
obj1
);
assert
.
Exactly
(
obj2
,
xobj2
)
// XXX is
t
.
PActivate
(
obj2
);
err
=
obj1
.
PActivate
(
ctx1
);
X
(
err
)
t
.
checkObj
(
obj1
,
101
,
at1
,
UPTODATE
,
1
,
nil
)
err
=
obj2
.
PActivate
(
ctx1
);
X
(
err
)
t
.
checkObj
(
obj2
,
102
,
at2
,
UPTODATE
,
1
,
nil
)
checkObj
(
obj1
,
conn1
,
101
,
at1
,
UPTODATE
,
1
,
nil
)
checkObj
(
obj2
,
conn1
,
102
,
at2
,
UPTODATE
,
1
,
nil
)
assert
.
Equal
(
obj1
.
value
,
"hello"
)
assert
.
Equal
(
obj1
.
value
,
"hello"
)
assert
.
Equal
(
obj2
.
value
,
"kitty"
)
assert
.
Equal
(
obj2
.
value
,
"kitty"
)
// XXX deactivate
// XXX deactivate
// finish tnx3 and txn2 - conn1 and conn2 go back to db pool
// finish tnx3 and txn2 - conn1 and conn2 go back to db pool
txn3
.
Abort
()
t
.
Abort
()
txn2
.
Abort
()
t2
.
Abort
()
assert
.
Equal
(
conn1
.
txn
,
nil
)
assert
.
Equal
(
db
.
pool
,
[]
*
Connection
{
t1
.
conn
,
t2
.
conn
})
assert
.
Equal
(
conn2
.
txn
,
nil
)
assert
.
Equal
(
db
.
pool
,
[]
*
Connection
{
conn1
,
conn2
})
// open new connection in nopool mode to verify resync
// open new connection in nopool mode to verify resync
txn4
,
ctx4
:=
transaction
.
New
(
ctx
)
t4
:=
testopen
(
&
ConnOptions
{
NoPool
:
true
})
rconn
,
err
:=
db
.
Open
(
ctx4
,
&
ConnOptions
{
NoPool
:
true
});
X
(
err
)
t
=
t4
assert
.
Equal
(
rconn
.
At
(),
at2
)
assert
.
Equal
(
t
.
conn
.
At
(),
at2
)
assert
.
Equal
(
db
.
pool
,
[]
*
Connection
{
conn1
,
conn2
})
assert
.
Equal
(
db
.
pool
,
[]
*
Connection
{
t1
.
conn
,
t2
.
conn
})
assert
.
Equal
(
rconn
.
db
,
db
)
assert
.
Equal
(
rconn
.
txn
,
txn4
)
// pin obj2 into live cache, similarly to conn1
// pin obj2 into live cache, similarly to conn1
rzcache
:=
r
conn
.
Cache
()
rzcache
:=
t
.
conn
.
Cache
()
rzcache
.
SetControl
(
&
zcacheControl
{[]
Oid
{
_obj2
.
oid
}})
rzcache
.
SetControl
(
&
zcacheControl
{[]
Oid
{
_obj2
.
oid
}})
// it should see latest data
// it should see latest data
xrobj1
,
err
:=
rconn
.
Get
(
ctx4
,
101
);
X
(
err
)
robj1
:=
t
.
Get
(
101
)
xrobj2
,
err
:=
rconn
.
Get
(
ctx4
,
102
);
X
(
err
)
robj2
:=
t
.
Get
(
102
)
t
.
checkObj
(
robj1
,
101
,
InvalidTid
,
GHOST
,
0
,
nil
)
assert
.
Equal
(
ClassOf
(
xrobj1
),
"t.zodb.MyObject"
)
t
.
checkObj
(
robj2
,
102
,
InvalidTid
,
GHOST
,
0
,
nil
)
assert
.
Equal
(
ClassOf
(
xrobj2
),
"t.zodb.MyObject"
)
t
.
PActivate
(
robj1
)
robj1
:=
xrobj1
.
(
*
MyObject
)
t
.
PActivate
(
robj2
)
robj2
:=
xrobj2
.
(
*
MyObject
)
t
.
checkObj
(
robj1
,
101
,
at1
,
UPTODATE
,
1
,
nil
)
checkObj
(
robj1
,
rconn
,
101
,
InvalidTid
,
GHOST
,
0
,
nil
)
t
.
checkObj
(
robj2
,
102
,
at2
,
UPTODATE
,
1
,
nil
)
checkObj
(
robj2
,
rconn
,
102
,
InvalidTid
,
GHOST
,
0
,
nil
)
err
=
robj1
.
PActivate
(
ctx4
);
X
(
err
)
err
=
robj2
.
PActivate
(
ctx4
);
X
(
err
)
checkObj
(
robj1
,
rconn
,
101
,
at1
,
UPTODATE
,
1
,
nil
)
checkObj
(
robj2
,
rconn
,
102
,
at2
,
UPTODATE
,
1
,
nil
)
assert
.
Equal
(
robj1
.
value
,
"hello"
)
assert
.
Equal
(
robj1
.
value
,
"hello"
)
assert
.
Equal
(
robj2
.
value
,
"kitty"
)
assert
.
Equal
(
robj2
.
value
,
"kitty"
)
// obj2 stays in live cache
// obj2 stays in live cache
robj1
.
PDeactivate
()
robj1
.
PDeactivate
()
robj2
.
PDeactivate
()
robj2
.
PDeactivate
()
checkObj
(
robj1
,
rconn
,
101
,
InvalidTid
,
GHOST
,
0
,
nil
)
t
.
checkObj
(
robj1
,
101
,
InvalidTid
,
GHOST
,
0
,
nil
)
checkObj
(
robj2
,
rconn
,
102
,
at2
,
UPTODATE
,
0
,
nil
)
t
.
checkObj
(
robj2
,
102
,
at2
,
UPTODATE
,
0
,
nil
)
// txn4 completes, but rconn stays out of db pool
// txn4 completes, but its conn stays out of db pool
assert
.
Equal
(
rconn
.
txn
,
txn4
)
t
.
Abort
()
txn4
.
Abort
()
assert
.
Equal
(
db
.
pool
,
[]
*
Connection
{
t1
.
conn
,
t2
.
conn
})
assert
.
Equal
(
rconn
.
txn
,
nil
)
assert
.
Equal
(
db
.
pool
,
[]
*
Connection
{
conn1
,
conn2
})
// Resync ↓ (at2 -> at1; within δtail coverage)
// Resync ↓ (at2 -> at1; within δtail coverage)
txn5
,
ctx5
:=
transaction
.
New
(
ctx
)
t
.
Resync
(
at1
)
rconn
.
Resync
(
txn5
,
at1
)
assert
.
Equal
(
t
.
conn
.
At
(),
at1
)
assert
.
Equal
(
db
.
pool
,
[]
*
Connection
{
t1
.
conn
,
t2
.
conn
})
assert
.
Equal
(
rconn
.
At
(),
at1
)
// XXX -> tt
assert
.
Equal
(
db
.
pool
,
[]
*
Connection
{
conn1
,
conn2
})
assert
.
Equal
(
rconn
.
db
,
db
)
// XXX -> tt
assert
.
Equal
(
rconn
.
txn
,
txn5
)
// XXX -> tt
// obj2 should be invalidated
// obj2 should be invalidated
assert
.
Equal
(
r
conn
.
Cache
()
.
Get
(
101
),
robj1
)
// XXX is
assert
.
Equal
(
t
.
conn
.
Cache
()
.
Get
(
101
),
robj1
)
// XXX is
assert
.
Equal
(
r
conn
.
Cache
()
.
Get
(
102
),
robj2
)
// XXX is
assert
.
Equal
(
t
.
conn
.
Cache
()
.
Get
(
102
),
robj2
)
// XXX is
checkObj
(
robj1
,
rconn
,
101
,
InvalidTid
,
GHOST
,
0
,
nil
)
t
.
checkObj
(
robj1
,
101
,
InvalidTid
,
GHOST
,
0
,
nil
)
checkObj
(
robj2
,
rconn
,
102
,
InvalidTid
,
GHOST
,
0
,
nil
)
t
.
checkObj
(
robj2
,
102
,
InvalidTid
,
GHOST
,
0
,
nil
)
// obj2 data should be old
// obj2 data should be old
//tt.checkData(at1, at2, "hello", "world")
//tt.checkData(at1, at2, "hello", "world")
xrobj1
,
err
=
rconn
.
Get
(
ctx5
,
101
);
X
(
err
)
assert
.
Exactly
(
robj1
,
t
.
Get
(
101
))
// XXX is
xrobj2
,
err
=
rconn
.
Get
(
ctx5
,
102
);
X
(
err
)
assert
.
Exactly
(
robj2
,
t
.
Get
(
102
))
// XXX is
assert
.
Exactly
(
robj1
,
xrobj1
)
// XXX is
t
.
PActivate
(
robj1
)
assert
.
Exactly
(
robj2
,
xrobj2
)
// XXX is
t
.
PActivate
(
robj2
)
err
=
robj1
.
PActivate
(
ctx5
);
X
(
err
)
t
.
checkObj
(
robj1
,
101
,
at1
,
UPTODATE
,
1
,
nil
)
err
=
robj2
.
PActivate
(
ctx5
);
X
(
err
)
t
.
checkObj
(
robj2
,
102
,
at1
,
UPTODATE
,
1
,
nil
)
checkObj
(
robj1
,
rconn
,
101
,
at1
,
UPTODATE
,
1
,
nil
)
checkObj
(
robj2
,
rconn
,
102
,
at1
,
UPTODATE
,
1
,
nil
)
assert
.
Equal
(
robj1
.
value
,
"hello"
)
assert
.
Equal
(
robj1
.
value
,
"hello"
)
assert
.
Equal
(
robj2
.
value
,
"world"
)
assert
.
Equal
(
robj2
.
value
,
"world"
)
robj1
.
PDeactivate
()
robj1
.
PDeactivate
()
robj2
.
PDeactivate
()
robj2
.
PDeactivate
()
checkObj
(
robj1
,
rconn
,
101
,
InvalidTid
,
GHOST
,
0
,
nil
)
t
.
checkObj
(
robj1
,
101
,
InvalidTid
,
GHOST
,
0
,
nil
)
checkObj
(
robj2
,
rconn
,
102
,
at1
,
UPTODATE
,
0
,
nil
)
t
.
checkObj
(
robj2
,
102
,
at1
,
UPTODATE
,
0
,
nil
)
// Resync ↑ (at1 -> at2; within δtail coverage)
// Resync ↑ (at1 -> at2; within δtail coverage)
assert
.
Equal
(
rconn
.
txn
,
txn5
)
t
.
Abort
()
txn5
.
Abort
()
assert
.
Equal
(
db
.
pool
,
[]
*
Connection
{
t1
.
conn
,
t2
.
conn
})
assert
.
Equal
(
rconn
.
txn
,
nil
)
assert
.
Equal
(
db
.
pool
,
[]
*
Connection
{
conn1
,
conn2
})
txn6
,
ctx6
:=
transaction
.
New
(
ctx
)
rconn
.
Resync
(
txn6
,
at2
)
assert
.
Equal
(
rconn
.
At
(),
at2
)
// XXX -> tt
t
.
Resync
(
at2
)
assert
.
Equal
(
db
.
pool
,
[]
*
Connection
{
conn1
,
conn2
})
assert
.
Equal
(
t
.
conn
.
At
(),
at2
)
assert
.
Equal
(
rconn
.
db
,
db
)
// XXX -> tt
assert
.
Equal
(
db
.
pool
,
[]
*
Connection
{
t1
.
conn
,
t2
.
conn
})
assert
.
Equal
(
rconn
.
txn
,
txn6
)
// XXX -> tt
// obj2 should be invalidated
// obj2 should be invalidated
assert
.
Equal
(
rconn
.
Cache
()
.
Get
(
101
),
robj1
)
// XXX is
assert
.
Equal
(
t
.
conn
.
Cache
()
.
Get
(
101
),
robj1
)
// XXX is
assert
.
Equal
(
rconn
.
Cache
()
.
Get
(
102
),
robj2
)
// XXX is
assert
.
Equal
(
t
.
conn
.
Cache
()
.
Get
(
102
),
robj2
)
// XXX is
checkObj
(
robj1
,
rconn
,
101
,
InvalidTid
,
GHOST
,
0
,
nil
)
t
.
checkObj
(
robj1
,
101
,
InvalidTid
,
GHOST
,
0
,
nil
)
checkObj
(
robj2
,
rconn
,
102
,
InvalidTid
,
GHOST
,
0
,
nil
)
t
.
checkObj
(
robj2
,
102
,
InvalidTid
,
GHOST
,
0
,
nil
)
xrobj1
,
err
=
rconn
.
Get
(
ctx6
,
101
);
X
(
err
)
assert
.
Exactly
(
robj1
,
t
.
Get
(
101
))
// XXX is
xrobj2
,
err
=
rconn
.
Get
(
ctx6
,
102
);
X
(
err
)
assert
.
Exactly
(
robj2
,
t
.
Get
(
102
))
// XXX is
assert
.
Exactly
(
robj1
,
xrobj1
)
// XXX is
t
.
PActivate
(
robj1
)
assert
.
Exactly
(
robj2
,
xrobj2
)
// XXX is
t
.
PActivate
(
robj2
)
err
=
robj1
.
PActivate
(
ctx6
);
X
(
err
)
t
.
checkObj
(
robj1
,
101
,
at1
,
UPTODATE
,
1
,
nil
)
err
=
robj2
.
PActivate
(
ctx6
);
X
(
err
)
t
.
checkObj
(
robj2
,
102
,
at2
,
UPTODATE
,
1
,
nil
)
checkObj
(
robj1
,
rconn
,
101
,
at1
,
UPTODATE
,
1
,
nil
)
checkObj
(
robj2
,
rconn
,
102
,
at2
,
UPTODATE
,
1
,
nil
)
assert
.
Equal
(
robj1
.
value
,
"hello"
)
assert
.
Equal
(
robj1
.
value
,
"hello"
)
assert
.
Equal
(
robj2
.
value
,
"kitty"
)
assert
.
Equal
(
robj2
.
value
,
"kitty"
)
robj1
.
PDeactivate
()
robj1
.
PDeactivate
()
robj2
.
PDeactivate
()
robj2
.
PDeactivate
()
checkObj
(
robj1
,
rconn
,
101
,
InvalidTid
,
GHOST
,
0
,
nil
)
t
.
checkObj
(
robj1
,
101
,
InvalidTid
,
GHOST
,
0
,
nil
)
checkObj
(
robj2
,
rconn
,
102
,
at2
,
UPTODATE
,
0
,
nil
)
t
.
checkObj
(
robj2
,
102
,
at2
,
UPTODATE
,
0
,
nil
)
t
xn6
.
Abort
()
t
.
Abort
()
// TODO Resync (without δtail coverage)
// TODO Resync (without δtail coverage)
...
...
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