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
7ed177e4
Commit
7ed177e4
authored
Jul 01, 2021
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
1e985a6c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
140 additions
and
142 deletions
+140
-142
wcfs/internal/xbtree/xbtreetest/rtree.go
wcfs/internal/xbtree/xbtreetest/rtree.go
+1
-1
wcfs/internal/xbtree/xbtreetest/treeenv.go
wcfs/internal/xbtree/xbtreetest/treeenv.go
+29
-29
wcfs/internal/xbtree/δbtail_test.go
wcfs/internal/xbtree/δbtail_test.go
+110
-112
No files found.
wcfs/internal/xbtree/xbtreetest/rtree.go
View file @
7ed177e4
...
...
@@ -70,7 +70,7 @@ func (rbs RBucketSet) Get(k Key) *RBucket {
}
rb
:=
rbs
[
i
]
if
!
(
rb
.
Keycov
.
Lo
<=
k
&&
k
<=
rb
.
Keycov
.
Hi_
)
{
if
!
rb
.
Keycov
.
Has
(
k
)
{
panicf
(
"BUG: get(%v) -> %s; coverage: %s"
,
k
,
rb
.
Keycov
,
rbs
.
coverage
())
}
...
...
wcfs/internal/xbtree/xbtreetest/treeenv.go
View file @
7ed177e4
...
...
@@ -42,7 +42,7 @@ type T struct {
work
string
// working directory
treeSrv
*
TreeSrv
zstor
zodb
.
IStorage
db
*
zodb
.
DB
DB
*
zodb
.
DB
// all committed trees
commitv
[]
*
Commit
...
...
@@ -50,13 +50,13 @@ type T struct {
// Commit represent test commit changing a tree.
type
Commit
struct
{
tree
string
// the tree in topology-encoding
prev
*
Commit
// previous commit
at
zodb
.
Tid
// commit revision
δZ
*
zodb
.
EventCommit
// raw ZODB changes; δZ.tid == at
xkv
RBucketSet
// full tree state as of @at
δxkv
map
[
Key
]
Δstring
// full tree-diff against parent
blkDataTab
map
[
zodb
.
Oid
]
string
// full snapshot of all ZBlk data @at XXX -> zblkDataTab
Tree
string
// the tree in topology-encoding
Prev
*
Commit
// previous commit
At
zodb
.
Tid
// commit revision
ΔZ
*
zodb
.
EventCommit
// raw ZODB changes; δZ.tid == at
Xkv
RBucketSet
// full tree state as of @at
Δxkv
map
[
Key
]
Δstring
// full tree-diff against parent
zblkDataTab
map
[
zodb
.
Oid
]
string
// full snapshot of all ZBlk data @at
// δzblkData map[zodb.Oid]Δstring // full diff for zblkData against parent XXX ?
}
...
...
@@ -81,25 +81,25 @@ func NewT(t *testing.T) *T {
err
:=
tt
.
zstor
.
Close
();
X
(
err
)
})
tt
.
db
=
zodb
.
NewDB
(
tt
.
zstor
,
&
zodb
.
DBOptions
{
tt
.
DB
=
zodb
.
NewDB
(
tt
.
zstor
,
&
zodb
.
DBOptions
{
// We need objects to be cached, because otherwise it is too
// slow to run the test for many testcases, especially
// xverifyΔBTail_rebuild.
CacheControl
:
&
tZODBCacheEverything
{},
})
t
.
Cleanup
(
func
()
{
err
:=
tt
.
db
.
Close
();
X
(
err
)
err
:=
tt
.
DB
.
Close
();
X
(
err
)
})
head
:=
tt
.
treeSrv
.
head
t1
:=
&
Commit
{
tree
:
"T/B:"
,
// treegen.py creates the tree as initially empty
prev
:
nil
,
at
:
head
,
xkv
:
xGetTree
(
tt
.
db
,
head
,
tt
.
Root
()),
blkDataTab
:
xGetBlkDataTab
(
tt
.
db
,
head
),
δZ
:
nil
,
δxkv
:
nil
,
Tree
:
"T/B:"
,
// treegen.py creates the tree as initially empty
Prev
:
nil
,
At
:
head
,
Xkv
:
xGetTree
(
tt
.
DB
,
head
,
tt
.
Root
()),
zblkDataTab
:
xGetBlkDataTab
(
tt
.
DB
,
head
),
ΔZ
:
nil
,
Δxkv
:
nil
,
}
tt
.
commitv
=
[]
*
Commit
{
t1
}
...
...
@@ -152,7 +152,7 @@ func (t *T) CommitTree(tree string) *Commit {
// if the tree does not exist yet - report its structure as empty
var
xkv
RBucketSet
if
tree
!=
DEL
{
xkv
=
xGetTree
(
t
.
db
,
δZ
.
Tid
,
t
.
Root
())
xkv
=
xGetTree
(
t
.
DB
,
δZ
.
Tid
,
t
.
Root
())
}
else
{
// empty tree with real treeRoot as oid even though the tree is
// deleted. Having real oid in the root tests that after deletion,
...
...
@@ -178,16 +178,16 @@ func (t *T) CommitTree(tree string) *Commit {
}
ttree
:=
&
Commit
{
tree
:
tree
,
at
:
δZ
.
Tid
,
δZ
:
δZ
,
xkv
:
xkv
,
blkDataTab
:
xGetBlkDataTab
(
t
.
db
,
δZ
.
Tid
),
Tree
:
tree
,
At
:
δZ
.
Tid
,
ΔZ
:
δZ
,
Xkv
:
xkv
,
zblkDataTab
:
xGetBlkDataTab
(
t
.
DB
,
δZ
.
Tid
),
}
tprev
:=
t
.
Head
()
ttree
.
p
rev
=
tprev
ttree
.
δxkv
=
kvdiff
(
tprev
.
xkv
.
Flatten
(),
ttree
.
x
kv
.
Flatten
())
ttree
.
P
rev
=
tprev
ttree
.
Δxkv
=
kvdiff
(
tprev
.
Xkv
.
Flatten
(),
ttree
.
X
kv
.
Flatten
())
t
.
commitv
=
append
(
t
.
commitv
,
ttree
)
...
...
@@ -242,16 +242,16 @@ func xGetBlkDataTab(db *zodb.DB, at zodb.Tid) map[zodb.Oid]string {
return
blkDataTab
}
//
xg
etBlkData loads blk data for ZBlk<oid> @t.at
//
XG
etBlkData loads blk data for ZBlk<oid> @t.at
//
// For speed the load is done via preloaded t.blkDataTab instead of access to the DB.
func
(
t
*
Commit
)
xg
etBlkData
(
oid
zodb
.
Oid
)
string
{
func
(
t
*
Commit
)
XG
etBlkData
(
oid
zodb
.
Oid
)
string
{
if
oid
==
VDEL
{
return
DEL
}
data
,
ok
:=
t
.
blkDataTab
[
oid
]
data
,
ok
:=
t
.
z
blkDataTab
[
oid
]
if
!
ok
{
exc
.
Raisef
(
"getBlkData ZBlk<%s> @%s: no such ZBlk"
,
oid
,
t
.
a
t
)
exc
.
Raisef
(
"getBlkData ZBlk<%s> @%s: no such ZBlk"
,
oid
,
t
.
A
t
)
}
return
data
}
...
...
wcfs/internal/xbtree/δbtail_test.go
View file @
7ed177e4
...
...
@@ -144,8 +144,8 @@ func XGetδKV(t1, t2 *xbtreetest.Commit, δkvOid map[Key]ΔValue) map[Key]Δstri
δkv
:=
make
(
map
[
Key
]
Δstring
,
len
(
δkvOid
))
for
k
,
δvOid
:=
range
δkvOid
{
δkv
[
k
]
=
Δstring
{
Old
:
t1
.
xg
etBlkData
(
δvOid
.
Old
),
New
:
t2
.
xg
etBlkData
(
δvOid
.
New
),
Old
:
t1
.
XG
etBlkData
(
δvOid
.
Old
),
New
:
t2
.
XG
etBlkData
(
δvOid
.
New
),
}
}
return
δkv
...
...
@@ -225,7 +225,7 @@ func KAdj(t1, t2 *xbtreetest.Commit, keysv ...setKey) (kadj KAdjMatrix) {
kadj21
:=
_KAdj
(
t2
,
t1
,
keysv
...
)
if
!
reflect
.
DeepEqual
(
kadj12
,
kadj21
)
{
panicf
(
"KAdj not symmetric:
\n
t1: %s
\n
t2: %s
\n
kadj12: %v
\n
kadj21: %v"
,
t1
.
tree
,
t2
.
t
ree
,
kadj12
,
kadj21
)
t1
.
Tree
,
t2
.
T
ree
,
kadj12
,
kadj21
)
}
return
kadj12
}
...
...
@@ -249,8 +249,8 @@ func _KAdj(t1, t2 *xbtreetest.Commit, keysv ...setKey) (kadj KAdjMatrix) {
}
debugfKAdj
(
"
\n\n
_KAdj
\n
"
)
debugfKAdj
(
"t1: %s
\n
"
,
t1
.
t
ree
)
debugfKAdj
(
"t2: %s
\n
"
,
t2
.
t
ree
)
debugfKAdj
(
"t1: %s
\n
"
,
t1
.
T
ree
)
debugfKAdj
(
"t2: %s
\n
"
,
t2
.
T
ree
)
debugfKAdj
(
"keys: %s
\n
"
,
keys
)
defer
func
()
{
debugfKAdj
(
"kadj -> %v
\n
"
,
kadj
)
...
...
@@ -273,59 +273,57 @@ func _KAdj(t1, t2 *xbtreetest.Commit, keysv ...setKey) (kadj KAdjMatrix) {
debugfKAdj
(
"q1: %s
\t
done1: %s
\n
"
,
q1
,
done1
)
debugfKAdj
(
"q2: %s
\t
done2: %s
\n
"
,
q2
,
done2
)
for
_
,
r1
:=
range
q1
.
AllRanges
()
{
lo1
:=
r1
.
l
o
lo1
:=
r1
.
L
o
for
{
b1
:=
t1
.
x
kv
.
Get
(
lo1
)
b1
:=
t1
.
X
kv
.
Get
(
lo1
)
debugfKAdj
(
" b1: %s
\n
"
,
b1
)
for
k_
:=
range
keys
{
if
b1
.
lo
<=
k_
&&
k_
<=
b1
.
hi_
{
if
b1
.
Keycov
.
Has
(
k_
)
{
adj1
.
Add
(
k_
)
debugfKAdj
(
" adj1 += %s
\t
-> %s
\n
"
,
kstr
(
k_
),
adj1
)
}
}
b1r
:=
blib
.
KeyRange
{
b1
.
lo
,
b1
.
hi_
}
done1
.
AddRange
(
b1r
)
done1
.
AddRange
(
b1
.
Keycov
)
// q2 |= (b1.keyrange \ done2)
δq2
:=
&
blib
.
RangedKeySet
{}
δq2
.
AddRange
(
b1
r
)
δq2
.
AddRange
(
b1
.
Keycov
)
δq2
.
DifferenceInplace
(
done2
)
q2
.
UnionInplace
(
δq2
)
debugfKAdj
(
"q2 += %s
\t
-> %s
\n
"
,
δq2
,
q2
)
// continue with next right bucket until r1 coverage is complete
if
r1
.
hi_
<=
b1
.
h
i_
{
if
r1
.
Hi_
<=
b1
.
Keycov
.
H
i_
{
break
}
lo1
=
b1
.
h
i_
+
1
lo1
=
b1
.
Keycov
.
H
i_
+
1
}
}
q1
.
Clear
()
for
_
,
r2
:=
range
q2
.
AllRanges
()
{
lo2
:=
r2
.
l
o
lo2
:=
r2
.
L
o
for
{
b2
:=
t2
.
x
kv
.
Get
(
lo2
)
b2
:=
t2
.
X
kv
.
Get
(
lo2
)
debugfKAdj
(
" b2: %s
\n
"
,
b2
)
for
k_
:=
range
keys
{
if
b2
.
lo
<=
k_
&&
k_
<=
b2
.
hi_
{
if
b2
.
Keycov
.
Has
(
k_
)
{
adj2
.
Add
(
k_
)
debugfKAdj
(
" adj2 += %s
\t
-> %s
\n
"
,
kstr
(
k_
),
adj2
)
}
}
b2r
:=
blib
.
KeyRange
{
b2
.
lo
,
b2
.
hi_
}
done2
.
AddRange
(
b2r
)
done2
.
AddRange
(
b2
.
Keycov
)
// q1 |= (b2.keyrange \ done1)
δq1
:=
&
blib
.
RangedKeySet
{}
δq1
.
AddRange
(
b2
r
)
δq1
.
AddRange
(
b2
.
Keycov
)
δq1
.
DifferenceInplace
(
done1
)
q1
.
UnionInplace
(
δq1
)
debugfKAdj
(
"q1 += %s
\t
-> %s
\n
"
,
δq1
,
q1
)
// continue with next right bucket until r2 coverage is complete
if
r2
.
hi_
<=
b2
.
h
i_
{
if
r2
.
Hi_
<=
b2
.
Keycov
.
H
i_
{
break
}
lo2
=
b2
.
h
i_
+
1
lo2
=
b2
.
Keycov
.
H
i_
+
1
}
}
q2
.
Clear
()
...
...
@@ -348,7 +346,7 @@ func _KAdj(t1, t2 *xbtreetest.Commit, keysv ...setKey) (kadj KAdjMatrix) {
func
xverifyΔBTail_Update
(
t
*
testing
.
T
,
subj
string
,
db
*
zodb
.
DB
,
treeRoot
zodb
.
Oid
,
t1
,
t2
*
xbtreetest
.
Commit
)
{
// verify transition at1->at2 for all initial states of tracked {keys} from kv1 + kv2 + ∞
t
.
Run
(
fmt
.
Sprintf
(
"Update/%s→%s"
,
t1
.
tree
,
t2
.
t
ree
),
func
(
t
*
testing
.
T
)
{
t
.
Run
(
fmt
.
Sprintf
(
"Update/%s→%s"
,
t1
.
Tree
,
t2
.
T
ree
),
func
(
t
*
testing
.
T
)
{
allKeys
:=
allTestKeys
(
t1
,
t2
)
allKeyv
:=
allKeys
.
SortedElements
()
...
...
@@ -376,8 +374,8 @@ func xverifyΔBTail_Update1(t *testing.T, subj string, db *zodb.DB, treeRoot zod
X
:=
exc
.
Raiseif
//t.Logf("\n>>> Track=%s\n", initialTrackedKeys)
δZ
:=
t2
.
δ
Z
d12
:=
t2
.
δ
xkv
δZ
:=
t2
.
Δ
Z
d12
:=
t2
.
Δ
xkv
var
TrackedδZ
setKey
=
nil
var
kadjTrackedδZ
setKey
=
nil
...
...
@@ -409,23 +407,23 @@ func xverifyΔBTail_Update1(t *testing.T, subj string, db *zodb.DB, treeRoot zod
// δbtail @at1 with initial tracked set
δbtail
:=
NewΔBtail
(
t1
.
a
t
,
db
)
δbtail
:=
NewΔBtail
(
t1
.
A
t
,
db
)
xtrackKeys
(
δbtail
,
t1
,
initialTrackedKeys
)
// TrackedδZ = Tracked ^ δZ (i.e. a tracked node has changed, or its coverage was changed)
TrackedδZ
=
setKey
{}
for
k
:=
range
initialTrackedKeys
{
leaf1
:=
t1
.
x
kv
.
Get
(
k
)
oid1
:=
leaf1
.
o
id
leaf1
:=
t1
.
X
kv
.
Get
(
k
)
oid1
:=
leaf1
.
O
id
if
oid1
==
zodb
.
InvalidOid
{
// embedded bucket
oid1
=
leaf1
.
parent
.
o
id
oid1
=
leaf1
.
Parent
.
O
id
}
leaf2
:=
t2
.
x
kv
.
Get
(
k
)
oid2
:=
leaf2
.
o
id
leaf2
:=
t2
.
X
kv
.
Get
(
k
)
oid2
:=
leaf2
.
O
id
if
oid2
==
zodb
.
InvalidOid
{
// embedded bucket
oid2
=
leaf2
.
parent
.
o
id
oid2
=
leaf2
.
Parent
.
O
id
}
if
δZset
.
Has
(
oid1
)
||
δZset
.
Has
(
oid2
)
||
(
blib
.
KeyRange
{
leaf1
.
lo
,
leaf1
.
hi_
}
!=
blib
.
KeyRange
{
leaf2
.
lo
,
leaf2
.
hi_
}
)
{
if
δZset
.
Has
(
oid1
)
||
δZset
.
Has
(
oid2
)
||
(
leaf1
.
Keycov
!=
leaf2
.
Keycov
)
{
TrackedδZ
.
Add
(
k
)
}
}
...
...
@@ -458,8 +456,8 @@ func xverifyΔBTail_Update1(t *testing.T, subj string, db *zodb.DB, treeRoot zod
// trackSet1 = xkv1[tracked1]
// trackSet2 = xkv2[tracked2] ( = xkv2[kadj[tracked1]]
trackSet1
,
tkeyCov1
:=
trackSetWithCov
(
t1
.
x
kv
,
initialTrackedKeys
)
trackSet2
,
tkeyCov2
:=
trackSetWithCov
(
t2
.
x
kv
,
initialTrackedKeys
.
Union
(
kadjTrackedδZ
))
trackSet1
,
tkeyCov1
:=
trackSetWithCov
(
t1
.
X
kv
,
initialTrackedKeys
)
trackSet2
,
tkeyCov2
:=
trackSetWithCov
(
t2
.
X
kv
,
initialTrackedKeys
.
Union
(
kadjTrackedδZ
))
// verify δbtail.trackSet against @at1
δbtail
.
assertTrack
(
t
,
"1"
,
ø
,
trackSet1
)
...
...
@@ -608,20 +606,20 @@ func (δBtail *ΔBtail) assertTrack(t *testing.T, subj string, trackSetOK blib.P
//
// It also exercises rebuild phase of ΔBtail.Update.
func
xverifyΔBTail_rebuild
(
t
*
testing
.
T
,
db
*
zodb
.
DB
,
treeRoot
zodb
.
Oid
,
t0
,
t1
,
t2
*
xbtreetest
.
Commit
)
{
t
.
Run
(
fmt
.
Sprintf
(
"rebuild/%s→%s"
,
t0
.
tree
,
t1
.
t
ree
),
func
(
t
*
testing
.
T
)
{
t
.
Run
(
fmt
.
Sprintf
(
"rebuild/%s→%s"
,
t0
.
Tree
,
t1
.
T
ree
),
func
(
t
*
testing
.
T
)
{
tAllKeys
:=
allTestKeys
(
t0
,
t1
,
t2
)
tAllKeyv
:=
tAllKeys
.
SortedElements
()
// tid -> "at_i"
xat
:=
map
[
zodb
.
Tid
]
string
{
t0
.
a
t
:
"at0"
,
t1
.
a
t
:
"at1"
,
t2
.
a
t
:
"at2"
,
t0
.
A
t
:
"at0"
,
t1
.
A
t
:
"at1"
,
t2
.
A
t
:
"at2"
,
}
//fmt.Printf("@%s: %v\n", xat[t0.
at], t0.x
kv.Flatten())
//fmt.Printf("@%s: %v\n", xat[t1.
at], t1.x
kv.Flatten())
//fmt.Printf("@%s: %v\n", xat[t2.
at], t2.x
kv.Flatten())
//fmt.Printf("@%s: %v\n", xat[t0.
At], t0.X
kv.Flatten())
//fmt.Printf("@%s: %v\n", xat[t1.
At], t1.X
kv.Flatten())
//fmt.Printf("@%s: %v\n", xat[t2.
At], t2.X
kv.Flatten())
kadj10
:=
KAdj
(
t1
,
t0
,
allTestKeys
(
t0
,
t1
,
t2
))
kadj21
:=
KAdj
(
t2
,
t1
,
allTestKeys
(
t0
,
t1
,
t2
))
...
...
@@ -644,17 +642,17 @@ func xverifyΔBTail_rebuild(t *testing.T, db *zodb.DB, treeRoot zodb.Oid, t0, t1
keys1_0
:=
kadj10
.
Map
(
keys1
)
δkv1_1
:=
map
[
Key
]
Δstring
{}
for
k
:=
range
keys1_0
{
δv
,
ok
:=
t1
.
δ
xkv
[
k
]
δv
,
ok
:=
t1
.
Δ
xkv
[
k
]
if
ok
{
δkv1_1
[
k
]
=
δv
}
}
Tkeys1
:=
t
1
.
xkv
.
trackSet
(
keys1
)
Tkeys1_0
:=
t
1
.
xkv
.
trackSet
(
keys1_0
)
Tkeys1
:=
t
rackSet
(
t1
.
Xkv
,
keys1
)
Tkeys1_0
:=
t
rackSet
(
t1
.
Xkv
,
keys1_0
)
t
.
Run
(
fmt
.
Sprintf
(
" T%s;R"
,
keys1
),
func
(
t
*
testing
.
T
)
{
δbtail
:=
NewΔBtail
(
t0
.
a
t
,
db
)
δbtail
:=
NewΔBtail
(
t0
.
A
t
,
db
)
// assert trackSet=ø, trackNew=ø, vδB=[]
δbtail
.
assertTrack
(
t
,
"@at0"
,
ø
,
ø
)
...
...
@@ -674,7 +672,7 @@ func xverifyΔBTail_rebuild(t *testing.T, db *zodb.DB, treeRoot zodb.Oid, t0, t1
/*trackSet=*/
Tkeys1_0
,
/*vδT=*/
δkv1_1
)
t
.
Run
((
" →"
+
t2
.
t
ree
),
func
(
t
*
testing
.
T
)
{
t
.
Run
((
" →"
+
t2
.
T
ree
),
func
(
t
*
testing
.
T
)
{
// keys1R2 is full set of keys that should become tracked after
// Update() (which includes rebuild)
keys1R2
:=
kadj12
.
Map
(
keys1
)
...
...
@@ -690,17 +688,17 @@ func xverifyΔBTail_rebuild(t *testing.T, db *zodb.DB, treeRoot zodb.Oid, t0, t1
δkv1_k1R2
:=
map
[
Key
]
Δstring
{}
δkv2_k1R2
:=
map
[
Key
]
Δstring
{}
for
k
:=
range
keys1R2
{
δv1
,
ok
:=
t1
.
δ
xkv
[
k
]
δv1
,
ok
:=
t1
.
Δ
xkv
[
k
]
if
ok
{
δkv1_k1R2
[
k
]
=
δv1
}
δv2
,
ok
:=
t2
.
δ
xkv
[
k
]
δv2
,
ok
:=
t2
.
Δ
xkv
[
k
]
if
ok
{
δkv2_k1R2
[
k
]
=
δv2
}
}
Tkeys1R2
:=
t
2
.
xkv
.
trackSet
(
keys1R2
)
Tkeys1R2
:=
t
rackSet
(
t2
.
Xkv
,
keys1R2
)
xverifyΔBTail_rebuild_U
(
t
,
δbtail
,
treeRoot
,
t1
,
t2
,
xat
,
/*trackSet=*/
Tkeys1R2
,
...
...
@@ -735,16 +733,16 @@ func xverifyΔBTail_rebuild(t *testing.T, db *zodb.DB, treeRoot zodb.Oid, t0, t1
keys12R2
=
keys12R2_
}
Tkeys2
:=
t
2
.
xkv
.
trackSet
(
keys2
)
Tkeys12R2
:=
t
2
.
xkv
.
trackSet
(
keys12R2
)
Tkeys2
:=
t
rackSet
(
t2
.
Xkv
,
keys2
)
Tkeys12R2
:=
t
rackSet
(
t2
.
Xkv
,
keys12R2
)
/*
fmt.Printf("\n\n\nKKK\nkeys1=%s keys2=%s\n", keys1, keys2)
fmt.Printf("keys1R2: %s\n", keys1R2)
fmt.Printf("keys12R2: %s\n", keys12R2)
fmt.Printf("t0.
xkv: %v\n", t0.x
kv)
fmt.Printf("t1.
xkv: %v\n", t1.x
kv)
fmt.Printf("t2.
xkv: %v\n", t2.x
kv)
fmt.Printf("t0.
Xkv: %v\n", t0.X
kv)
fmt.Printf("t1.
Xkv: %v\n", t1.X
kv)
fmt.Printf("t2.
Xkv: %v\n", t2.X
kv)
fmt.Printf("kadj21: %v\n", kadj21)
fmt.Printf("kadj12: %v\n", kadj12)
fmt.Printf("Tkeys2 -> %s\n", Tkeys2)
...
...
@@ -755,14 +753,14 @@ func xverifyΔBTail_rebuild(t *testing.T, db *zodb.DB, treeRoot zodb.Oid, t0, t1
// δkvX_k12R2 = tX.δxkv / keys12R2
δkv1_k12R2
:=
make
(
map
[
Key
]
Δstring
,
len
(
t1
.
δ
xkv
))
δkv2_k12R2
:=
make
(
map
[
Key
]
Δstring
,
len
(
t2
.
δ
xkv
))
δkv1_k12R2
:=
make
(
map
[
Key
]
Δstring
,
len
(
t1
.
Δ
xkv
))
δkv2_k12R2
:=
make
(
map
[
Key
]
Δstring
,
len
(
t2
.
Δ
xkv
))
for
k
:=
range
keys12R2
{
δv1
,
ok
:=
t1
.
δ
xkv
[
k
]
δv1
,
ok
:=
t1
.
Δ
xkv
[
k
]
if
ok
{
δkv1_k12R2
[
k
]
=
δv1
}
δv2
,
ok
:=
t2
.
δ
xkv
[
k
]
δv2
,
ok
:=
t2
.
Δ
xkv
[
k
]
if
ok
{
δkv2_k12R2
[
k
]
=
δv2
}
...
...
@@ -797,10 +795,10 @@ func xverifyΔBTail_rebuild_U(t *testing.T, δbtail *ΔBtail, treeRoot zodb.Oid,
X
:=
exc
.
Raiseif
ø
:=
blib
.
PPTreeSubSet
{}
subj
:=
fmt
.
Sprintf
(
"after Update(@%s→@%s)"
,
xat
[
ti
.
at
],
xat
[
tj
.
a
t
])
subj
:=
fmt
.
Sprintf
(
"after Update(@%s→@%s)"
,
xat
[
ti
.
At
],
xat
[
tj
.
A
t
])
// Update ati -> atj
δB
,
err
:=
δbtail
.
Update
(
tj
.
δ
Z
);
X
(
err
)
δB
,
err
:=
δbtail
.
Update
(
tj
.
Δ
Z
);
X
(
err
)
δbtail
.
assertTrack
(
t
,
subj
,
trackSet
,
ø
)
assertΔTtail
(
t
,
subj
,
δbtail
,
tj
,
treeRoot
,
xat
,
vδTok
...
)
...
...
@@ -825,8 +823,8 @@ func xverifyΔBTail_rebuild_U(t *testing.T, δbtail *ΔBtail, treeRoot zodb.Oid,
if
ok
{
δT
=
XGetδKV
(
ti
,
tj
,
δToid
)
}
if
δB
.
Rev
!=
tj
.
a
t
{
t
.
Errorf
(
"%s: δB.Rev: have %s ; want %s"
,
subj
,
δB
.
Rev
,
tj
.
a
t
)
if
δB
.
Rev
!=
tj
.
A
t
{
t
.
Errorf
(
"%s: δB.Rev: have %s ; want %s"
,
subj
,
δB
.
Rev
,
tj
.
A
t
)
}
if
len
(
δB
.
ΔByRoot
)
!=
δrootsOK
{
t
.
Errorf
(
"%s: len(δB.ΔByRoot) != %d ; δroots=%v"
,
subj
,
δrootsOK
,
δroots
)
...
...
@@ -844,7 +842,7 @@ func xverifyΔBTail_rebuild_TR(t *testing.T, δbtail *ΔBtail, tj *xbtreetest.Co
// Track(keys)
xtrackKeys
(
δbtail
,
tj
,
keys
)
subj
:=
fmt
.
Sprintf
(
"@%s: after Track%v"
,
xat
[
tj
.
a
t
],
keys
)
subj
:=
fmt
.
Sprintf
(
"@%s: after Track%v"
,
xat
[
tj
.
A
t
],
keys
)
δbtail
.
assertTrack
(
t
,
subj
,
trackSet
,
trackNew
)
δbtail
.
rebuildAll
()
...
...
@@ -867,16 +865,16 @@ func assertΔTtail(t *testing.T, subj string, δbtail *ΔBtail, tj *xbtreetest.C
l
:=
len
(
vδTok
)
var
vatOK
[]
zodb
.
Tid
var
vδTok_
[]
map
[
Key
]
Δstring
at2t
:=
map
[
zodb
.
Tid
]
*
xbtreetest
.
Commit
{
tj
.
a
t
:
tj
}
at2t
:=
map
[
zodb
.
Tid
]
*
xbtreetest
.
Commit
{
tj
.
A
t
:
tj
}
t0
:=
tj
for
i
:=
0
;
i
<
l
;
i
++
{
// empty vδTok entries means they should be absent in vδT
if
δTok
:=
vδTok
[
l
-
i
-
1
];
len
(
δTok
)
!=
0
{
vatOK
=
append
([]
zodb
.
Tid
{
t0
.
a
t
},
vatOK
...
)
vatOK
=
append
([]
zodb
.
Tid
{
t0
.
A
t
},
vatOK
...
)
vδTok_
=
append
([]
map
[
Key
]
Δstring
{
δTok
},
vδTok_
...
)
}
t0
=
t0
.
p
rev
at2t
[
t0
.
a
t
]
=
t0
t0
=
t0
.
P
rev
at2t
[
t0
.
A
t
]
=
t0
}
vδTok
=
vδTok_
δTtail
,
ok
:=
δbtail
.
vδTbyRoot
[
treeRoot
]
...
...
@@ -888,7 +886,7 @@ func assertΔTtail(t *testing.T, subj string, δbtail *ΔBtail, tj *xbtreetest.C
l
=
len
(
vδToid
)
var
vat
[]
zodb
.
Tid
var
vδT
[]
map
[
Key
]
Δstring
atPrev
:=
t0
.
a
t
atPrev
:=
t0
.
A
t
for
_
,
δToid
:=
range
vδToid
{
vat
=
append
(
vat
,
δToid
.
Rev
)
δT
:=
XGetδKV
(
at2t
[
atPrev
],
at2t
[
δToid
.
Rev
],
δToid
.
ΔKV
)
// {} k -> δ(ZBlk(oid).data)
...
...
@@ -938,8 +936,8 @@ func assertΔTtail(t *testing.T, subj string, δbtail *ΔBtail, tj *xbtreetest.C
func
xtrackKeys
(
δbtail
*
ΔBtail
,
t
*
xbtreetest
.
Commit
,
keys
setKey
)
{
X
:=
exc
.
Raiseif
head
:=
δbtail
.
Head
()
if
head
!=
t
.
a
t
{
panicf
(
"BUG: δbtail.head: %s ; t.at: %s"
,
head
,
t
.
a
t
)
if
head
!=
t
.
A
t
{
panicf
(
"BUG: δbtail.head: %s ; t.at: %s"
,
head
,
t
.
A
t
)
}
for
k
:=
range
keys
{
...
...
@@ -953,7 +951,7 @@ func xtrackKeys(δbtail *ΔBtail, t *xbtreetest.Commit, keys setKey) {
// continues to be tracked and all keys migrate to holes in the
// tracking set. By aligning initial state to the same as after
// T1->ø, we test what will happen on ø->T2.
b
:=
t
.
x
kv
.
Get
(
k
)
b
:=
t
.
X
kv
.
Get
(
k
)
err
:=
δbtail
.
track
(
k
,
b
.
Path
());
X
(
err
)
}
}
...
...
@@ -963,18 +961,18 @@ func xtrackKeys(δbtail *ΔBtail, t *xbtreetest.Commit, keys setKey) {
// XXX kill
/*
func ___xverifyΔBTail_GetAt(t *testing.T, db *zodb.DB, treeRoot zodb.Oid, vt ...*xbtreetest.Commit) {
subj := vt[0].
t
ree
subj := vt[0].
T
ree
for _, t := range vt[1:] {
subj += "→" + t.
t
ree
subj += "→" + t.
T
ree
}
t.Run(fmt.Sprintf("Get/%s", subj), func(t *testing.T) {
// tid -> "at_i"
xat := map[zodb.Tid]string{}
for i := range vt {
xat[vt[i].
a
t] = fmt.Sprintf("at%d", i)
xat[vt[i].
A
t] = fmt.Sprintf("at%d", i)
fmt.Printf("@%s: %v\n", xat[vt[i].
at], vt[i].x
kv.Flatten())
fmt.Printf("@%s: %v\n", xat[vt[i].
At], vt[i].X
kv.Flatten())
}
tkeys := allTestKeys(vt...)
...
...
@@ -999,15 +997,15 @@ func xverifyΔBTail_GetAt1(t *testing.T, db *zodb.DB, treeRoot zodb.Oid, vt []*x
X := exc.Raiseif
// t1->t2-> ... -> tn
δbtail := NewΔBtail(vt[0].
a
t, db)
δbtail := NewΔBtail(vt[0].
A
t, db)
for i := 1; i < len(vt); i++ {
_, err := δbtail.Update(vt[i].
δ
Z); X(err)
_, err := δbtail.Update(vt[i].
Δ
Z); X(err)
}
// Track(keys)
txn, ctx := transaction.New(context.Background())
defer txn.Abort()
zconn, err := db.Open(ctx, &zodb.ConnOptions{At: vt[len(vt)-1].
a
t}); X(err)
zconn, err := db.Open(ctx, &zodb.ConnOptions{At: vt[len(vt)-1].
A
t}); X(err)
xtree, err := zconn.Get(ctx, treeRoot); X(err)
ztree := xtree.(*Tree)
...
...
@@ -1018,21 +1016,21 @@ func xverifyΔBTail_GetAt1(t *testing.T, db *zodb.DB, treeRoot zodb.Oid, vt []*x
// verify GetAt(k, @at) for all keys and @at
for i := 1; i < len(vt); i++ {
at := vt[i].
a
t
at := vt[i].
A
t
for _, k := range keys.SortedElements() {
vOid, ok, rev, revExact, err := δbtail.GetAt(ctx, ztree, k, at); X(err)
v := xzgetBlkDataAt(db, vOid, rev)
v_, ok_ := vt[i].
x
kv.Get(k).kv[k]
rev_, revExact_ := vt[i].
a
t, false
v_, ok_ := vt[i].
X
kv.Get(k).kv[k]
rev_, revExact_ := vt[i].
A
t, false
for j := i-1; j >= 0; j-- {
v__ := vt[j].
x
kv.Get(k).kv[k]
v__ := vt[j].
X
kv.Get(k).kv[k]
if v__ != v_ {
rev_ = vt[j+1].
a
t
rev_ = vt[j+1].
A
t
revExact_ = true
break
}
rev_ = vt[j].
a
t
rev_ = vt[j].
A
t
}
if v == "" { v = DEL }
...
...
@@ -1090,12 +1088,12 @@ func testΔBTail(t_ *testing.T, testq chan ΔBTestEntry) {
t1
:=
t
.
Head
()
t2
:=
t
.
CommitTree
(
test
.
tree
)
subj
:=
fmt
.
Sprintf
(
"%s -> %s"
,
t1
.
tree
,
t2
.
t
ree
)
subj
:=
fmt
.
Sprintf
(
"%s -> %s"
,
t1
.
Tree
,
t2
.
T
ree
)
//t.Logf("\n\n\n**** %s ****\n\n", subj)
// KAdj
if
kadjOK
:=
test
.
kadjOK
;
kadjOK
!=
nil
{
t
.
Run
(
fmt
.
Sprintf
(
"KAdj/%s→%s"
,
t1
.
tree
,
t2
.
t
ree
),
func
(
t
*
testing
.
T
)
{
t
.
Run
(
fmt
.
Sprintf
(
"KAdj/%s→%s"
,
t1
.
Tree
,
t2
.
T
ree
),
func
(
t
*
testing
.
T
)
{
kadj
:=
KAdj
(
t1
,
t2
)
if
!
reflect
.
DeepEqual
(
kadj
,
kadjOK
)
{
t
.
Fatalf
(
"BUG: computed kadj is wrong:
\n
kadjOK: %v
\n
kadj : %v
\n\n
"
,
kadjOK
,
kadj
)
...
...
@@ -1105,12 +1103,12 @@ func testΔBTail(t_ *testing.T, testq chan ΔBTestEntry) {
// ΔBTail.Update
if
test
.
flags
&
ΔBTest_SkipUpdate
==
0
{
xverifyΔBTail_Update
(
t
.
T
,
subj
,
t
.
db
,
t
.
Root
(),
t1
,
t2
)
xverifyΔBTail_Update
(
t
.
T
,
subj
,
t
.
DB
,
t
.
Root
(),
t1
,
t2
)
}
// ΔBTail.rebuild
if
t0
!=
nil
&&
(
test
.
flags
&
ΔBTest_SkipRebuild
==
0
)
{
xverifyΔBTail_rebuild
(
t
.
T
,
t
.
db
,
t
.
Root
(),
t0
,
t1
,
t2
)
xverifyΔBTail_rebuild
(
t
.
T
,
t
.
DB
,
t
.
Root
(),
t0
,
t1
,
t2
)
}
t0
,
t1
=
t1
,
t2
...
...
@@ -1280,7 +1278,7 @@ func TestΔBTail(t *testing.T) {
// * `ø -> Tree ...` (tree is created anew),
// * `... Tree -> ø` (tree is deleted), and
// * `Tree -> ø -> Tree` (tree is deleted and then recreated)
DEL
,
xbtreetest
.
DEL
,
// tree rotation
"T3/B2:b-B3:c,4:d"
,
...
...
@@ -1573,29 +1571,29 @@ func TestΔBtailForget(t_ *testing.T) {
t2
:=
t
.
CommitTree
(
"T2/B1:a-B2:b"
)
t3
:=
t
.
CommitTree
(
"T/B2:b"
)
δbtail
:=
NewΔBtail
(
t0
.
at
,
t
.
db
)
_
,
err
:=
δbtail
.
Update
(
t1
.
δ
Z
);
X
(
err
)
_
,
err
=
δbtail
.
Update
(
t2
.
δ
Z
);
X
(
err
)
δbtail
:=
NewΔBtail
(
t0
.
At
,
t
.
DB
)
_
,
err
:=
δbtail
.
Update
(
t1
.
Δ
Z
);
X
(
err
)
_
,
err
=
δbtail
.
Update
(
t2
.
Δ
Z
);
X
(
err
)
// start tracking. everything becomes tracked because t1's T/B1:a has [-∞,∞) coverage
// By starting tracking after t2 we verify vδBroots update in both Update and rebuild
_0
:=
setKey
{};
_0
.
Add
(
0
)
xtrackKeys
(
δbtail
,
t2
,
_0
)
_
,
err
=
δbtail
.
Update
(
t3
.
δ
Z
);
X
(
err
)
_
,
err
=
δbtail
.
Update
(
t3
.
Δ
Z
);
X
(
err
)
xat
:=
map
[
zodb
.
Tid
]
string
{
t0
.
a
t
:
"at0"
,
t1
.
a
t
:
"at1"
,
t2
.
a
t
:
"at2"
,
t3
.
a
t
:
"at3"
,
}
assertΔTtail
(
t
.
T
,
"init"
,
δbtail
,
t3
,
t
.
Root
(),
xat
,
t1
.
δxkv
,
t2
.
δxkv
,
t3
.
δ
xkv
)
δbtail
.
ForgetPast
(
t0
.
a
t
)
assertΔTtail
(
t
.
T
,
"forget ≤ at0"
,
δbtail
,
t3
,
t
.
Root
(),
xat
,
t1
.
δxkv
,
t2
.
δxkv
,
t3
.
δ
xkv
)
δbtail
.
ForgetPast
(
t1
.
a
t
)
assertΔTtail
(
t
.
T
,
"forget ≤ at1"
,
δbtail
,
t3
,
t
.
Root
(),
xat
,
t2
.
δxkv
,
t3
.
δ
xkv
)
δbtail
.
ForgetPast
(
t3
.
a
t
)
t0
.
A
t
:
"at0"
,
t1
.
A
t
:
"at1"
,
t2
.
A
t
:
"at2"
,
t3
.
A
t
:
"at3"
,
}
assertΔTtail
(
t
.
T
,
"init"
,
δbtail
,
t3
,
t
.
Root
(),
xat
,
t1
.
Δxkv
,
t2
.
Δxkv
,
t3
.
Δ
xkv
)
δbtail
.
ForgetPast
(
t0
.
A
t
)
assertΔTtail
(
t
.
T
,
"forget ≤ at0"
,
δbtail
,
t3
,
t
.
Root
(),
xat
,
t1
.
Δxkv
,
t2
.
Δxkv
,
t3
.
Δ
xkv
)
δbtail
.
ForgetPast
(
t1
.
A
t
)
assertΔTtail
(
t
.
T
,
"forget ≤ at1"
,
δbtail
,
t3
,
t
.
Root
(),
xat
,
t2
.
Δxkv
,
t3
.
Δ
xkv
)
δbtail
.
ForgetPast
(
t3
.
A
t
)
assertΔTtail
(
t
.
T
,
"forget ≤ at3"
,
δbtail
,
t3
,
t
.
Root
(),
xat
,
)
}
...
...
@@ -1609,15 +1607,15 @@ func TestΔBtailClone(t_ *testing.T) {
t0
:=
t
.
CommitTree
(
"T2/B1:a-B2:b"
)
t1
:=
t
.
CommitTree
(
"T2/B1:c-B2:d"
)
δbtail
:=
NewΔBtail
(
t0
.
at
,
t
.
db
)
_
,
err
:=
δbtail
.
Update
(
t1
.
δ
Z
);
X
(
err
)
δbtail
:=
NewΔBtail
(
t0
.
At
,
t
.
DB
)
_
,
err
:=
δbtail
.
Update
(
t1
.
Δ
Z
);
X
(
err
)
_2
:=
setKey
{};
_2
.
Add
(
2
)
xtrackKeys
(
δbtail
,
t1
,
_2
)
err
=
δbtail
.
rebuildAll
();
X
(
err
)
xat
:=
map
[
zodb
.
Tid
]
string
{
t0
.
a
t
:
"at0"
,
t1
.
a
t
:
"at1"
,
t0
.
A
t
:
"at0"
,
t1
.
A
t
:
"at1"
,
}
δkv1_1
:=
map
[
Key
]
Δstring
{
2
:
{
"b"
,
"d"
}}
...
...
@@ -1626,8 +1624,8 @@ func TestΔBtailClone(t_ *testing.T) {
assertΔTtail
(
t
.
T
,
"klon @at1"
,
δbklon
,
t1
,
t
.
Root
(),
xat
,
δkv1_1
)
t2
:=
t
.
CommitTree
(
"T/B1:b,2:a"
)
_
,
err
=
δbtail
.
Update
(
t2
.
δ
Z
);
X
(
err
)
xat
[
t2
.
a
t
]
=
"at2"
_
,
err
=
δbtail
.
Update
(
t2
.
Δ
Z
);
X
(
err
)
xat
[
t2
.
A
t
]
=
"at2"
δkv1_2
:=
map
[
Key
]
Δstring
{
1
:
{
"a"
,
"c"
},
2
:
{
"b"
,
"d"
}}
δkv2_2
:=
map
[
Key
]
Δstring
{
1
:
{
"c"
,
"b"
},
2
:
{
"d"
,
"a"
}}
...
...
@@ -1683,8 +1681,8 @@ func TestIntSets(t *testing.T) {
func
allTestKeys
(
vt
...*
xbtreetest
.
Commit
)
setKey
{
allKeys
:=
setKey
{};
allKeys
.
Add
(
KeyMax
)
// ∞ simulating ZBigFile.Size() query
for
_
,
t
:=
range
vt
{
for
_
,
b
:=
range
t
.
x
kv
{
for
k
:=
range
b
.
kv
{
for
_
,
b
:=
range
t
.
X
kv
{
for
k
:=
range
b
.
KV
{
allKeys
.
Add
(
k
)
}
}
...
...
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