From 8cb09ab83aa2f89b868a95bed647a845c92f9a71 Mon Sep 17 00:00:00 2001 From: xige-16 Date: Mon, 17 Jul 2023 11:54:28 +0800 Subject: [PATCH] Fix querynode panic when binlog ts wrong Signed-off-by: xige-16 --- internal/core/src/storage/DataCodec.h | 3 ++- internal/storage/data_codec.go | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/internal/core/src/storage/DataCodec.h b/internal/core/src/storage/DataCodec.h index cb09a6ff1e0e6..7def219eb9471 100644 --- a/internal/core/src/storage/DataCodec.h +++ b/internal/core/src/storage/DataCodec.h @@ -44,7 +44,8 @@ class DataCodec { void SetTimestamps(Timestamp start_timestamp, Timestamp end_timestamp) { - assert(start_timestamp <= end_timestamp); + // if milvus version <= 2.2.5 + // assert(start_timestamp <= end_timestamp) condition may not be satisfied time_range_ = std::make_pair(start_timestamp, end_timestamp); } diff --git a/internal/storage/data_codec.go b/internal/storage/data_codec.go index e75a7d1f5d0b6..c919143712f5a 100644 --- a/internal/storage/data_codec.go +++ b/internal/storage/data_codec.go @@ -406,8 +406,17 @@ func (insertCodec *InsertCodec) Serialize(partitionID UniqueID, segmentID Unique rowNum := int64(timeFieldData.RowNum()) ts := timeFieldData.(*Int64FieldData).Data - startTs := ts[0] - endTs := ts[len(ts)-1] + var startTs, endTs Timestamp + startTs, endTs = math.MaxUint64, 0 + for _, t := range ts { + if uint64(t) > endTs { + endTs = uint64(t) + } + + if uint64(t) < startTs { + startTs = uint64(t) + } + } // sort insert data by rowID dataSorter := &DataSorter{ @@ -440,7 +449,7 @@ func (insertCodec *InsertCodec) Serialize(partitionID UniqueID, segmentID Unique return nil, err } - eventWriter.SetEventTimestamp(typeutil.Timestamp(startTs), typeutil.Timestamp(endTs)) + eventWriter.SetEventTimestamp(startTs, endTs) switch field.DataType { case schemapb.DataType_Bool: err = eventWriter.AddBoolToPayload(singleData.(*BoolFieldData).Data) @@ -550,7 +559,7 @@ func (insertCodec *InsertCodec) Serialize(partitionID UniqueID, segmentID Unique if err != nil { return nil, err } - writer.SetEventTimeStamp(typeutil.Timestamp(startTs), typeutil.Timestamp(endTs)) + writer.SetEventTimeStamp(startTs, endTs) err = writer.Finish() if err != nil {