Skip to content

Commit

Permalink
Fix DataNode panic while allocating IDs (milvus-io#17294)
Browse files Browse the repository at this point in the history
See also: milvus-io#17270

Signed-off-by: yangxuan <xuan.yang@zilliz.com>
  • Loading branch information
XuanYang-cn authored May 31, 2022
1 parent bcf3b74 commit d920e5c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
18 changes: 9 additions & 9 deletions internal/datanode/allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,14 @@ func (alloc *allocator) allocID() (UniqueID, error) {
},
Count: 1,
})

if resp.Status.ErrorCode != commonpb.ErrorCode_Success {
return 0, errors.New(resp.Status.GetReason())
}

if err != nil {
return 0, err
}

if resp.GetStatus().GetErrorCode() != commonpb.ErrorCode_Success {
return 0, errors.New(resp.GetStatus().GetReason())
}

return resp.ID, nil
}

Expand All @@ -81,13 +80,14 @@ func (alloc *allocator) allocIDBatch(count uint32) (UniqueID, uint32, error) {
Count: count,
})

if resp.Status.ErrorCode != commonpb.ErrorCode_Success {
return 0, 0, errors.New(resp.Status.GetReason())
}

if err != nil {
return 0, 0, err
}

if resp.GetStatus().GetErrorCode() != commonpb.ErrorCode_Success {
return 0, 0, errors.New(resp.GetStatus().GetReason())
}

return resp.GetID(), resp.GetCount(), nil
}

Expand Down
6 changes: 5 additions & 1 deletion internal/datanode/allocator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ func TestAllocator_Basic(t *testing.T) {
ms.setID(666)
_, err := allocator.allocID()
assert.NoError(t, err)

ms.setID(-1)
_, err = allocator.allocID()
assert.Error(t, err)
})

t.Run("Test alloc ID batch", func(t *testing.T) {
// If id == 0, AllocID will return not successful status
// If id == -1, AllocID will return err
// If id == -1, AllocID will return err with nil status
ms.setID(666)
_, count, err := allocator.allocIDBatch(10)
assert.NoError(t, err)
Expand Down
3 changes: 1 addition & 2 deletions internal/datanode/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -864,8 +864,7 @@ func (m *RootCoordFactory) AllocID(ctx context.Context, in *rootcoordpb.AllocIDR
}

if m.ID == -1 {
resp.Status.ErrorCode = commonpb.ErrorCode_Success
return resp, errors.New(resp.Status.GetReason())
return nil, errors.New(resp.Status.GetReason())
}

resp.ID = m.ID
Expand Down

0 comments on commit d920e5c

Please sign in to comment.