diff options
author | 2021-04-05 15:45:28 +0200 | |
---|---|---|
committer | 2021-04-05 06:45:28 -0700 | |
commit | 13cef2ee090ce122e960761e2a26113b6300a722 (patch) | |
tree | 0cd6c546cc5401a9b7cadcfeb71f53d5239f0942 /plugin/pkg/cache/cache.go | |
parent | 454bc9e0b96b86dfa458400959907b6854448764 (diff) | |
download | coredns-13cef2ee090ce122e960761e2a26113b6300a722.tar.gz coredns-13cef2ee090ce122e960761e2a26113b6300a722.tar.zst coredns-13cef2ee090ce122e960761e2a26113b6300a722.zip |
plugin/dnssec: use entire RRset as key input (#4537)
* plugin/dnssec: use entire RRset as key input
This uses the entire rrset as input for the hash key; this is to detect
differences in the RRset and generate the correct signature.
As this would then lead to unbounded growth, we periodically (every 8h)
prune the cache of old entries. In theory we could rely on the random
eviction, but it seems nicer to do this in a maintannce loop so that we
remove the unused ones. This required adding a Walk function to the
plugin/pkg/cache.
Signed-off-by: Miek Gieben <miek@miek.nl>
* Update plugin/dnssec/cache.go
Co-authored-by: Chris O'Haver <cohaver@infoblox.com>
Co-authored-by: Chris O'Haver <cohaver@infoblox.com>
Diffstat (limited to 'plugin/pkg/cache/cache.go')
-rw-r--r-- | plugin/pkg/cache/cache.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/plugin/pkg/cache/cache.go b/plugin/pkg/cache/cache.go index 19a4e7a80..19b35e870 100644 --- a/plugin/pkg/cache/cache.go +++ b/plugin/pkg/cache/cache.go @@ -72,6 +72,13 @@ func (c *Cache) Len() int { return l } +// Walk walks each shard in the cache. +func (c *Cache) Walk(f func(map[uint64]interface{}, uint64) bool) { + for _, s := range c.shards { + s.Walk(f) + } +} + // newShard returns a new shard with size. func newShard(size int) *shard { return &shard{items: make(map[uint64]interface{}), size: size} } @@ -127,4 +134,24 @@ func (s *shard) Len() int { return l } +// Walk walks the shard for each element the function f is executed while holding a write lock. +func (s *shard) Walk(f func(map[uint64]interface{}, uint64) bool) { + items := make([]uint64, len(s.items)) + s.RLock() + i := 0 + for k := range s.items { + items[i] = k + i++ + } + s.RUnlock() + for _, k := range items { + s.Lock() + ok := f(s.items, k) + s.Unlock() + if !ok { + return + } + } +} + const shardSize = 256 |