parent
d514ff573a
commit
ce42e9ea1f
8
command/agent/cache/lease_cache.go
vendored
8
command/agent/cache/lease_cache.go
vendored
|
@ -12,6 +12,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/hashicorp/errwrap"
|
"github.com/hashicorp/errwrap"
|
||||||
hclog "github.com/hashicorp/go-hclog"
|
hclog "github.com/hashicorp/go-hclog"
|
||||||
|
@ -69,6 +70,7 @@ type LeaseCache struct {
|
||||||
logger hclog.Logger
|
logger hclog.Logger
|
||||||
db *cachememdb.CacheMemDB
|
db *cachememdb.CacheMemDB
|
||||||
baseCtxInfo *cachememdb.ContextInfo
|
baseCtxInfo *cachememdb.ContextInfo
|
||||||
|
l *sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// LeaseCacheConfig is the configuration for initializing a new
|
// LeaseCacheConfig is the configuration for initializing a new
|
||||||
|
@ -108,6 +110,7 @@ func NewLeaseCache(conf *LeaseCacheConfig) (*LeaseCache, error) {
|
||||||
logger: conf.Logger,
|
logger: conf.Logger,
|
||||||
db: db,
|
db: db,
|
||||||
baseCtxInfo: baseCtxInfo,
|
baseCtxInfo: baseCtxInfo,
|
||||||
|
l: &sync.RWMutex{},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -305,7 +308,9 @@ func (c *LeaseCache) Send(ctx context.Context, req *SendRequest) (*SendResponse,
|
||||||
|
|
||||||
func (c *LeaseCache) createCtxInfo(ctx context.Context) *cachememdb.ContextInfo {
|
func (c *LeaseCache) createCtxInfo(ctx context.Context) *cachememdb.ContextInfo {
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
|
c.l.RLock()
|
||||||
ctx = c.baseCtxInfo.Ctx
|
ctx = c.baseCtxInfo.Ctx
|
||||||
|
c.l.RUnlock()
|
||||||
}
|
}
|
||||||
return cachememdb.NewContextInfo(ctx)
|
return cachememdb.NewContextInfo(ctx)
|
||||||
}
|
}
|
||||||
|
@ -500,14 +505,15 @@ func (c *LeaseCache) handleCacheClear(ctx context.Context, clearType string, cle
|
||||||
// Cancel the base context which triggers all the goroutines to
|
// Cancel the base context which triggers all the goroutines to
|
||||||
// stop and evict entries from cache.
|
// stop and evict entries from cache.
|
||||||
c.logger.Debug("canceling base context")
|
c.logger.Debug("canceling base context")
|
||||||
|
c.l.Lock()
|
||||||
c.baseCtxInfo.CancelFunc()
|
c.baseCtxInfo.CancelFunc()
|
||||||
|
|
||||||
// Reset the base context
|
// Reset the base context
|
||||||
baseCtx, baseCancel := context.WithCancel(ctx)
|
baseCtx, baseCancel := context.WithCancel(ctx)
|
||||||
c.baseCtxInfo = &cachememdb.ContextInfo{
|
c.baseCtxInfo = &cachememdb.ContextInfo{
|
||||||
Ctx: baseCtx,
|
Ctx: baseCtx,
|
||||||
CancelFunc: baseCancel,
|
CancelFunc: baseCancel,
|
||||||
}
|
}
|
||||||
|
c.l.Unlock()
|
||||||
|
|
||||||
// Reset the memdb instance
|
// Reset the memdb instance
|
||||||
if err := c.db.Flush(); err != nil {
|
if err := c.db.Flush(); err != nil {
|
||||||
|
|
Loading…
Reference in a new issue