MCPcopy Index your code
hub / github.com/netdata/netdata / tryFinalize

Method tryFinalize

src/go/plugin/framework/functions/manager.go:592–624  ·  view source on GitHub ↗

tryFinalize emits a terminal response once per transaction UID. Later terminal attempts for the same UID are dropped while tombstone is active.

(uid, source string, emit func())

Source from the content-addressed store, hash-verified

590// tryFinalize emits a terminal response once per transaction UID.
591// Later terminal attempts for the same UID are dropped while tombstone is active.
592func (m *Manager) tryFinalize(uid, source string, emit func()) bool {
593 if uid == "" || emit == nil {
594 return false
595 }
596
597 m.invStateMux.Lock()
598 now := time.Now()
599 m.pruneExpiredTombstonesLocked(now)
600 if _, ok := m.tombstones[uid]; ok {
601 m.invStateMux.Unlock()
602 m.Debugf("dropping late terminal response for uid '%s' (source=%s)", uid, source)
603 m.observeLateTerminalDropped()
604 return false
605 }
606
607 var scheduleKey string
608 if rec, ok := m.invState[uid]; ok && rec != nil {
609 m.stopTimersLocked(rec)
610 scheduleKey = rec.scheduleKey
611 }
612 delete(m.invState, uid)
613 m.tombstones[uid] = now.Add(m.tombstoneTTL)
614 m.observeInvocationsLocked()
615 m.invStateMux.Unlock()
616
617 if scheduleKey != "" && m.scheduler != nil {
618 m.scheduler.complete(scheduleKey, uid)
619 m.observeSchedulerPending()
620 }
621
622 emit()
623 return true
624}
625
626func (m *Manager) pruneExpiredTombstonesLocked(now time.Time) {
627 for uid, expiresAt := range m.tombstones {

Callers 2

finalizeTerminalMethod · 0.95
TestManager_tryFinalizeFunction · 0.80

Calls 11

stopTimersLockedMethod · 0.95
emitFunction · 0.85
LockMethod · 0.80
UnlockMethod · 0.80
completeMethod · 0.80
DebugfMethod · 0.65
AddMethod · 0.65

Tested by 1

TestManager_tryFinalizeFunction · 0.64