@@ -210,17 +210,30 @@ func (t tsdbTokenRange) reassemble(from int) tsdbTokenRange {
210
210
return t [:len (t )- (reassembleTo - from )]
211
211
}
212
212
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
+
214
216
// Sort metas descending by most recent source when checking
215
217
// for outdated metas (older metas are discarded if they don't change the range).
216
218
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 )
220
225
}
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
224
237
}
225
238
return ! a .TS .Before (b .TS )
226
239
})
@@ -231,9 +244,11 @@ func outdatedMetas(metas []bloomshipper.Meta) (outdated []bloomshipper.Meta, err
231
244
)
232
245
233
246
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 )
237
252
}
238
253
version := int (model .TimeFromUnixNano (mostRecent .TS .UnixNano ()))
239
254
tokenRange , added = tokenRange .Add (version , meta .Bounds )
@@ -242,6 +257,5 @@ func outdatedMetas(metas []bloomshipper.Meta) (outdated []bloomshipper.Meta, err
242
257
}
243
258
}
244
259
245
- return outdated , nil
246
-
260
+ return outdated
247
261
}
0 commit comments