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
9baafc82
Commit
9baafc82
authored
Feb 01, 2019
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
6f377311
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
38 deletions
+52
-38
go/zodb/db.go
go/zodb/db.go
+8
-1
go/zodb/δtail.go
go/zodb/δtail.go
+14
-8
go/zodb/δtail_test.go
go/zodb/δtail_test.go
+30
-29
No files found.
go/zodb/db.go
View file @
9baafc82
...
...
@@ -200,9 +200,16 @@ func (db *DB) watcher(watchq <-chan CommitEvent) { // XXX err ?
}
// forget older δtail entries
fmt
.
Println
()
fmt
.
Printf
(
"%s
\n
"
,
db
.
δtail
.
Head
()
.
Time
()
.
Time
)
fmt
.
Printf
(
"%s
\n
"
,
db
.
δtail
.
Head
()
.
Time
()
.
Add
(
-
db
.
tδkeep
))
tcut
:=
db
.
δtail
.
Head
()
.
Time
()
.
Add
(
-
db
.
tδkeep
)
δcut
:=
TidFromTime
(
tcut
)
db
.
δtail
.
ForgetBefore
(
δcut
)
fmt
.
Printf
(
"db: watcher: δtail: = (%s, %s]
\n
"
,
db
.
δtail
.
Tail
(),
db
.
δtail
.
Head
())
fmt
.
Printf
(
"db: watcher: forget <= %s
\n
"
,
δcut
)
db
.
δtail
.
ForgetPast
(
δcut
)
fmt
.
Printf
(
"db: watcher: δtail: -> (%s, %s]
\n
"
,
db
.
δtail
.
Tail
(),
db
.
δtail
.
Head
())
db
.
mu
.
Unlock
()
...
...
go/zodb/δtail.go
View file @
9baafc82
...
...
@@ -58,7 +58,8 @@ import (
// #blk - file block number, when ΔTail represents changes to a file.
type
ΔTail
struct
{
head
Tid
tailv
[]
δRevEntry
tail
Tid
tailv
[]
δRevEntry
// XXX -> revv ?
lastRevOf
map
[
Oid
]
Tid
// index for LastRevOf queries
// XXX -> lastRevOf = {} oid -> []rev↑ if linear scan in LastRevOf starts to eat cpu
...
...
@@ -78,6 +79,7 @@ type δRevEntry struct {
func
NewΔTail
(
at0
Tid
)
*
ΔTail
{
return
&
ΔTail
{
head
:
at0
,
tail
:
at0
,
lastRevOf
:
make
(
map
[
Oid
]
Tid
),
}
}
...
...
@@ -98,10 +100,7 @@ func (δtail *ΔTail) Head() Tid {
//
// Tail is ↑= on Forget, even if δtail becomes empty.
func
(
δtail
*
ΔTail
)
Tail
()
Tid
{
if
len
(
δtail
.
tailv
)
==
0
{
return
δtail
.
head
}
return
δtail
.
tailv
[
0
]
.
rev
-
1
return
δtail
.
tail
}
// SliceByRev returns δtail slice of elements with .rev ∈ (low, high].
...
...
@@ -161,12 +160,17 @@ func (δtail *ΔTail) Append(rev Tid, changev []Oid) {
}
}
// ForgetBefore discards all δtail entries with rev < revCut.
func
(
δtail
*
ΔTail
)
ForgetBefore
(
revCut
Tid
)
{
// ForgetPast discards all δtail entries with rev ≤ revCut.
func
(
δtail
*
ΔTail
)
ForgetPast
(
revCut
Tid
)
{
// revCut ≤ tail: nothing to do; don't let .tail go ↓
if
revCut
<=
δtail
.
tail
{
return
}
icut
:=
0
for
i
,
δ
:=
range
δtail
.
tailv
{
rev
:=
δ
.
rev
if
rev
>
=
revCut
{
if
rev
>
revCut
{
break
}
icut
=
i
+
1
...
...
@@ -186,6 +190,8 @@ func (δtail *ΔTail) ForgetBefore(revCut Tid) {
tailv
:=
make
([]
δRevEntry
,
l
)
copy
(
tailv
,
δtail
.
tailv
[
icut
:
])
δtail
.
tailv
=
tailv
δtail
.
tail
=
revCut
}
// LastRevOf tries to return what was the last revision that changed id as of at database state.
...
...
go/zodb/δtail_test.go
View file @
9baafc82
...
...
@@ -26,7 +26,7 @@ import (
)
func
TestΔTail
(
t
*
testing
.
T
)
{
δtail
:=
NewΔTail
(
1
)
var
δtail
*
ΔTail
// R is syntactic sugar to create 1 δRevEntry
R
:=
func
(
rev
Tid
,
changev
...
Oid
)
δRevEntry
{
...
...
@@ -39,7 +39,7 @@ func TestΔTail(t *testing.T) {
}
// δCheck verifies that δtail state corresponds to provided tailv
δCheck
:=
func
(
head
Tid
,
tailv
...
δRevEntry
)
{
δCheck
:=
func
(
tail
,
head
Tid
,
tailv
...
δRevEntry
)
{
t
.
Helper
()
for
i
:=
1
;
i
<
len
(
tailv
);
i
++
{
...
...
@@ -48,19 +48,11 @@ func TestΔTail(t *testing.T) {
}
}
// Len/Head/Tail
if
l
:=
δtail
.
Len
();
l
!=
len
(
tailv
)
{
t
.
Fatalf
(
"Len() -> %d ; want %d"
,
l
,
len
(
tailv
))
}
// Head/Tail/Data
if
h
:=
δtail
.
Head
();
h
!=
head
{
t
.
Fatalf
(
"Head() -> %s ; want %s"
,
h
,
head
)
}
tail
:=
head
if
len
(
tailv
)
>
0
{
tail
=
tailv
[
0
]
.
rev
-
1
}
if
tt
:=
δtail
.
Tail
();
tt
!=
tail
{
t
.
Fatalf
(
"Tail() -> %s ; want %s"
,
tt
,
tail
)
}
...
...
@@ -69,6 +61,11 @@ func TestΔTail(t *testing.T) {
t
.
Fatalf
(
"tailv:
\n
have: %v
\n
want: %v"
,
δtail
.
tailv
,
tailv
)
}
if
l
:=
δtail
.
Len
();
l
!=
len
(
tailv
)
{
t
.
Fatalf
(
"Len() -> %d ; want %d"
,
l
,
len
(
tailv
))
}
// SliceByRev
// check that δtail.SliceByRev(rlo, rhi) == tailv[ilo:ihi).
...
...
@@ -170,39 +167,43 @@ func TestΔTail(t *testing.T) {
}
}
δtail
=
NewΔTail
(
3
)
δCheck
(
1
)
δCheck
(
3
,
3
)
δCheckLastUP
(
4
,
12
,
12
)
// δtail = ø
δAppend
(
R
(
10
,
3
,
5
))
δCheck
(
10
,
R
(
10
,
3
,
5
))
δCheck
(
3
,
10
,
R
(
10
,
3
,
5
))
δCheckLastUP
(
3
,
9
,
9
)
// at < δtail
δCheckLastUP
(
3
,
2
,
2
)
// at < δtail
δCheckLastUP
(
3
,
12
,
12
)
// at > δtail
δCheckLastUP
(
4
,
10
,
10
)
// id ∉ δtail
δAppend
(
R
(
11
,
7
))
δCheck
(
11
,
R
(
10
,
3
,
5
),
R
(
11
,
7
))
δCheck
(
3
,
11
,
R
(
10
,
3
,
5
),
R
(
11
,
7
))
δAppend
(
R
(
12
,
7
))
δCheck
(
12
,
R
(
10
,
3
,
5
),
R
(
11
,
7
),
R
(
12
,
7
))
δCheck
(
3
,
12
,
R
(
10
,
3
,
5
),
R
(
11
,
7
),
R
(
12
,
7
))
δAppend
(
R
(
14
,
3
,
8
))
δCheck
(
14
,
R
(
10
,
3
,
5
),
R
(
11
,
7
),
R
(
12
,
7
),
R
(
14
,
3
,
8
))
δCheck
(
3
,
14
,
R
(
10
,
3
,
5
),
R
(
11
,
7
),
R
(
12
,
7
),
R
(
14
,
3
,
8
))
δCheckLastUP
(
8
,
12
,
10
)
// id ∈ δtail, but has no entry with rev ≤ at
δtail
.
ForgetBefore
(
10
)
δCheck
(
14
,
R
(
10
,
3
,
5
),
R
(
11
,
7
),
R
(
12
,
7
),
R
(
14
,
3
,
8
))
δtail
.
ForgetPast
(
9
)
δCheck
(
9
,
14
,
R
(
10
,
3
,
5
),
R
(
11
,
7
),
R
(
12
,
7
),
R
(
14
,
3
,
8
))
δtail
.
ForgetPast
(
10
)
δCheck
(
10
,
14
,
R
(
11
,
7
),
R
(
12
,
7
),
R
(
14
,
3
,
8
))
δtail
.
Forget
Before
(
11
)
δCheck
(
1
4
,
R
(
11
,
7
),
R
(
12
,
7
)
,
R
(
14
,
3
,
8
))
δtail
.
Forget
Past
(
12
)
δCheck
(
1
2
,
14
,
R
(
14
,
3
,
8
))
δtail
.
Forget
Before
(
13
)
δCheck
(
14
,
R
(
14
,
3
,
8
)
)
δtail
.
Forget
Past
(
14
)
δCheck
(
14
,
14
)
δtail
.
Forget
Before
(
15
)
δCheck
(
14
)
δtail
.
Forget
Past
(
12
)
δCheck
(
14
,
14
)
// .tail should not go ↓
// Append panics on non-↑ rev
...
...
@@ -229,14 +230,14 @@ func TestΔTail(t *testing.T) {
// on !empty δtail
δAppend
(
R
(
15
,
1
))
δCheck
(
15
,
R
(
15
,
1
))
δCheck
(
1
4
,
1
5
,
R
(
15
,
1
))
δAppendPanic
(
15
)
δAppendPanic
(
14
)
// .tailv underlying storage is not kept after forget
δtail
.
Forget
Before
(
16
)
δCheck
(
15
)
δtail
.
Forget
Past
(
15
)
δCheck
(
15
,
15
)
const
N
=
1E3
for
rev
,
i
:=
Tid
(
16
),
0
;
i
<
N
;
i
,
rev
=
i
+
1
,
rev
+
1
{
...
...
@@ -244,7 +245,7 @@ func TestΔTail(t *testing.T) {
}
capN
:=
cap
(
δtail
.
tailv
)
δtail
.
Forget
Before
(
N
)
δtail
.
Forget
Past
(
N
)
if
c
:=
cap
(
δtail
.
tailv
);
!
(
c
<
capN
/
10
)
{
t
.
Fatalf
(
"forget: tailv storage did not shrink: cap%v: %d -> cap: %d"
,
N
,
capN
,
c
)
}
...
...
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