Skip to content

Commit

Permalink
add ut
Browse files Browse the repository at this point in the history
Signed-off-by: shaoting-huang <[email protected]>
  • Loading branch information
shaoting-huang committed Jun 20, 2024
1 parent 2729bef commit e10672b
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions internal/storage/data_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -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()
Expand Down

0 comments on commit e10672b

Please sign in to comment.