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

Method updateInternal

tempodb/blocklist/list.go:127–194  ·  view source on GitHub ↗

updateInternal exists to do the work of applying updates to held PerTenant and PerTenantCompacted maps it must be called under lock

(tenantID string, add []*backend.BlockMeta, remove []*backend.BlockMeta, compactedAdd []*backend.CompactedBlockMeta, compactedRemove []*backend.CompactedBlockMeta)

Source from the content-addressed store, hash-verified

125// updateInternal exists to do the work of applying updates to held PerTenant and PerTenantCompacted maps
126// it must be called under lock
127func (l *List) updateInternal(tenantID string, add []*backend.BlockMeta, remove []*backend.BlockMeta, compactedAdd []*backend.CompactedBlockMeta, compactedRemove []*backend.CompactedBlockMeta) {
128 hasID := func(id backend.UUID) func(*backend.BlockMeta) bool {
129 return func(b *backend.BlockMeta) bool {
130 return b.BlockID == id
131 }
132 }
133
134 hasIDC := func(id backend.UUID) func(*backend.CompactedBlockMeta) bool {
135 return func(b *backend.CompactedBlockMeta) bool {
136 return b.BlockID == id
137 }
138 }
139
140 // ******** Regular blocks ********
141 if len(add) > 0 || len(remove) > 0 || len(compactedAdd) > 0 || len(compactedRemove) > 0 {
142 var (
143 existing = l.metas[tenantID]
144 final = make([]*backend.BlockMeta, 0, max(0, len(existing)+len(add)-len(remove)))
145 )
146
147 // rebuild dropping all removals
148 for _, b := range existing {
149 if slices.ContainsFunc(remove, hasID(b.BlockID)) {
150 continue
151 }
152 final = append(final, b)
153 }
154 // add new if they don't already exist and weren't also removed
155 for _, b := range add {
156 if slices.ContainsFunc(final, hasID(b.BlockID)) ||
157 slices.ContainsFunc(remove, hasID(b.BlockID)) ||
158 slices.ContainsFunc(compactedAdd, hasIDC(b.BlockID)) ||
159 slices.ContainsFunc(compactedRemove, hasIDC(b.BlockID)) {
160 continue
161 }
162
163 final = append(final, b)
164 }
165
166 l.metas[tenantID] = final
167 }
168
169 // ******** Compacted blocks ********
170 if len(compactedAdd) > 0 || len(compactedRemove) > 0 {
171 var (
172 existing = l.compactedMetas[tenantID]
173 final = make([]*backend.CompactedBlockMeta, 0, max(0, len(existing)+len(compactedAdd)-len(compactedRemove)))
174 )
175
176 // rebuild dropping all removals
177 for _, b := range existing {
178 if slices.ContainsFunc(compactedRemove, hasIDC(b.BlockID)) {
179 continue
180 }
181 final = append(final, b)
182 }
183 // add new if they don't already exist and weren't also removed
184 for _, b := range compactedAdd {

Callers 2

ApplyPollResultsMethod · 0.95
UpdateMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected