Skip to content

Commit c996349

Browse files
authored
fix: Fix bloom deleter PR after merge (#13167)
1 parent 9c96d26 commit c996349

File tree

3 files changed

+29
-19
lines changed

3 files changed

+29
-19
lines changed

pkg/bloombuild/planner/planner.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,7 @@ func (p *Planner) processTenantTaskResults(
365365
}
366366

367367
combined := append(originalMetas, newMetas...)
368-
outdated, err := outdatedMetas(combined)
369-
if err != nil {
370-
return fmt.Errorf("failed to find outdated metas: %w", err)
371-
}
368+
outdated := outdatedMetas(combined)
372369
level.Debug(logger).Log("msg", "found outdated metas", "outdated", len(outdated))
373370

374371
if err := p.deleteOutdatedMetasAndBlocks(ctx, table, tenant, outdated); err != nil {
@@ -476,7 +473,7 @@ func (p *Planner) loadTenantWork(
476473

477474
// If this is the first this we see this table, initialize the map
478475
if tenantTableWork[table] == nil {
479-
tenantTableWork[table] = make(map[string][]v1.FingerprintBounds, tenants.Len())
476+
tenantTableWork[table] = make(map[string][]v1.FingerprintBounds, tenants.Remaining())
480477
}
481478

482479
for tenants.Next() && tenants.Err() == nil && ctx.Err() == nil {

pkg/bloombuild/planner/versioned_range.go

+26-12
Original file line numberDiff line numberDiff line change
@@ -210,17 +210,30 @@ func (t tsdbTokenRange) reassemble(from int) tsdbTokenRange {
210210
return t[:len(t)-(reassembleTo-from)]
211211
}
212212

213-
func outdatedMetas(metas []bloomshipper.Meta) (outdated []bloomshipper.Meta, err error) {
213+
func outdatedMetas(metas []bloomshipper.Meta) []bloomshipper.Meta {
214+
var outdated []bloomshipper.Meta
215+
214216
// Sort metas descending by most recent source when checking
215217
// for outdated metas (older metas are discarded if they don't change the range).
216218
sort.Slice(metas, func(i, j int) bool {
217-
a, err := metas[i].MostRecentSource()
218-
if err != nil {
219-
panic(err.Error())
219+
a, aExists := metas[i].MostRecentSource()
220+
b, bExists := metas[j].MostRecentSource()
221+
222+
if !aExists && !bExists {
223+
// stable sort two sourceless metas by their bounds (easier testing)
224+
return metas[i].Bounds.Less(metas[j].Bounds)
220225
}
221-
b, err := metas[j].MostRecentSource()
222-
if err != nil {
223-
panic(err.Error())
226+
227+
if !aExists {
228+
// If a meta has no sources, it's out of date by definition.
229+
// By convention we sort it to the beginning of the list and will mark it for removal later
230+
return true
231+
}
232+
233+
if !bExists {
234+
// if a exists but b does not, mark b as lesser, sorting b to the
235+
// front
236+
return false
224237
}
225238
return !a.TS.Before(b.TS)
226239
})
@@ -231,9 +244,11 @@ func outdatedMetas(metas []bloomshipper.Meta) (outdated []bloomshipper.Meta, err
231244
)
232245

233246
for _, meta := range metas {
234-
mostRecent, err := meta.MostRecentSource()
235-
if err != nil {
236-
return nil, err
247+
mostRecent, exists := meta.MostRecentSource()
248+
if !exists {
249+
// if the meta exists but does not reference a TSDB, it's out of date
250+
// TODO(owen-d): this shouldn't happen, figure out why
251+
outdated = append(outdated, meta)
237252
}
238253
version := int(model.TimeFromUnixNano(mostRecent.TS.UnixNano()))
239254
tokenRange, added = tokenRange.Add(version, meta.Bounds)
@@ -242,6 +257,5 @@ func outdatedMetas(metas []bloomshipper.Meta) (outdated []bloomshipper.Meta, err
242257
}
243258
}
244259

245-
return outdated, nil
246-
260+
return outdated
247261
}

pkg/bloombuild/planner/versioned_range_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,7 @@ func Test_OutdatedMetas(t *testing.T) {
315315
},
316316
} {
317317
t.Run(tc.desc, func(t *testing.T) {
318-
outdated, err := outdatedMetas(tc.metas)
319-
require.NoError(t, err)
318+
outdated := outdatedMetas(tc.metas)
320319
require.Equal(t, tc.exp, outdated)
321320
})
322321
}

0 commit comments

Comments
 (0)