MCPcopy
hub / github.com/grafana/tempo / UpsertEdge

Method UpsertEdge

modules/generator/processor/servicegraphs/store/store.go:101–141  ·  view source on GitHub ↗

UpsertEdge fetches an Edge from the store and updates it using the given callback. If the Edge doesn't exist yet, it creates a new one with the default TTL. If the Edge is complete after applying the callback, it's completed and removed.

(key string, side Side, update Callback)

Source from the content-addressed store, hash-verified

99// doesn't exist yet, it creates a new one with the default TTL.
100// If the Edge is complete after applying the callback, it's completed and removed.
101func (s *store) UpsertEdge(key string, side Side, update Callback) (isNew bool, err error) {
102 s.mtx.Lock()
103 defer s.mtx.Unlock()
104
105 if storedEdge, ok := s.m[key]; ok {
106 edge := storedEdge.Value.(*Edge)
107 update(edge)
108
109 if edge.isComplete() {
110 s.onComplete(edge)
111 s.deleteEdge(storedEdge)
112 }
113
114 return false, nil
115 }
116
117 if s.hasDroppedCounterpart(key, side) {
118 return true, ErrDroppedSpanSide
119 }
120
121 edge := s.grabEdge(key)
122 update(edge)
123
124 if edge.isComplete() {
125 s.onComplete(edge)
126 s.returnEdge(edge)
127 return true, nil
128 }
129
130 // Check we can add new edges
131 if s.l.Len() >= s.maxItems {
132 // todo: try to evict expired items
133 s.returnEdge(edge)
134 return false, ErrTooManyItems
135 }
136
137 ele := s.l.PushBack(edge)
138 s.m[key] = ele
139
140 return true, nil
141}
142
143// Expire evicts all expired items in the store.
144func (s *store) Expire() {

Callers

nothing calls this directly

Calls 7

deleteEdgeMethod · 0.95
hasDroppedCounterpartMethod · 0.95
grabEdgeMethod · 0.95
returnEdgeMethod · 0.95
isCompleteMethod · 0.80
onCompleteMethod · 0.80
LenMethod · 0.65

Tested by

no test coverage detected