Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
Commits
ed7ffaa2
Commit
ed7ffaa2
authored
Aug 24, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
94e427fe
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
52 deletions
+50
-52
go/neo/client/cache.go
go/neo/client/cache.go
+26
-26
go/neo/client/cache_test.go
go/neo/client/cache_test.go
+24
-26
No files found.
go/neo/client/cache.go
View file @
ed7ffaa2
...
...
@@ -68,7 +68,7 @@ type oidCacheEntry struct {
// XXX or?
// cached revisions in descending order
// .before > .serial >= next.before > next.serial ?
r
evv
[]
*
revCacheEntry
// XXX -> rcev ?
r
cev
[]
*
revCacheEntry
}
// revCacheEntry is information about 1 cached oid revision
...
...
@@ -104,8 +104,8 @@ func NewCache(loader storLoader) *Cache {
return
&
Cache
{
loader
:
loader
,
entryMap
:
make
(
map
[
zodb
.
Oid
]
*
oidCacheEntry
)}
}
// newReveEntry creates new revCacheEntry with .before and inserts it into .r
ev
v @i
// (if i == len(oce.r
ev
v) - entry is appended)
// newReveEntry creates new revCacheEntry with .before and inserts it into .r
ce
v @i
// (if i == len(oce.r
ce
v) - entry is appended)
func
(
oce
*
oidCacheEntry
)
newRevEntry
(
i
int
,
before
zodb
.
Tid
)
*
revCacheEntry
{
rce
:=
&
revCacheEntry
{
parent
:
oce
,
...
...
@@ -115,17 +115,17 @@ func (oce *oidCacheEntry) newRevEntry(i int, before zodb.Tid) *revCacheEntry {
}
rce
.
inLRU
.
Init
()
oce
.
r
evv
=
append
(
oce
.
rev
v
,
nil
)
copy
(
oce
.
r
evv
[
i
+
1
:
],
oce
.
rev
v
[
i
:
])
oce
.
r
ev
v
[
i
]
=
rce
oce
.
r
cev
=
append
(
oce
.
rce
v
,
nil
)
copy
(
oce
.
r
cev
[
i
+
1
:
],
oce
.
rce
v
[
i
:
])
oce
.
r
ce
v
[
i
]
=
rce
return
rce
}
// find finds rce under oce and returns its index in oce.r
ev
v.
// find finds rce under oce and returns its index in oce.r
ce
v.
// not found -> -1.
func
(
oce
*
oidCacheEntry
)
find
(
rce
*
revCacheEntry
)
int
{
for
i
,
r
:=
range
oce
.
r
ev
v
{
for
i
,
r
:=
range
oce
.
r
ce
v
{
if
r
==
rce
{
return
i
}
...
...
@@ -134,12 +134,12 @@ func (oce *oidCacheEntry) find(rce *revCacheEntry) int {
}
func
(
oce
*
oidCacheEntry
)
deli
(
i
int
)
{
n
:=
len
(
oce
.
r
ev
v
)
-
1
copy
(
oce
.
r
evv
[
i
:
],
oce
.
rev
v
[
i
+
1
:
])
n
:=
len
(
oce
.
r
ce
v
)
-
1
copy
(
oce
.
r
cev
[
i
:
],
oce
.
rce
v
[
i
+
1
:
])
// release ptr to revCacheEntry so it won't confusingly stay live when
// its turn to be deleted come.
oce
.
r
ev
v
[
n
]
=
nil
oce
.
r
evv
=
oce
.
rev
v
[
:
n
]
oce
.
r
ce
v
[
n
]
=
nil
oce
.
r
cev
=
oce
.
rce
v
[
:
n
]
}
// XXX doc; must be called with oce lock held
...
...
@@ -200,9 +200,9 @@ func (c *Cache) Load(xid zodb.Xid) (data []byte, tid zodb.Tid, err error) {
var
rceNew
bool
// whether we created rce anew
if
xid
.
TidBefore
{
l
:=
len
(
oce
.
r
ev
v
)
l
:=
len
(
oce
.
r
ce
v
)
i
:=
sort
.
Search
(
l
,
func
(
i
int
)
bool
{
before
:=
oce
.
r
ev
v
[
i
]
.
before
before
:=
oce
.
r
ce
v
[
i
]
.
before
if
before
==
zodb
.
TidMax
{
before
=
cacheBefore
}
...
...
@@ -210,7 +210,7 @@ func (c *Cache) Load(xid zodb.Xid) (data []byte, tid zodb.Tid, err error) {
})
switch
{
// not found - tid > max(r
ev
v.before) - insert new max entry
// not found - tid > max(r
ce
v.before) - insert new max entry
case
i
==
l
:
rce
=
oce
.
newRevEntry
(
i
,
xid
.
Tid
)
if
rce
.
before
==
cacheBefore
{
...
...
@@ -221,17 +221,17 @@ func (c *Cache) Load(xid zodb.Xid) (data []byte, tid zodb.Tid, err error) {
rceNew
=
true
// found:
// tid <= r
ev
v[i].before
// tid > r
ev
v[i-1].before
// tid <= r
ce
v[i].before
// tid > r
ce
v[i-1].before
// exact match - we already have entry for this before
case
xid
.
Tid
==
oce
.
r
ev
v
[
i
]
.
before
:
rce
=
oce
.
r
ev
v
[
i
]
case
xid
.
Tid
==
oce
.
r
ce
v
[
i
]
.
before
:
rce
=
oce
.
r
ce
v
[
i
]
// non-exact match - same entry if inside (serial, before]
// XXX do we need `oce.r
ev
v[i].serial != 0` check vvv ?
case
oce
.
r
evv
[
i
]
.
loaded
()
&&
oce
.
revv
[
i
]
.
serial
!=
0
&&
oce
.
rev
v
[
i
]
.
serial
<
xid
.
Tid
:
rce
=
oce
.
r
ev
v
[
i
]
// XXX do we need `oce.r
ce
v[i].serial != 0` check vvv ?
case
oce
.
r
cev
[
i
]
.
loaded
()
&&
oce
.
rcev
[
i
]
.
serial
!=
0
&&
oce
.
rce
v
[
i
]
.
serial
<
xid
.
Tid
:
rce
=
oce
.
r
ce
v
[
i
]
// otherwise - insert new entry
default
:
...
...
@@ -288,8 +288,8 @@ func (c *Cache) Load(xid zodb.Xid) (data []byte, tid zodb.Tid, err error) {
}
// if rce & rceNext cover the same range -> drop rce
if
i
+
1
<
len
(
oce
.
r
ev
v
)
{
rceNext
:=
oce
.
r
ev
v
[
i
+
1
]
if
i
+
1
<
len
(
oce
.
r
ce
v
)
{
rceNext
:=
oce
.
r
ce
v
[
i
+
1
]
if
rceNext
.
loaded
()
&&
tryMerge
(
rce
,
rceNext
,
rce
,
xid
.
Oid
)
{
// not δsize -= len(rce.data)
// tryMerge can change rce.data if consistency is broken
...
...
@@ -300,7 +300,7 @@ func (c *Cache) Load(xid zodb.Xid) (data []byte, tid zodb.Tid, err error) {
// if rcePrev & rce cover the same range -> drop rcePrev
if
i
>
0
{
rcePrev
:=
oce
.
r
ev
v
[
i
-
1
]
rcePrev
:=
oce
.
r
ce
v
[
i
-
1
]
if
rcePrev
.
loaded
()
&&
tryMerge
(
rcePrev
,
rce
,
rce
,
xid
.
Oid
)
{
δsize
-=
len
(
rcePrev
.
data
)
}
...
...
@@ -323,7 +323,7 @@ func (c *Cache) Load(xid zodb.Xid) (data []byte, tid zodb.Tid, err error) {
// tryMerge tries to merge rce prev into next
//
// both prev and next must be already loaded.
// prev and next must come adjacent to each other in parent.r
ev
v with
// prev and next must come adjacent to each other in parent.r
ce
v with
// prev.before < next.before .
//
// cur must be one of either prev or next and indicates which rce is current
...
...
go/neo/client/cache_test.go
View file @
ed7ffaa2
...
...
@@ -115,9 +115,7 @@ func TestCache(t *testing.T) {
// XXX cases when .serial=0 (not yet determined - 1st loadBefore is in progress)
// XXX for every serial check before = (s-1, s, s+1)
// merge: rce + rceNext
// rcePrev + rce
// rcePrev + (rce + rceNext)
// merge: rcePrev + (rce + rceNext) ?
tc
:=
Checker
{
t
}
ok1
:=
func
(
v
bool
)
{
t
.
Helper
();
tc
.
ok1
(
v
)
}
...
...
@@ -171,75 +169,75 @@ func TestCache(t *testing.T) {
checkOCE
:=
func
(
oid
zodb
.
Oid
,
rcev
...*
revCacheEntry
)
{
t
.
Helper
()
oce
:=
c
.
entryMap
[
oid
]
if
!
reflect
.
DeepEqual
(
oce
.
r
ev
v
,
rcev
)
{
t
.
Fatalf
(
"oce(%v):
\n
%s"
,
oid
,
pretty
.
Compare
(
rcev
,
oce
.
r
ev
v
))
if
!
reflect
.
DeepEqual
(
oce
.
r
ce
v
,
rcev
)
{
t
.
Fatalf
(
"oce(%v):
\n
%s"
,
oid
,
pretty
.
Compare
(
rcev
,
oce
.
r
ce
v
))
}
}
// load <3 -> new rce entry
checkLoad
(
xidlt
(
1
,
3
),
nil
,
0
,
&
zodb
.
ErrXidMissing
{
xidlt
(
1
,
3
)})
oce1
:=
c
.
entryMap
[
1
]
ok1
(
len
(
oce1
.
r
ev
v
)
==
1
)
rce1_b3
:=
oce1
.
r
ev
v
[
0
]
ok1
(
len
(
oce1
.
r
ce
v
)
==
1
)
rce1_b3
:=
oce1
.
r
ce
v
[
0
]
checkRCE
(
rce1_b3
,
3
,
0
,
nil
,
&
zodb
.
ErrXidMissing
{
xidlt
(
1
,
3
)})
// load <4 -> <3 merged with <4
checkLoad
(
xidlt
(
1
,
4
),
nil
,
0
,
&
zodb
.
ErrXidMissing
{
xidlt
(
1
,
4
)})
ok1
(
len
(
oce1
.
r
ev
v
)
==
1
)
rce1_b4
:=
oce1
.
r
ev
v
[
0
]
ok1
(
len
(
oce1
.
r
ce
v
)
==
1
)
rce1_b4
:=
oce1
.
r
ce
v
[
0
]
ok1
(
rce1_b4
!=
rce1_b3
)
// rce1_b3 was merged into rce1_b4
checkRCE
(
rce1_b4
,
4
,
0
,
nil
,
&
zodb
.
ErrXidMissing
{
xidlt
(
1
,
4
)})
// load <2 -> <2 merged with <4
checkLoad
(
xidlt
(
1
,
2
),
nil
,
0
,
&
zodb
.
ErrXidMissing
{
xidlt
(
1
,
2
)})
ok1
(
len
(
oce1
.
r
ev
v
)
==
1
)
ok1
(
oce1
.
r
ev
v
[
0
]
==
rce1_b4
)
ok1
(
len
(
oce1
.
r
ce
v
)
==
1
)
ok1
(
oce1
.
r
ce
v
[
0
]
==
rce1_b4
)
checkRCE
(
rce1_b4
,
4
,
0
,
nil
,
&
zodb
.
ErrXidMissing
{
xidlt
(
1
,
4
)})
// load <6 -> new rce entry with data
checkLoad
(
xidlt
(
1
,
6
),
hello
,
4
,
nil
)
ok1
(
len
(
oce1
.
r
ev
v
)
==
2
)
rce1_b6
:=
oce1
.
r
ev
v
[
1
]
ok1
(
len
(
oce1
.
r
ce
v
)
==
2
)
rce1_b6
:=
oce1
.
r
ce
v
[
1
]
checkRCE
(
rce1_b6
,
6
,
4
,
hello
,
nil
)
checkOCE
(
1
,
rce1_b4
,
rce1_b6
)
// load <5 -> merged with <6
// load <5 ->
<5
merged with <6
checkLoad
(
xidlt
(
1
,
5
),
hello
,
4
,
nil
)
checkOCE
(
1
,
rce1_b4
,
rce1_b6
)
// load <7 -> <6 merged
->
<7
// load <7 -> <6 merged
with
<7
checkLoad
(
xidlt
(
1
,
7
),
hello
,
4
,
nil
)
ok1
(
len
(
oce1
.
r
ev
v
)
==
2
)
rce1_b7
:=
oce1
.
r
ev
v
[
1
]
ok1
(
len
(
oce1
.
r
ce
v
)
==
2
)
rce1_b7
:=
oce1
.
r
ce
v
[
1
]
ok1
(
rce1_b7
!=
rce1_b6
)
checkRCE
(
rce1_b7
,
7
,
4
,
hello
,
nil
)
checkOCE
(
1
,
rce1_b4
,
rce1_b7
)
// load <8 -> ioerr + new rce
checkLoad
(
xidlt
(
1
,
8
),
nil
,
0
,
ioerr
)
ok1
(
len
(
oce1
.
r
ev
v
)
==
3
)
rce1_b8
:=
oce1
.
r
ev
v
[
2
]
ok1
(
len
(
oce1
.
r
ce
v
)
==
3
)
rce1_b8
:=
oce1
.
r
ce
v
[
2
]
checkRCE
(
rce1_b8
,
8
,
0
,
nil
,
ioerr
)
checkOCE
(
1
,
rce1_b4
,
rce1_b7
,
rce1_b8
)
// load <9 -> ioerr + new rce (IO errors are not merged)
checkLoad
(
xidlt
(
1
,
9
),
nil
,
0
,
ioerr
)
ok1
(
len
(
oce1
.
r
ev
v
)
==
4
)
rce1_b9
:=
oce1
.
r
ev
v
[
3
]
ok1
(
len
(
oce1
.
r
ce
v
)
==
4
)
rce1_b9
:=
oce1
.
r
ce
v
[
3
]
checkRCE
(
rce1_b9
,
9
,
0
,
nil
,
ioerr
)
checkOCE
(
1
,
rce1_b4
,
rce1_b7
,
rce1_b8
,
rce1_b9
)
// load <10 -> new data rce, not merged with ioerr @<9
checkLoad
(
xidlt
(
1
,
10
),
world
,
9
,
nil
)
ok1
(
len
(
oce1
.
r
ev
v
)
==
5
)
rce1_b10
:=
oce1
.
r
ev
v
[
4
]
ok1
(
len
(
oce1
.
r
ce
v
)
==
5
)
rce1_b10
:=
oce1
.
r
ce
v
[
4
]
checkRCE
(
rce1_b10
,
10
,
9
,
world
,
nil
)
checkOCE
(
1
,
rce1_b4
,
rce1_b7
,
rce1_b8
,
rce1_b9
,
rce1_b10
)
// load <12 -> <10 merged
->
<12
// load <12 -> <10 merged
with
<12
checkLoad
(
xidlt
(
1
,
12
),
world
,
9
,
nil
)
ok1
(
len
(
oce1
.
r
ev
v
)
==
5
)
rce1_b12
:=
oce1
.
r
ev
v
[
4
]
ok1
(
len
(
oce1
.
r
ce
v
)
==
5
)
rce1_b12
:=
oce1
.
r
ce
v
[
4
]
ok1
(
rce1_b12
!=
rce1_b10
)
checkRCE
(
rce1_b12
,
12
,
9
,
world
,
nil
)
checkOCE
(
1
,
rce1_b4
,
rce1_b7
,
rce1_b8
,
rce1_b9
,
rce1_b12
)
...
...
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