Commit f06f6858 authored by Kirill Smelkov's avatar Kirill Smelkov

X works with go -race under wrk load

parent caaf8192
......@@ -36,6 +36,9 @@ type AuthCacheEntry struct {
// FIXME we need to lock the entry only to "correctly" update Nhit on
// read side but we can tolerate some looses in Nhit and update it
// without mutex or atomic. Only -race complains...
// (we could use atomic.Value for atomic cache entry updates from
// refresher withot need for locks on readers side, but the need to do
// .Nhit++ on readers side ruins that)
sync.Mutex
AuthReply
......@@ -55,10 +58,12 @@ type AuthCache struct {
cached map[string]*AuthCacheEntry
}
var authCache = AuthCache{} // XXX make map ?
var authCache = AuthCache{cached: make(map[string]*AuthCacheEntry)}
// XXX u should not be in args?
func (c *AuthCache) VerifyDownloadAccess(u *upstream, project string) AuthReply {
var authReply AuthReply
// first try to read from cache in parallel with other readers
c.mu.RLock()
auth := c.cached[project]
......@@ -67,7 +72,6 @@ func (c *AuthCache) VerifyDownloadAccess(u *upstream, project string) AuthReply
have_entry:
// entry in cache - use it
if auth != nil {
//have_entry:
<-auth.ready // make sure it is ready
auth.Lock()
......@@ -76,6 +80,7 @@ have_entry:
// project,
// time.Since(time.Unix(auth.Tauth, 0)),
// auth.Nhit)
authReply = auth.AuthReply
auth.Unlock()
// no entry - relock the cache in exclusive mode, create empty entry,
......@@ -100,6 +105,8 @@ have_entry:
auth.Tauth = time.Now().Unix()
auth.Nhit = 0
authReply = auth.AuthReply
// broadcast to other goroutines this entry is ready
close(auth.ready)
......@@ -107,12 +114,12 @@ have_entry:
go c.refreshEntry(auth, u, project)
}
return auth.AuthReply
return authReply
}
// Time period for refreshing / removing unused entires in authCache
const authCacheRefresh = 10 * time.Second // XXX 30
const authCacheRefresh = 5 * time.Second // XXX 30
// Goroutine to refresh auth cache entry periodically while it is used.
// if the entry is detected to be not used - remove it from cache and stop refreshing.
......
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