Commit cb07d772 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 40256267
...@@ -88,16 +88,6 @@ type revCacheEntry struct { ...@@ -88,16 +88,6 @@ type revCacheEntry struct {
ready chan struct{} // closed when loading finished ready chan struct{} // closed when loading finished
} }
// loaded reports whether rce was already loaded
func (rce *revCacheEntry) loaded() bool {
select {
case <-rce.ready:
return true
default:
return false
}
}
// XXX doc // XXX doc
func (oce *oidCacheEntry) newRevEntry(before zodb.Tid) *revCacheEntry { func (oce *oidCacheEntry) newRevEntry(before zodb.Tid) *revCacheEntry {
rce := &revCacheEntry{ rce := &revCacheEntry{
...@@ -135,12 +125,13 @@ func (oce *oidCacheEntry) del(rce *revCacheEntry) { ...@@ -135,12 +125,13 @@ func (oce *oidCacheEntry) del(rce *revCacheEntry) {
rce.revv = append(rce.revv[:i], rce.revv[i+1:]) rce.revv = append(rce.revv[:i], rce.revv[i+1:])
} }
// lock order: Cache > cacheEntry > (?) revCacheEntry // lock order: Cache.mu > oidCacheEntry > (?) revCacheEntry
// Cache.gcMu > ?
// XXX maintain nhit / nmiss? // XXX maintain nhit / nmiss?
func (c *cache) Load(xid zodb.Xid) (data []byte, tid Tid, err error) { func (c *cache) Load(xid zodb.Xid) (data []byte, tid Tid, err error) {
// oid -> oce (oidCacheEntry) ; creating new empty if not yet there // oid -> oce (oidCacheEntry) ; create new empty oce if not yet there
// exit with oce locked and cache.before read consistently // exit with oce locked and cache.before read consistently
c.mu.RLock() c.mu.RLock()
...@@ -152,6 +143,7 @@ func (c *cache) Load(xid zodb.Xid) (data []byte, tid Tid, err error) { ...@@ -152,6 +143,7 @@ func (c *cache) Load(xid zodb.Xid) (data []byte, tid Tid, err error) {
oce.Lock() oce.Lock()
c.mu.RUnlock() c.mu.RUnlock()
} else { } else {
// relock cache in write mode to create oce
c.mu.RUnlock() c.mu.RUnlock()
c.mu.Lock() c.mu.Lock()
oce = c.entryMap[xid.Oid] oce = c.entryMap[xid.Oid]
...@@ -166,7 +158,7 @@ func (c *cache) Load(xid zodb.Xid) (data []byte, tid Tid, err error) { ...@@ -166,7 +158,7 @@ func (c *cache) Load(xid zodb.Xid) (data []byte, tid Tid, err error) {
// oce, before -> rce (revCacheEntry) // oce, before -> rce (revCacheEntry)
var rce *revCacheEntry var rce *revCacheEntry
var rceNew bool // whether rce created anew var rceNew bool // whether we created rce anew
if xid.TidBefore { if xid.TidBefore {
l := len(oce.revv) l := len(oce.revv)
...@@ -252,7 +244,8 @@ func (c *cache) Load(xid zodb.Xid) (data []byte, tid Tid, err error) { ...@@ -252,7 +244,8 @@ func (c *cache) Load(xid zodb.Xid) (data []byte, tid Tid, err error) {
oce.Lock() oce.Lock()
i := oce.find(rce) i := oce.find(rce)
if i == -1 { if i == -1 {
// rce was already dropped / evicted // rce was already dropped by merge / evicted
// (XXX recheck about evicted)
oce.Unlock() oce.Unlock()
return rce.data, rce.serial, rce.err return rce.data, rce.serial, rce.err
} }
...@@ -337,6 +330,15 @@ func (c *cache) cleaner() { ...@@ -337,6 +330,15 @@ func (c *cache) cleaner() {
} }
// loaded reports whether rce was already loaded
func (rce *revCacheEntry) loaded() bool {
select {
case <-rce.ready:
return true
default:
return false
}
}
// revCacheEntry: .inLRU -> . // revCacheEntry: .inLRU -> .
func (h *listHead) rceFromInLRU() (rce *revCacheEntry) { func (h *listHead) rceFromInLRU() (rce *revCacheEntry) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment