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
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
neoppod
Commits
44357788
Commit
44357788
authored
Aug 25, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
bbe11527
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
3 deletions
+40
-3
go/neo/client/cache.go
go/neo/client/cache.go
+15
-1
go/neo/client/cache_test.go
go/neo/client/cache_test.go
+24
-1
go/neo/client/list.go
go/neo/client/list.go
+1
-1
No files found.
go/neo/client/cache.go
View file @
44357788
...
...
@@ -26,6 +26,7 @@ import (
"sync"
"unsafe"
// "github.com/kylelemons/godebug/pretty"
"lab.nexedi.com/kirr/neo/go/zodb"
)
...
...
@@ -103,7 +104,12 @@ type revCacheEntry struct {
// NewCache creates new cache backed up by loader
// XXX +sizeMax
func
NewCache
(
loader
storLoader
)
*
Cache
{
return
&
Cache
{
loader
:
loader
,
entryMap
:
make
(
map
[
zodb
.
Oid
]
*
oidCacheEntry
)}
c
:=
&
Cache
{
loader
:
loader
,
entryMap
:
make
(
map
[
zodb
.
Oid
]
*
oidCacheEntry
),
}
c
.
lru
.
Init
()
return
c
}
// newRevEntry creates new revCacheEntry with .before and inserts it into .rcev @i.
...
...
@@ -182,6 +188,7 @@ func (c *Cache) Load(xid zodb.Xid) (data []byte, serial zodb.Tid, err error) {
// rce is already in cache - use it
if
!
rceNew
{
//panic(0)
<-
rce
.
ready
c
.
gcMu
.
Lock
()
rce
.
inLRU
.
MoveBefore
(
&
c
.
lru
)
...
...
@@ -375,7 +382,14 @@ func (c *Cache) loadRCE(rce *revCacheEntry, oid zodb.Oid) {
// update lru & cache size
c
.
gcMu
.
Lock
()
//xv1 := map[string]interface{}{"lru": &c.lru, "rce": &rce.inLRU}
//fmt.Printf("aaa:\n%s\n", pretty.Sprint(xv1))
rce
.
inLRU
.
MoveBefore
(
&
c
.
lru
)
//xv2 := map[string]interface{}{"lru": &c.lru, "rce": &rce.inLRU}
//fmt.Printf("\n--------\n%s\n\n\n", pretty.Sprint(xv2))
//panic(1)
c
.
size
+=
δsize
if
c
.
size
>
c
.
sizeMax
{
// XXX -> run gc
...
...
go/neo/client/cache_test.go
View file @
44357788
...
...
@@ -108,6 +108,8 @@ func xideq(oid zodb.Oid, tid zodb.Tid) zodb.Xid {
func
TestCache
(
t
*
testing
.
T
)
{
// XXX hack; place=ok?
pretty
.
CompareConfig
.
PrintStringers
=
true
debug
:=
pretty
.
DefaultConfig
debug
.
IncludeUnexported
=
true
// XXX <100 <90 <80
// q<110 -> a) 110 <= cache.before b) otherwise
...
...
@@ -172,19 +174,39 @@ func TestCache(t *testing.T) {
t
.
Helper
()
oce
:=
c
.
entryMap
[
oid
]
if
!
reflect
.
DeepEqual
(
oce
.
rcev
,
rcev
)
{
t
.
Fatalf
(
"oce(%v):
\n
%s"
,
oid
,
pretty
.
Compare
(
rcev
,
oce
.
rcev
))
t
.
Fatalf
(
"oce(%v):
\n
%s
\n
"
,
oid
,
pretty
.
Compare
(
rcev
,
oce
.
rcev
))
}
}
checkMRU
:=
func
(
mruvOk
...*
revCacheEntry
)
{
t
.
Helper
()
var
mruv
[]
*
revCacheEntry
for
hp
,
h
:=
&
c
.
lru
,
c
.
lru
.
prev
;
h
!=
&
c
.
lru
;
hp
,
h
=
h
,
h
.
prev
{
xv
:=
[]
interface
{}{
&
c
.
lru
,
h
.
rceFromInLRU
()}
debug
.
Print
(
xv
)
// &c.lru, h.rceFromInLRU())
if
h
.
next
!=
hp
{
t
.
Fatalf
(
"LRU list .next/.prev broken for
\n
h:
\n
%s
\n\n
hp:
\n
%s
\n
"
,
debug
.
Sprint
(
h
),
debug
.
Sprint
(
hp
))
}
mruv
=
append
(
mruv
,
h
.
rceFromInLRU
())
}
if
!
reflect
.
DeepEqual
(
mruv
,
mruvOk
)
{
t
.
Fatalf
(
"MRU:
\n
%s
\n
"
,
pretty
.
Compare
(
mruv
,
mruvOk
))
}
}
// ---- verify cache behaviour for must be loaded/merged entries ----
// (this excercises mostly loadRCE/tryMerge)
checkMRU
()
// load <3 -> new rce entry
checkLoad
(
xidlt
(
1
,
3
),
nil
,
0
,
&
zodb
.
ErrXidMissing
{
xidlt
(
1
,
3
)})
oce1
:=
c
.
entryMap
[
1
]
ok1
(
len
(
oce1
.
rcev
)
==
1
)
rce1_b3
:=
oce1
.
rcev
[
0
]
checkRCE
(
rce1_b3
,
3
,
0
,
nil
,
&
zodb
.
ErrXidMissing
{
xidlt
(
1
,
3
)})
checkMRU
(
rce1_b3
)
// load <4 -> <3 merged with <4
checkLoad
(
xidlt
(
1
,
4
),
nil
,
0
,
&
zodb
.
ErrXidMissing
{
xidlt
(
1
,
4
)})
...
...
@@ -192,6 +214,7 @@ func TestCache(t *testing.T) {
rce1_b4
:=
oce1
.
rcev
[
0
]
ok1
(
rce1_b4
!=
rce1_b3
)
// rce1_b3 was merged into rce1_b4
checkRCE
(
rce1_b4
,
4
,
0
,
nil
,
&
zodb
.
ErrXidMissing
{
xidlt
(
1
,
4
)})
checkMRU
(
rce1_b4
)
// load <2 -> <2 merged with <4
checkLoad
(
xidlt
(
1
,
2
),
nil
,
0
,
&
zodb
.
ErrXidMissing
{
xidlt
(
1
,
2
)})
...
...
go/neo/client/list.go
View file @
44357788
...
...
@@ -49,7 +49,7 @@ func (a *listHead) MoveBefore(b *listHead) {
a
.
Delete
()
a
.
next
=
b
b
.
prev
=
a
a
.
prev
=
b
.
prev
b
.
prev
=
a
a
.
prev
.
next
=
a
}
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