@@ -155,20 +155,16 @@ func getBlocksMatchingBounds(metas []bloomshipper.Meta, bounds v1.FingerprintBou
155
155
return deduped , nil
156
156
}
157
157
158
- type seriesWithChunks struct {
159
- tsdb tsdb.SingleTenantTSDBIdentifier
160
- fp model.Fingerprint
161
- chunks []index.ChunkMeta
162
- }
163
-
164
158
type seriesBatch struct {
165
- series []seriesWithChunks
159
+ tsdb tsdb.SingleTenantTSDBIdentifier
160
+ series []* v1.Series
166
161
size uint64
167
162
}
168
163
169
- func newSeriesBatch () seriesBatch {
164
+ func newSeriesBatch (tsdb tsdb. SingleTenantTSDBIdentifier ) seriesBatch {
170
165
return seriesBatch {
171
- series : make ([]seriesWithChunks , 0 , 100 ),
166
+ tsdb : tsdb ,
167
+ series : make ([]* v1.Series , 0 , 100 ),
172
168
}
173
169
}
174
170
@@ -179,31 +175,14 @@ func (b *seriesBatch) Bounds() v1.FingerprintBounds {
179
175
180
176
// We assume that the series are sorted by fingerprint.
181
177
// This is guaranteed since series are iterated in order by the TSDB.
182
- return v1 .NewBounds (b .series [0 ].fp , b .series [len (b .series )- 1 ].fp )
178
+ return v1 .NewBounds (b .series [0 ].Fingerprint , b .series [len (b .series )- 1 ].Fingerprint )
183
179
}
184
180
185
181
func (b * seriesBatch ) V1Series () []* v1.Series {
186
- series := make ([]* v1.Series , 0 , len (b .series ))
187
- for _ , s := range b .series {
188
- res := & v1.Series {
189
- Fingerprint : s .fp ,
190
- Chunks : make (v1.ChunkRefs , 0 , len (s .chunks )),
191
- }
192
- for _ , chk := range s .chunks {
193
- res .Chunks = append (res .Chunks , v1.ChunkRef {
194
- From : model .Time (chk .MinTime ),
195
- Through : model .Time (chk .MaxTime ),
196
- Checksum : chk .Checksum ,
197
- })
198
- }
199
-
200
- series = append (series , res )
201
- }
202
-
203
- return series
182
+ return b .series
204
183
}
205
184
206
- func (b * seriesBatch ) Append (s seriesWithChunks , size uint64 ) {
185
+ func (b * seriesBatch ) Append (s * v1. Series , size uint64 ) {
207
186
b .series = append (b .series , s )
208
187
b .size += size
209
188
}
@@ -217,10 +196,7 @@ func (b *seriesBatch) Size() uint64 {
217
196
}
218
197
219
198
func (b * seriesBatch ) TSDB () tsdb.SingleTenantTSDBIdentifier {
220
- if len (b .series ) == 0 {
221
- return tsdb.SingleTenantTSDBIdentifier {}
222
- }
223
- return b .series [0 ].tsdb
199
+ return b .tsdb
224
200
}
225
201
226
202
func (s * ChunkSizeStrategy ) sizedSeriesIter (
@@ -230,9 +206,14 @@ func (s *ChunkSizeStrategy) sizedSeriesIter(
230
206
targetTaskSizeBytes uint64 ,
231
207
) (iter.Iterator [seriesBatch ], int , error ) {
232
208
batches := make ([]seriesBatch , 0 , 100 )
233
- currentBatch := newSeriesBatch ()
209
+ var currentBatch seriesBatch
234
210
235
211
for _ , idx := range tsdbsWithGaps {
212
+ if currentBatch .Len () > 0 {
213
+ batches = append (batches , currentBatch )
214
+ }
215
+ currentBatch = newSeriesBatch (idx .tsdbIdentifier )
216
+
236
217
for _ , gap := range idx .gaps {
237
218
if err := idx .tsdb .ForSeries (
238
219
ctx ,
@@ -253,14 +234,22 @@ func (s *ChunkSizeStrategy) sizedSeriesIter(
253
234
// AND Adding this series to the batch would exceed the target task size.
254
235
if currentBatch .Len () > 0 && currentBatch .Size ()+ seriesSize > targetTaskSizeBytes {
255
236
batches = append (batches , currentBatch )
256
- currentBatch = newSeriesBatch ()
237
+ currentBatch = newSeriesBatch (idx .tsdbIdentifier )
238
+ }
239
+
240
+ res := & v1.Series {
241
+ Fingerprint : fp ,
242
+ Chunks : make (v1.ChunkRefs , 0 , len (chks )),
243
+ }
244
+ for _ , chk := range chks {
245
+ res .Chunks = append (res .Chunks , v1.ChunkRef {
246
+ From : model .Time (chk .MinTime ),
247
+ Through : model .Time (chk .MaxTime ),
248
+ Checksum : chk .Checksum ,
249
+ })
257
250
}
258
251
259
- currentBatch .Append (seriesWithChunks {
260
- tsdb : idx .tsdbIdentifier ,
261
- fp : fp ,
262
- chunks : chks ,
263
- }, seriesSize )
252
+ currentBatch .Append (res , seriesSize )
264
253
return false
265
254
}
266
255
},
@@ -269,10 +258,10 @@ func (s *ChunkSizeStrategy) sizedSeriesIter(
269
258
return nil , 0 , err
270
259
}
271
260
272
- // Add the last batch for this TSDB if it's not empty.
261
+ // Add the last batch for this gap if it's not empty.
273
262
if currentBatch .Len () > 0 {
274
263
batches = append (batches , currentBatch )
275
- currentBatch = newSeriesBatch ()
264
+ currentBatch = newSeriesBatch (idx . tsdbIdentifier )
276
265
}
277
266
}
278
267
}
0 commit comments