From 215eba0b82d03f5101fc1d0b1fe03fdcd6575cc6 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Sun, 26 Jul 2020 12:09:01 +0300 Subject: [PATCH] app/vminsert: flush bufs if needed after the current row is added Previously the data for the added row could be overwritten by the flush before the row addition is complete. --- app/vminsert/common/insert_ctx.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/vminsert/common/insert_ctx.go b/app/vminsert/common/insert_ctx.go index 6f01c845b..ce6ff849f 100644 --- a/app/vminsert/common/insert_ctx.go +++ b/app/vminsert/common/insert_ctx.go @@ -70,11 +70,6 @@ func (ctx *InsertCtx) WriteDataPointExt(metricNameRaw []byte, labels []prompb.La } func (ctx *InsertCtx) addRow(metricNameRaw []byte, timestamp int64, value float64) error { - if len(ctx.metricNamesBuf) > 16*1024*1024 { - if err := ctx.FlushBufs(); err != nil { - return err - } - } mrs := ctx.mrs if cap(mrs) > len(mrs) { mrs = mrs[:len(mrs)+1] @@ -86,6 +81,11 @@ func (ctx *InsertCtx) addRow(metricNameRaw []byte, timestamp int64, value float6 mr.MetricNameRaw = metricNameRaw mr.Timestamp = timestamp mr.Value = value + if len(ctx.metricNamesBuf) > 16*1024*1024 { + if err := ctx.FlushBufs(); err != nil { + return err + } + } return nil }