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())
| 590 | // tryFinalize emits a terminal response once per transaction UID. |
| 591 | // Later terminal attempts for the same UID are dropped while tombstone is active. |
| 592 | func (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 | |
| 626 | func (m *Manager) pruneExpiredTombstonesLocked(now time.Time) { |
| 627 | for uid, expiresAt := range m.tombstones { |