MCPcopy
hub / github.com/netdata/netdata / checkAndRecordHash

Function checkAndRecordHash

packaging/tools/agent-events/server.go:197–213  ·  view source on GitHub ↗

checkAndRecordHash accepts the SHA256 hash ([32]byte) for checking. It now REFRESHES the timestamp whenever a hash is found, effectively creating a sliding deduplication window.

(hash [32]byte)

Source from the content-addressed store, hash-verified

195// It now REFRESHES the timestamp whenever a hash is found,
196// effectively creating a sliding deduplication window.
197func checkAndRecordHash(hash [32]byte) bool {
198 now := time.Now()
199 mapMutex.Lock()
200 defer mapMutex.Unlock()
201 var zeroHash [32]byte
202 if hash == zeroHash {
203 slog.Warn("potentially zero hash received", "hash", fmt.Sprintf("%x", hash))
204 }
205 entry, found := seenIDs[hash]
206 if found {
207 isRecentDuplicate := now.Sub(entry.timestamp) < dedupWindow
208 seenIDs[hash] = seenEntry{timestamp: now}
209 return !isRecentDuplicate
210 }
211 seenIDs[hash] = seenEntry{timestamp: now}
212 return true
213}
214
215// cleanupExpiredEntries uses the hash ([32]byte) as the key type.
216func cleanupExpiredEntries(interval time.Duration) {

Callers 1

handlerFunction · 0.85

Calls 3

LockMethod · 0.80
UnlockMethod · 0.80
SubMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…