Skip to content

Commit

Permalink
Fix potential crash bug of bulkinsert (milvus-io#24596)
Browse files Browse the repository at this point in the history
Signed-off-by: yhmo <yihua.mo@zilliz.com>
  • Loading branch information
yhmo authored Jun 2, 2023
1 parent 1a60fe4 commit 9ffcd53
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
4 changes: 4 additions & 0 deletions internal/datanode/data_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,10 @@ func assignSegmentFunc(node *DataNode, req *datapb.ImportTaskRequest) importutil
if resp.Status.ErrorCode != commonpb.ErrorCode_Success {
return 0, "", fmt.Errorf("syncSegmentID Failed:%s", resp.Status.Reason)
}
if len(resp.SegIDAssignments) == 0 || resp.SegIDAssignments[0] == nil {
return 0, "", fmt.Errorf("syncSegmentID Failed: the collection was dropped")
}

segmentID := resp.SegIDAssignments[0].SegID
log.Info("new segment assigned",
zap.Int64("task ID", importTaskID),
Expand Down
5 changes: 5 additions & 0 deletions internal/datanode/data_node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,11 @@ func TestDataNode(t *testing.T) {
assert.NoError(t, err)
node.dataCoord.(*DataCoordFactory).AddSegmentNotSuccess = false

node.dataCoord.(*DataCoordFactory).AddSegmentEmpty = true
_, err = node.Import(context.WithValue(ctx, ctxKey{}, ""), req)
assert.NoError(t, err)
node.dataCoord.(*DataCoordFactory).AddSegmentEmpty = false

stat, err := node.Import(context.WithValue(ctx, ctxKey{}, ""), req)
assert.NoError(t, err)
assert.Equal(t, commonpb.ErrorCode_Success, stat.GetErrorCode())
Expand Down
16 changes: 14 additions & 2 deletions internal/datanode/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,14 @@ type DataCoordFactory struct {

AddSegmentError bool
AddSegmentNotSuccess bool
AddSegmentEmpty bool
}

func (ds *DataCoordFactory) AssignSegmentID(ctx context.Context, req *datapb.AssignSegmentIDRequest) (*datapb.AssignSegmentIDResponse, error) {
return &datapb.AssignSegmentIDResponse{
if ds.AddSegmentError {
return nil, errors.New("Error")
}
res := &datapb.AssignSegmentIDResponse{
Status: &commonpb.Status{
ErrorCode: commonpb.ErrorCode_Success,
},
Expand All @@ -240,7 +244,15 @@ func (ds *DataCoordFactory) AssignSegmentID(ctx context.Context, req *datapb.Ass
SegID: 666,
},
},
}, nil
}
if ds.AddSegmentNotSuccess {
res.Status = &commonpb.Status{
ErrorCode: commonpb.ErrorCode_UnexpectedError,
}
} else if ds.AddSegmentEmpty {
res.SegIDAssignments = []*datapb.SegmentIDAssignment{}
}
return res, nil
}

func (ds *DataCoordFactory) CompleteCompaction(ctx context.Context, req *datapb.CompactionResult) (*commonpb.Status, error) {
Expand Down

0 comments on commit 9ffcd53

Please sign in to comment.