diff --git a/internal/storage/data_codec.go b/internal/storage/data_codec.go index 140bff813a113..0a9770c82083a 100644 --- a/internal/storage/data_codec.go +++ b/internal/storage/data_codec.go @@ -993,24 +993,32 @@ func (deleteCodec *DeleteCodec) Serialize(collectionID UniqueID, partitionID Uni func (deleteCodec *DeleteCodec) SerializeV2(collectionID UniqueID, partitionID UniqueID, segmentID UniqueID, data *DeleteData) ([]*Blob, error) { blobs := make([]*Blob, 0) var binlogWriter *DeleteBinlogWriter + length := len(data.Pks) + if length != len(data.Tss) { + return nil, fmt.Errorf("the length of pks, and TimeStamps is not equal") + } + var startTs, endTs Timestamp + startTs, endTs = math.MaxUint64, 0 + for i := 0; i < length; i++ { + ts := data.Tss[i] + if ts < startTs { + startTs = ts + } + if ts > endTs { + endTs = ts + } + } for k := 0; k < 2; k++ { binlogWriter = NewDeleteBinlogWriter(schemapb.DataType_String, collectionID, partitionID, segmentID) eventWriter, err := binlogWriter.NextDeleteEventWriter() + eventWriter.SetEventTimestamp(startTs, endTs) if err != nil { eventWriter.Close() binlogWriter.Close() return nil, err } - length := len(data.Pks) - if length != len(data.Tss) { - return nil, fmt.Errorf("the length of pks, and TimeStamps is not equal") - } - sizeTotal := 0 - var startTs, endTs Timestamp - startTs, endTs = math.MaxUint64, 0 - for i := 0; i < length; i++ { if k == 0 { // write pk pkStr := strconv.FormatInt(data.Pks[i].GetValue().(int64), 10) @@ -1023,12 +1031,6 @@ func (deleteCodec *DeleteCodec) SerializeV2(collectionID UniqueID, partitionID U sizeTotal += len(pkStr) } else if k == 1 { // write ts ts := data.Tss[i] - if ts < startTs { - startTs = ts - } - if ts > endTs { - endTs = ts - } tsStr := strconv.FormatUint(ts, 10) err = eventWriter.AddOneStringToPayload(tsStr) if err != nil { @@ -1037,11 +1039,11 @@ func (deleteCodec *DeleteCodec) SerializeV2(collectionID UniqueID, partitionID U return nil, err } sizeTotal += len(tsStr) - eventWriter.SetEventTimestamp(startTs, endTs) - binlogWriter.SetEventTimeStamp(startTs, endTs) - binlogWriter.AddExtra(originalSizeKey, fmt.Sprintf("%v", sizeTotal)) } } + + binlogWriter.SetEventTimeStamp(startTs, endTs) + binlogWriter.AddExtra(originalSizeKey, fmt.Sprintf("%v", sizeTotal)) err = binlogWriter.Finish() if err != nil { eventWriter.Close()