mirror of https://github.com/hashicorp/consul
Ensure that Cache options are reloaded when `consul reload` is performed.
This will apply cache throttling parameters are properly applied: * cache.EntryFetchMaxBurst * cache.EntryFetchRate When values are updated, a log is displayed in info.pull/8552/head
parent
dfcd9c00cf
commit
d2be9d38da
|
@ -3748,6 +3748,12 @@ func (a *Agent) reloadConfigInternal(newCfg *config.RuntimeConfig) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if a.cache.ReloadOptions(newCfg.Cache) {
|
||||||
|
a.logger.Info("Cache options have been updated")
|
||||||
|
} else {
|
||||||
|
a.logger.Debug("Cache options have not been modified")
|
||||||
|
}
|
||||||
|
|
||||||
// Update filtered metrics
|
// Update filtered metrics
|
||||||
metrics.UpdateFilter(newCfg.Telemetry.AllowedPrefixes,
|
metrics.UpdateFilter(newCfg.Telemetry.AllowedPrefixes,
|
||||||
newCfg.Telemetry.BlockedPrefixes)
|
newCfg.Telemetry.BlockedPrefixes)
|
||||||
|
|
|
@ -144,16 +144,21 @@ type Options struct {
|
||||||
EntryFetchRate rate.Limit
|
EntryFetchRate rate.Limit
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new cache with the given RPC client and reasonable defaults.
|
// applyDefaultValuesOnOptions set default values on options and returned updated value
|
||||||
// Further settings can be tweaked on the returned value.
|
func applyDefaultValuesOnOptions(options Options) Options {
|
||||||
func New(options Options) *Cache {
|
|
||||||
if options.EntryFetchRate == 0.0 {
|
if options.EntryFetchRate == 0.0 {
|
||||||
options.EntryFetchRate = DefaultEntryFetchRate
|
options.EntryFetchRate = DefaultEntryFetchRate
|
||||||
}
|
}
|
||||||
if options.EntryFetchMaxBurst == 0 {
|
if options.EntryFetchMaxBurst == 0 {
|
||||||
options.EntryFetchMaxBurst = DefaultEntryFetchMaxBurst
|
options.EntryFetchMaxBurst = DefaultEntryFetchMaxBurst
|
||||||
}
|
}
|
||||||
|
return options
|
||||||
|
}
|
||||||
|
|
||||||
|
// New creates a new cache with the given RPC client and reasonable defaults.
|
||||||
|
// Further settings can be tweaked on the returned value.
|
||||||
|
func New(options Options) *Cache {
|
||||||
|
options = applyDefaultValuesOnOptions(options)
|
||||||
// Initialize the heap. The buffer of 1 is really important because
|
// Initialize the heap. The buffer of 1 is really important because
|
||||||
// its possible for the expiry loop to trigger the heap to update
|
// its possible for the expiry loop to trigger the heap to update
|
||||||
// itself and it'd block forever otherwise.
|
// itself and it'd block forever otherwise.
|
||||||
|
@ -234,6 +239,28 @@ func (c *Cache) RegisterType(n string, typ Type) {
|
||||||
c.types[n] = typeEntry{Name: n, Type: typ, Opts: &opts}
|
c.types[n] = typeEntry{Name: n, Type: typ, Opts: &opts}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReloadOptions updates the cache with the new options
|
||||||
|
// return true if Cache is updated, false if already up to date
|
||||||
|
func (c *Cache) ReloadOptions(options Options) bool {
|
||||||
|
options = applyDefaultValuesOnOptions(options)
|
||||||
|
if c.options.EntryFetchRate != options.EntryFetchRate || c.options.EntryFetchMaxBurst != options.EntryFetchMaxBurst {
|
||||||
|
c.entriesLock.RLock()
|
||||||
|
defer c.entriesLock.RUnlock()
|
||||||
|
for _, entry := range c.entries {
|
||||||
|
if c.options.EntryFetchRate != options.EntryFetchRate {
|
||||||
|
entry.FetchRateLimiter.SetLimit(options.EntryFetchRate)
|
||||||
|
}
|
||||||
|
if c.options.EntryFetchMaxBurst != options.EntryFetchMaxBurst {
|
||||||
|
entry.FetchRateLimiter.SetBurst(options.EntryFetchMaxBurst)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c.options.EntryFetchRate = options.EntryFetchRate
|
||||||
|
c.options.EntryFetchMaxBurst = options.EntryFetchMaxBurst
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// Get loads the data for the given type and request. If data satisfying the
|
// Get loads the data for the given type and request. If data satisfying the
|
||||||
// minimum index is present in the cache, it is returned immediately. Otherwise,
|
// minimum index is present in the cache, it is returned immediately. Otherwise,
|
||||||
// this will block until the data is available or the request timeout is
|
// this will block until the data is available or the request timeout is
|
||||||
|
|
Loading…
Reference in New Issue