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
07981138
Commit
07981138
authored
Jun 22, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
9d3483ba
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
81 additions
and
6 deletions
+81
-6
wcfs/δbtail.go
wcfs/δbtail.go
+80
-6
wcfs/δbtail_test.go
wcfs/δbtail_test.go
+1
-0
No files found.
wcfs/δbtail.go
View file @
07981138
...
...
@@ -348,6 +348,7 @@ func (δBtail *ΔBtail) Update(δZ *zodb.EventCommit) (_ ΔB, err error) {
fmt
.
Printf
(
"
\n
Update δZ: %v
\n
"
,
δZ
.
Changev
)
fmt
.
Printf
(
"trackIdx: %v
\n
"
,
δBtail
.
trackIdx
)
/*
// {} root -> {oid} changed under that root in tracked set
// XXX dumb -> rework to toposort and getting root from tops only
rootOf := func(node zodb.Oid) (root zodb.Oid, ok bool) {
...
...
@@ -378,11 +379,13 @@ func (δBtail *ΔBtail) Update(δZ *zodb.EventCommit) (_ ΔB, err error) {
δZT.Add(oid)
}
fmt.Println("δZByRoot:", δZByRoot)
*/
δZTC
,
δtopsByRoot
:=
δBtail
.
δZConnectTracked
(
δZ
)
δB
:=
ΔB
{
Rev
:
δZ
.
Tid
,
ByRoot
:
make
(
map
[
zodb
.
Oid
]
map
[
Key
]
ΔValue
)}
// skip opening DB connections if there is no change to any tree node
if
len
(
δ
Z
ByRoot
)
==
0
{
if
len
(
δ
tops
ByRoot
)
==
0
{
return
δB
,
nil
}
...
...
@@ -399,8 +402,10 @@ func (δBtail *ΔBtail) Update(δZ *zodb.EventCommit) (_ ΔB, err error) {
return
ΔB
{},
err
}
for
root
,
δZT
:=
range
δZByRoot
{
δT
,
err
:=
treediff
(
ctx
,
root
,
δZT
,
δBtail
.
trackIdx
,
zconnOld
,
zconnNew
)
// for root, δZT := range δZByRoot {
for
root
,
δtops
:=
range
δtopsByRoot
{
// δT, err := treediff(ctx, root, δZT, δBtail.trackIdx, zconnOld, zconnNew)
δT
,
err
:=
treediff
(
ctx
,
root
,
δtops
,
δZTC
,
δBtail
.
trackIdx
,
zconnOld
,
zconnNew
)
if
err
!=
nil
{
return
ΔB
{},
err
}
...
...
@@ -431,24 +436,93 @@ func (δBtail *ΔBtail) Update(δZ *zodb.EventCommit) (_ ΔB, err error) {
*/
}
// δZConnectTracked computes connected closure of δZ/T.
//
// δZ - all changes in a ZODB transaction.
// δZ/T - subset of those changes intersection with tracking set.
// δZ/TC - connected closure for δZ/T
//
// for example for e.g. t₀->t₁->b₂ if δZ/T={t₀ b₂} -> δZ/TC=δZ/T+{t₁}
//
// δtopsByRoot = {} root -> {top changed nodes in that tree}
func
(
δBtail
*
ΔBtail
)
δZConnectTracked
(
δZv
*
zodb
.
EventCommit
)
(
δZTC
SetOid
,
δtopsByRoot
map
[
zodb
.
Oid
]
SetOid
)
{
δZ
:=
SetOid
{}
δZTC
=
SetOid
{}
δtopsByRoot
=
map
[
zodb
.
Oid
]
SetOid
{}
for
_
,
δ
:=
range
δZv
.
Changev
{
δZ
.
Add
(
δ
)
}
for
δ
:=
range
δZ
{
track
,
ok
:=
δBtail
.
trackIdx
[
δ
]
if
!
ok
{
continue
// not tracked at all
}
δZTC
.
Add
(
δ
)
// go up by .parent till root or till another tracked node in the tree
// if root -> δtopsByRoot[root] += δ
// if !root -> δZTC += path through which we reached another node (forming connection)
path
:=
[]
zodb
.
Oid
{}
node
:=
δ
parent
:=
track
.
parent
for
{
// reached root
if
parent
==
zodb
.
InvalidOid
{
root
:=
node
δtops
,
ok
:=
δtopsByRoot
[
root
]
if
!
ok
{
δtops
=
SetOid
{}
δtopsByRoot
[
root
]
=
δtops
}
δtops
.
Add
(
δ
)
break
}
// reached another tracked node
if
δZ
.
Has
(
parent
)
{
for
_
,
δp
:=
range
path
{
δZTC
.
Add
(
δp
)
}
break
}
path
=
append
(
path
,
parent
)
trackUp
,
ok
:=
δBtail
.
trackIdx
[
parent
]
if
!
ok
{
panicf
(
"BUG: .p%s -> %s, but %s is not tracked"
,
node
,
parent
,
parent
)
}
node
=
parent
parent
=
trackUp
.
parent
}
}
return
δZTC
,
δtopsByRoot
}
// treediff computes δT for tree specified by root in between old..new.
//
// XXX only for tracked
// δZT is δZ/T - subset of δZ(old..new) that touches tracked nodes of T.
func
treediff
(
ctx
context
.
Context
,
root
zodb
.
Oid
,
δZT
SetOid
,
trackIdx
map
[
zodb
.
Oid
]
nodeTrack
,
zconnOld
,
zconnNew
*
zodb
.
Connection
)
(
δT
map
[
Key
]
ΔValue
,
err
error
)
{
//func treediff(ctx context.Context, root zodb.Oid, δZT SetOid, trackIdx map[zodb.Oid]nodeTrack, zconnOld, zconnNew *zodb.Connection) (δT map[Key]ΔValue, err error) {
func
treediff
(
ctx
context
.
Context
,
root
zodb
.
Oid
,
δtops
SetOid
,
δZTC
SetOid
,
trackIdx
map
[
zodb
.
Oid
]
nodeTrack
,
zconnOld
,
zconnNew
*
zodb
.
Connection
)
(
δT
map
[
Key
]
ΔValue
,
err
error
)
{
defer
xerr
.
Contextf
(
&
err
,
"treediff %s..%s %s"
,
zconnOld
.
At
(),
zconnNew
.
At
(),
root
)
// XXX zconnX -> a, b ?
fmt
.
Printf
(
"treediff %s δ
ZT: %v
\n
"
,
root
,
δZT
)
fmt
.
Printf
(
"treediff %s δ
tops: %v δZTC: %v
\n
"
,
root
,
δtops
,
δZTC
)
defer
fmt
.
Printf
(
"
\n
"
)
/*
// XXX δZT -> δZTC (all changed nodes are connected)
// e.g. t₀->t₁->b₂ δZ={t₀ b₂} -> δZC=δZ+{t₁}
δZTC := δZT // FIXME stub
*/
δT
=
map
[
Key
]
ΔValue
{}
for
top
:=
range
δ
ZT
{
// XXX -> sorted?
for
top
:=
range
δ
tops
{
// XXX -> sorted?
a
,
err1
:=
zgetNode
(
ctx
,
zconnOld
,
top
)
b
,
err2
:=
zgetNode
(
ctx
,
zconnNew
,
top
)
err
:=
xerr
.
Merge
(
err1
,
err2
)
...
...
wcfs/δbtail_test.go
View file @
07981138
...
...
@@ -756,6 +756,7 @@ func TestΔBTail(t *testing.T) {
// test known cases going through tree1 -> tree2 -> ...
testv
:=
[]
interface
{}
{
"T2/B1:a-B2:c"
,
"T2,3/B1:a-B2:c-B3:c"
,
///*
"T/B:"
,
...
...
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