Skip to content

Commit 4d1dc4d

Browse files
dinalDina Nimrodi
and
Dina Nimrodi
authored
[IG-15609] handle error in NextPart (#495) (#496)
* catch error * throw error and handle in writeChunks * remove print * return err without pushing metric back to queue Co-authored-by: Dina Nimrodi <[email protected]> Co-authored-by: Dina Nimrodi <[email protected]>
1 parent 61898d6 commit 4d1dc4d

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

Diff for: pkg/appender/store.go

+21-11
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,12 @@ func (cs *chunkStore) Append(t int64, v interface{}) {
238238
}
239239

240240
// Return current, previous, or create new chunk based on sample time
241-
func (cs *chunkStore) chunkByTime(t int64, isVariantEncoding bool) *attrAppender {
241+
func (cs *chunkStore) chunkByTime(t int64, isVariantEncoding bool) (*attrAppender, error) {
242242

243243
// Sample is in the current chunk
244244
cur := cs.chunks[cs.curChunk]
245245
if cur.inRange(t) {
246-
return cur
246+
return cur, nil
247247
}
248248

249249
// Sample is in the next chunk, need to initialize
@@ -255,29 +255,32 @@ func (cs *chunkStore) chunkByTime(t int64, isVariantEncoding bool) *attrAppender
255255
chunk := chunkenc.NewChunk(cs.logger, isVariantEncoding) // TODO: init based on schema, use init function
256256
app, err := chunk.Appender()
257257
if err != nil {
258-
return nil
258+
return nil, err
259+
}
260+
nextPart, err := part.NextPart(t)
261+
if err != nil {
262+
return nil, err
259263
}
260-
nextPart, _ := part.NextPart(t)
261264
cur.initialize(nextPart, t)
262265
cs.nextTid = t
263266
cur.appender = app
264267
cs.curChunk = cs.curChunk ^ 1
265268

266-
return cur
269+
return cur, nil
267270
}
268271

269272
// If it's the first chunk after init we don't allow old updates
270273
if (cur.state & chunkStateFirst) != 0 {
271-
return nil
274+
return nil, nil
272275
}
273276

274277
prev := cs.chunks[cs.curChunk^1]
275278
// Delayed appends - only allowed to previous chunk or within allowed window
276279
if prev.partition != nil && prev.inRange(t) && t > cs.maxTime-maxLateArrivalInterval {
277-
return prev
280+
return prev, nil
278281
}
279282

280-
return nil
283+
return nil, nil
281284
}
282285

283286
// Write all pending samples to DB chunks and aggregates
@@ -327,7 +330,6 @@ func (cs *chunkStore) writeChunks(mc *MetricsCache, metric *MetricState) (hasPen
327330
expr = expr + cs.aggrList.SetOrUpdateExpr("v", bucket, isNewBucket)
328331
expr = expr + cs.appendExpression(activeChunk)
329332
}
330-
331333
pendingSampleIndex++
332334
break
333335
} else {
@@ -339,7 +341,11 @@ func (cs *chunkStore) writeChunks(mc *MetricsCache, metric *MetricState) (hasPen
339341
// Init activeChunk if nil (when samples are too old); if still too
340342
// old, skip to next sample
341343
if !cs.isAggr() && activeChunk == nil {
342-
activeChunk = cs.chunkByTime(sampleTime, metric.isVariant)
344+
activeChunk, err = cs.chunkByTime(sampleTime, metric.isVariant)
345+
if err != nil {
346+
hasPendingUpdates = false
347+
return
348+
}
343349
if activeChunk == nil {
344350
pendingSampleIndex++
345351
mc.logger.DebugWith("nil active chunk", "T", sampleTime)
@@ -385,7 +391,11 @@ func (cs *chunkStore) writeChunks(mc *MetricsCache, metric *MetricState) (hasPen
385391
// initialize the new chunk
386392
if activeChunk != nil && !activeChunk.inRange(nextT) {
387393
expr = expr + cs.appendExpression(activeChunk)
388-
activeChunk = cs.chunkByTime(nextT, metric.isVariant)
394+
activeChunk, err = cs.chunkByTime(nextT, metric.isVariant)
395+
if err != nil {
396+
hasPendingUpdates = false
397+
return
398+
}
389399
}
390400

391401
pendingSampleIndex++

0 commit comments

Comments
 (0)