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
eeeb2673
Commit
eeeb2673
authored
Sep 23, 2021
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
caa31ef6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
26 deletions
+39
-26
wcfs/internal/xbtree/δbtail.go
wcfs/internal/xbtree/δbtail.go
+17
-17
wcfs/internal/xbtree/δbtail_test.go
wcfs/internal/xbtree/δbtail_test.go
+22
-9
No files found.
wcfs/internal/xbtree/δbtail.go
View file @
eeeb2673
...
@@ -130,12 +130,12 @@ const debugΔBtail = false
...
@@ -130,12 +130,12 @@ const debugΔBtail = false
//
//
// See also zodb.ΔTail and zdata.ΔFtail
// See also zodb.ΔTail and zdata.ΔFtail
type
ΔBtail
struct
{
type
ΔBtail
struct
{
// raw ZODB changes; Kept to rebuild .
vδT
byRoot after new Track.
// raw ZODB changes; Kept to rebuild .byRoot after new Track.
// includes all changed objects, not only tracked ones.
// includes all changed objects, not only tracked ones.
δZtail
*
zodb
.
ΔTail
δZtail
*
zodb
.
ΔTail
vδBroots
[]
_ΔBroots
// [] (rev↑, roots changed in this rev)
vδBroots
[]
_ΔBroots
// [] (rev↑, roots changed in this rev)
vδT
byRoot
map
[
zodb
.
Oid
]
*
_ΔTtail
// {} root -> [] k/v change history; only for keys ∈ tracked subset
byRoot
map
[
zodb
.
Oid
]
*
_ΔTtail
// {} root -> [] k/v change history; only for keys ∈ tracked subset
// set of tracked nodes as of @head state.
// set of tracked nodes as of @head state.
// For this set all vδT are fully computed.
// For this set all vδT are fully computed.
...
@@ -195,7 +195,7 @@ func NewΔBtail(at0 zodb.Tid, db *zodb.DB) *ΔBtail {
...
@@ -195,7 +195,7 @@ func NewΔBtail(at0 zodb.Tid, db *zodb.DB) *ΔBtail {
return
&
ΔBtail
{
return
&
ΔBtail
{
δZtail
:
zodb
.
NewΔTail
(
at0
),
δZtail
:
zodb
.
NewΔTail
(
at0
),
vδBroots
:
nil
,
vδBroots
:
nil
,
vδTbyRoot
:
map
[
zodb
.
Oid
]
*
_ΔTtail
{},
byRoot
:
map
[
zodb
.
Oid
]
*
_ΔTtail
{},
trackSet
:
blib
.
PPTreeSubSet
{},
trackSet
:
blib
.
PPTreeSubSet
{},
trackNewRoots
:
setOid
{},
trackNewRoots
:
setOid
{},
db
:
db
,
db
:
db
,
...
@@ -229,10 +229,10 @@ func (orig *ΔBtail) Clone() *ΔBtail {
...
@@ -229,10 +229,10 @@ func (orig *ΔBtail) Clone() *ΔBtail {
klon
.
vδBroots
=
append
(
klon
.
vδBroots
,
klonδBroots
)
klon
.
vδBroots
=
append
(
klon
.
vδBroots
,
klonδBroots
)
}
}
//
vδT
byRoot
// byRoot
klon
.
vδTbyRoot
=
make
(
map
[
zodb
.
Oid
]
*
_ΔTtail
,
len
(
orig
.
vδT
byRoot
))
klon
.
byRoot
=
make
(
map
[
zodb
.
Oid
]
*
_ΔTtail
,
len
(
orig
.
byRoot
))
for
root
,
origΔTtail
:=
range
orig
.
vδT
byRoot
{
for
root
,
origΔTtail
:=
range
orig
.
byRoot
{
klon
.
vδT
byRoot
[
root
]
=
origΔTtail
.
Clone
()
klon
.
byRoot
[
root
]
=
origΔTtail
.
Clone
()
}
}
// trackSet, trackNewRoots
// trackSet, trackNewRoots
...
@@ -358,10 +358,10 @@ func (δBtail *ΔBtail) track(key Key, path []zodb.Oid) {
...
@@ -358,10 +358,10 @@ func (δBtail *ΔBtail) track(key Key, path []zodb.Oid) {
}
}
// queue path into trackNew
// queue path into trackNew
δTtail
,
ok
:=
δBtail
.
vδT
byRoot
[
root
]
δTtail
,
ok
:=
δBtail
.
byRoot
[
root
]
if
!
ok
{
if
!
ok
{
δTtail
=
newΔTtail
()
δTtail
=
newΔTtail
()
δBtail
.
vδT
byRoot
[
root
]
=
δTtail
δBtail
.
byRoot
[
root
]
=
δTtail
}
}
δBtail
.
trackNewRoots
.
Add
(
root
)
δBtail
.
trackNewRoots
.
Add
(
root
)
...
@@ -399,7 +399,7 @@ func (δBtail *ΔBtail) rebuild1IfNeeded(root zodb.Oid) error {
...
@@ -399,7 +399,7 @@ func (δBtail *ΔBtail) rebuild1IfNeeded(root zodb.Oid) error {
// rebuild1 rebuilds ΔBtail for single root.
// rebuild1 rebuilds ΔBtail for single root.
func
(
δBtail
*
ΔBtail
)
rebuild1
(
root
zodb
.
Oid
)
error
{
func
(
δBtail
*
ΔBtail
)
rebuild1
(
root
zodb
.
Oid
)
error
{
// XXX locking
// XXX locking
δTtail
:=
δBtail
.
vδT
byRoot
[
root
]
// must be there
δTtail
:=
δBtail
.
byRoot
[
root
]
// must be there
δtrackSet
,
δrevSet
,
err
:=
δTtail
.
rebuild
(
root
,
δBtail
.
δZtail
,
δBtail
.
db
)
δtrackSet
,
δrevSet
,
err
:=
δTtail
.
rebuild
(
root
,
δBtail
.
δZtail
,
δBtail
.
db
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -640,7 +640,7 @@ func (δBtail *ΔBtail) Update(δZ *zodb.EventCommit) (_ ΔB, err error) {
...
@@ -640,7 +640,7 @@ func (δBtail *ΔBtail) Update(δZ *zodb.EventCommit) (_ ΔB, err error) {
δB
:=
ΔB
{
Rev
:
δZ
.
Tid
,
ByRoot
:
make
(
map
[
zodb
.
Oid
]
map
[
Key
]
ΔValue
)}
δB
:=
ΔB
{
Rev
:
δZ
.
Tid
,
ByRoot
:
make
(
map
[
zodb
.
Oid
]
map
[
Key
]
ΔValue
)}
for
root
,
δT1
:=
range
δB1
.
ByRoot
{
for
root
,
δT1
:=
range
δB1
.
ByRoot
{
δTtail
:=
δBtail
.
vδT
byRoot
[
root
]
// must succeed
δTtail
:=
δBtail
.
byRoot
[
root
]
// must succeed
// δtkeycov1 != ø -> rebuild δTtail with trackNew ~= δtkeycov1
// δtkeycov1 != ø -> rebuild δTtail with trackNew ~= δtkeycov1
if
!
δT1
.
δtkeycov1
.
Empty
()
&&
δBtail
.
δZtail
.
Len
()
>
1
{
if
!
δT1
.
δtkeycov1
.
Empty
()
&&
δBtail
.
δZtail
.
Len
()
>
1
{
...
@@ -701,7 +701,7 @@ func (δBtail *ΔBtail) _Update1(δZ *zodb.EventCommit) (δB1 _ΔBUpdate1, err e
...
@@ -701,7 +701,7 @@ func (δBtail *ΔBtail) _Update1(δZ *zodb.EventCommit) (δB1 _ΔBUpdate1, err e
tracefΔBtail
(
"
\n
Update @%s -> @%s δZ: %v
\n
"
,
δBtail
.
Head
(),
δZ
.
Tid
,
δZ
.
Changev
)
tracefΔBtail
(
"
\n
Update @%s -> @%s δZ: %v
\n
"
,
δBtail
.
Head
(),
δZ
.
Tid
,
δZ
.
Changev
)
tracefΔBtail
(
"trackSet: %v
\n
"
,
δBtail
.
trackSet
)
tracefΔBtail
(
"trackSet: %v
\n
"
,
δBtail
.
trackSet
)
for
_
,
root
:=
range
δBtail
.
trackNewRoots
.
SortedElements
()
{
for
_
,
root
:=
range
δBtail
.
trackNewRoots
.
SortedElements
()
{
δTtail
:=
δBtail
.
vδT
byRoot
[
root
]
δTtail
:=
δBtail
.
byRoot
[
root
]
tracefΔBtail
(
"[%s].trackNew: %v
\n
"
,
root
,
δTtail
.
trackNew
)
tracefΔBtail
(
"[%s].trackNew: %v
\n
"
,
root
,
δTtail
.
trackNew
)
}
}
...
@@ -745,7 +745,7 @@ func (δBtail *ΔBtail) _Update1(δZ *zodb.EventCommit) (δB1 _ΔBUpdate1, err e
...
@@ -745,7 +745,7 @@ func (δBtail *ΔBtail) _Update1(δZ *zodb.EventCommit) (δB1 _ΔBUpdate1, err e
tracefΔBtail
(
"
\n
-> root<%s> δkv: %v δtrack: %v δtkeycov: %v
\n
"
,
root
,
δT
,
δtrack
,
δtkeycov
)
tracefΔBtail
(
"
\n
-> root<%s> δkv: %v δtrack: %v δtkeycov: %v
\n
"
,
root
,
δT
,
δtrack
,
δtkeycov
)
δTtail
:=
δBtail
.
vδT
byRoot
[
root
]
// must be there
δTtail
:=
δBtail
.
byRoot
[
root
]
// must be there
if
len
(
δT
)
>
0
{
// an object might be resaved without change
if
len
(
δT
)
>
0
{
// an object might be resaved without change
// NOTE no need to clone .vδT here because we only append to it:
// NOTE no need to clone .vδT here because we only append to it:
// Even though queries return vδT aliases, append
// Even though queries return vδT aliases, append
...
@@ -809,7 +809,7 @@ func (δBtail *ΔBtail) ForgetPast(revCut zodb.Tid) {
...
@@ -809,7 +809,7 @@ func (δBtail *ΔBtail) ForgetPast(revCut zodb.Tid) {
// trim roots
// trim roots
for
root
:=
range
totrim
{
for
root
:=
range
totrim
{
δTtail
:=
δBtail
.
vδT
byRoot
[
root
]
// must be present
δTtail
:=
δBtail
.
byRoot
[
root
]
// must be present
δTtail
.
forgetPast
(
revCut
)
δTtail
.
forgetPast
(
revCut
)
}
}
}
}
...
@@ -875,7 +875,7 @@ func (δBtail *ΔBtail) GetAt(root zodb.Oid, key Key, at zodb.Tid) (value Value,
...
@@ -875,7 +875,7 @@ func (δBtail *ΔBtail) GetAt(root zodb.Oid, key Key, at zodb.Tid) (value Value,
return
value
,
rev
,
valueExact
,
revExact
,
err
return
value
,
rev
,
valueExact
,
revExact
,
err
}
}
δTtail
:=
δBtail
.
vδT
byRoot
[
root
]
δTtail
:=
δBtail
.
byRoot
[
root
]
if
δTtail
==
nil
{
if
δTtail
==
nil
{
panicf
(
"δBtail: root<%s> not tracked"
,
root
)
panicf
(
"δBtail: root<%s> not tracked"
,
root
)
}
}
...
@@ -924,7 +924,7 @@ func (δBtail *ΔBtail) SliceByRootRev(root zodb.Oid, lo, hi zodb.Tid) /*readonl
...
@@ -924,7 +924,7 @@ func (δBtail *ΔBtail) SliceByRootRev(root zodb.Oid, lo, hi zodb.Tid) /*readonl
panic
(
err
)
// XXX
panic
(
err
)
// XXX
}
}
δTtail
,
ok
:=
δBtail
.
vδT
byRoot
[
root
]
δTtail
,
ok
:=
δBtail
.
byRoot
[
root
]
if
!
ok
{
if
!
ok
{
return
[]
ΔTree
{}
return
[]
ΔTree
{}
}
}
...
...
wcfs/internal/xbtree/δbtail_test.go
View file @
eeeb2673
...
@@ -738,8 +738,21 @@ func xverifyΔBTail_Update1(t *testing.T, subj string, db *zodb.DB, treeRoot zod
...
@@ -738,8 +738,21 @@ func xverifyΔBTail_Update1(t *testing.T, subj string, db *zodb.DB, treeRoot zod
}
}
δB
,
err
:=
δbtail
.
Update
(
δZ
);
X
(
err
)
δB
,
err
:=
δbtail
.
Update
(
δZ
);
X
(
err
)
// XXX assert δB.roots == δTKeyCov roots
// XXX assert δBtail[root].vδT = δBtail_[root].vδT
// assert δBtail[root].vδT = δBtail_[root].vδT
//
// NOTE we don't verify .roots because δB1.roots always has treeRoot because
// for debugging δtkeycov information is always recorded, even if empty.
var
vδT
,
vδT_
[]
ΔTree
if
δttail
,
ok
:=
δbtail
.
byRoot
[
treeRoot
];
ok
{
vδT
=
δttail
.
vδT
}
if
δttail_
,
ok
:=
δbtail_
.
byRoot
[
treeRoot
];
ok
{
vδT_
=
δttail_
.
vδT
}
if
!
reflect
.
DeepEqual
(
vδT
,
vδT_
)
{
badf
(
"δBtail.vδT differs after Update and _Update1:
\n
_Update1: %v
\n
Update: %v"
,
vδT_
,
vδT
)
}
if
δB
.
Rev
!=
δZ
.
Tid
{
if
δB
.
Rev
!=
δZ
.
Tid
{
badf
(
"δB: rev != δZ.Tid ; rev=%s δZ.Tid=%s"
,
δB
.
Rev
,
δZ
.
Tid
)
badf
(
"δB: rev != δZ.Tid ; rev=%s δZ.Tid=%s"
,
δB
.
Rev
,
δZ
.
Tid
)
...
@@ -1017,7 +1030,7 @@ func xverifyΔBTail_rebuild_U(t *testing.T, δbtail *ΔBtail, treeRoot zodb.Oid,
...
@@ -1017,7 +1030,7 @@ func xverifyΔBTail_rebuild_U(t *testing.T, δbtail *ΔBtail, treeRoot zodb.Oid,
}
}
δroots
:=
setOid
{}
δroots
:=
setOid
{}
for
root
:=
range
δbtail
.
vδT
byRoot
{
for
root
:=
range
δbtail
.
byRoot
{
δroots
.
Add
(
root
)
δroots
.
Add
(
root
)
}
}
δToid
,
ok
:=
δB
.
ByRoot
[
treeRoot
]
δToid
,
ok
:=
δB
.
ByRoot
[
treeRoot
]
...
@@ -1053,7 +1066,7 @@ func xverifyΔBTail_rebuild_TR(t *testing.T, δbtail *ΔBtail, tj *xbtreetest.Co
...
@@ -1053,7 +1066,7 @@ func xverifyΔBTail_rebuild_TR(t *testing.T, δbtail *ΔBtail, tj *xbtreetest.Co
// XXX verify Get -> XXX assertΔTtail ?
// XXX verify Get -> XXX assertΔTtail ?
// verify δbtail.
vδT
byRoot[treeRoot]
// verify δbtail.byRoot[treeRoot]
assertΔTtail
(
t
,
subj
,
δbtail
,
tj
,
treeRoot
,
vδTok
...
)
assertΔTtail
(
t
,
subj
,
δbtail
,
tj
,
treeRoot
,
vδTok
...
)
}
}
...
@@ -1210,7 +1223,7 @@ func TestΔBtailSliceByRootRev(t_ *testing.T) {
...
@@ -1210,7 +1223,7 @@ func TestΔBtailSliceByRootRev(t_ *testing.T) {
trackKeys
(
δbtail
,
t2
,
_2
)
trackKeys
(
δbtail
,
t2
,
_2
)
err
=
δbtail
.
rebuildAll
();
X
(
err
)
err
=
δbtail
.
rebuildAll
();
X
(
err
)
δttail
:=
δbtail
.
vδT
byRoot
[
t
.
Root
()]
δttail
:=
δbtail
.
byRoot
[
t
.
Root
()]
// assertvδT asserts that vδT matches vδTok
// assertvδT asserts that vδT matches vδTok
assertvδT
:=
func
(
subj
string
,
vδT
[]
ΔTree
,
vδTok
...
ΔT
)
{
assertvδT
:=
func
(
subj
string
,
vδT
[]
ΔTree
,
vδTok
...
ΔT
)
{
...
@@ -1535,7 +1548,7 @@ func assertΔTtail(t *testing.T, subj string, δbtail *ΔBtail, tj *xbtreetest.C
...
@@ -1535,7 +1548,7 @@ func assertΔTtail(t *testing.T, subj string, δbtail *ΔBtail, tj *xbtreetest.C
t0
=
t0
.
Prev
t0
=
t0
.
Prev
}
}
vδTok
=
vδTok_
vδTok
=
vδTok_
δTtail
,
ok
:=
δbtail
.
vδT
byRoot
[
treeRoot
]
δTtail
,
ok
:=
δbtail
.
byRoot
[
treeRoot
]
var
vδToid
[]
ΔTree
var
vδToid
[]
ΔTree
if
ok
{
if
ok
{
vδToid
=
δTtail
.
vδT
vδToid
=
δTtail
.
vδT
...
@@ -1597,7 +1610,7 @@ func (δBtail *ΔBtail) assertTrack(t *testing.T, subj string, trackSetOK blib.P
...
@@ -1597,7 +1610,7 @@ func (δBtail *ΔBtail) assertTrack(t *testing.T, subj string, trackSetOK blib.P
}
}
roots
:=
setOid
{}
roots
:=
setOid
{}
for
root
:=
range
δBtail
.
vδT
byRoot
{
for
root
:=
range
δBtail
.
byRoot
{
roots
.
Add
(
root
)
roots
.
Add
(
root
)
}
}
...
@@ -1606,7 +1619,7 @@ func (δBtail *ΔBtail) assertTrack(t *testing.T, subj string, trackSetOK blib.P
...
@@ -1606,7 +1619,7 @@ func (δBtail *ΔBtail) assertTrack(t *testing.T, subj string, trackSetOK blib.P
nrootsOK
=
0
nrootsOK
=
0
}
}
if
len
(
roots
)
!=
nrootsOK
{
if
len
(
roots
)
!=
nrootsOK
{
t
.
Errorf
(
"%s: len(
vδT
byRoot) != %d ; roots=%v"
,
subj
,
nrootsOK
,
roots
)
t
.
Errorf
(
"%s: len(byRoot) != %d ; roots=%v"
,
subj
,
nrootsOK
,
roots
)
return
return
}
}
if
nrootsOK
==
0
{
if
nrootsOK
==
0
{
...
@@ -1615,7 +1628,7 @@ func (δBtail *ΔBtail) assertTrack(t *testing.T, subj string, trackSetOK blib.P
...
@@ -1615,7 +1628,7 @@ func (δBtail *ΔBtail) assertTrack(t *testing.T, subj string, trackSetOK blib.P
root
:=
roots
.
Elements
()[
0
]
root
:=
roots
.
Elements
()[
0
]
δTtail
:=
δBtail
.
vδT
byRoot
[
root
]
δTtail
:=
δBtail
.
byRoot
[
root
]
trackNewRootsOK
:=
setOid
{}
trackNewRootsOK
:=
setOid
{}
if
!
trackNewOK
.
Empty
()
{
if
!
trackNewOK
.
Empty
()
{
...
...
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