未验证 提交 d920e5c9 编写于 作者: X XuanYang-cn 提交者: GitHub

Fix DataNode panic while allocating IDs (#17294)

See also: #17270
Signed-off-by: Nyangxuan <xuan.yang@zilliz.com>
上级 bcf3b742
......@@ -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
}
......@@ -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
}
......
......@@ -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)
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册