mirror of
https://gitee.com/milvus-io/milvus.git
synced 2025-12-07 01:28:27 +08:00
enhance: Use dbName in error message (#44618)
The collection not found err could contains db id in err message, which is not meaningful to users. This patch make error message wrapping dbname instead of db id. --------- Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
This commit is contained in:
parent
4c49295c3d
commit
31670c5489
@ -22,7 +22,7 @@ type RootCoordCatalog interface {
|
|||||||
|
|
||||||
CreateCollection(ctx context.Context, collectionInfo *model.Collection, ts typeutil.Timestamp) error
|
CreateCollection(ctx context.Context, collectionInfo *model.Collection, ts typeutil.Timestamp) error
|
||||||
GetCollectionByID(ctx context.Context, dbID int64, ts typeutil.Timestamp, collectionID typeutil.UniqueID) (*model.Collection, error)
|
GetCollectionByID(ctx context.Context, dbID int64, ts typeutil.Timestamp, collectionID typeutil.UniqueID) (*model.Collection, error)
|
||||||
GetCollectionByName(ctx context.Context, dbID int64, collectionName string, ts typeutil.Timestamp) (*model.Collection, error)
|
GetCollectionByName(ctx context.Context, dbID int64, dbName string, collectionName string, ts typeutil.Timestamp) (*model.Collection, error)
|
||||||
ListCollections(ctx context.Context, dbID int64, ts typeutil.Timestamp) ([]*model.Collection, error)
|
ListCollections(ctx context.Context, dbID int64, ts typeutil.Timestamp) ([]*model.Collection, error)
|
||||||
CollectionExists(ctx context.Context, dbID int64, collectionID typeutil.UniqueID, ts typeutil.Timestamp) bool
|
CollectionExists(ctx context.Context, dbID int64, collectionID typeutil.UniqueID, ts typeutil.Timestamp) bool
|
||||||
DropCollection(ctx context.Context, collectionInfo *model.Collection, ts typeutil.Timestamp) error
|
DropCollection(ctx context.Context, collectionInfo *model.Collection, ts typeutil.Timestamp) error
|
||||||
|
|||||||
@ -863,7 +863,7 @@ func (kc *Catalog) DropAlias(ctx context.Context, dbID int64, alias string, ts t
|
|||||||
return kc.Snapshot.MultiSaveAndRemove(ctx, nil, []string{k, oldKeyWithoutDb, oldKBefore210}, ts)
|
return kc.Snapshot.MultiSaveAndRemove(ctx, nil, []string{k, oldKeyWithoutDb, oldKBefore210}, ts)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (kc *Catalog) GetCollectionByName(ctx context.Context, dbID int64, collectionName string, ts typeutil.Timestamp) (*model.Collection, error) {
|
func (kc *Catalog) GetCollectionByName(ctx context.Context, dbID int64, dbName string, collectionName string, ts typeutil.Timestamp) (*model.Collection, error) {
|
||||||
prefix := getDatabasePrefix(dbID)
|
prefix := getDatabasePrefix(dbID)
|
||||||
_, vals, err := kc.Snapshot.LoadWithPrefix(ctx, prefix, ts)
|
_, vals, err := kc.Snapshot.LoadWithPrefix(ctx, prefix, ts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -884,7 +884,7 @@ func (kc *Catalog) GetCollectionByName(ctx context.Context, dbID int64, collecti
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, merr.WrapErrCollectionNotFoundWithDB(dbID, collectionName, fmt.Sprintf("timestamp = %d", ts))
|
return nil, merr.WrapErrCollectionNotFoundWithDB(dbName, collectionName, fmt.Sprintf("timestamp = %d", ts))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (kc *Catalog) ListCollections(ctx context.Context, dbID int64, ts typeutil.Timestamp) ([]*model.Collection, error) {
|
func (kc *Catalog) ListCollections(ctx context.Context, dbID int64, ts typeutil.Timestamp) ([]*model.Collection, error) {
|
||||||
|
|||||||
@ -1293,9 +1293,9 @@ func (_c *RootCoordCatalog_GetCollectionByID_Call) RunAndReturn(run func(context
|
|||||||
return _c
|
return _c
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCollectionByName provides a mock function with given fields: ctx, dbID, collectionName, ts
|
// GetCollectionByName provides a mock function with given fields: ctx, dbID, dbName, collectionName, ts
|
||||||
func (_m *RootCoordCatalog) GetCollectionByName(ctx context.Context, dbID int64, collectionName string, ts uint64) (*model.Collection, error) {
|
func (_m *RootCoordCatalog) GetCollectionByName(ctx context.Context, dbID int64, dbName string, collectionName string, ts uint64) (*model.Collection, error) {
|
||||||
ret := _m.Called(ctx, dbID, collectionName, ts)
|
ret := _m.Called(ctx, dbID, dbName, collectionName, ts)
|
||||||
|
|
||||||
if len(ret) == 0 {
|
if len(ret) == 0 {
|
||||||
panic("no return value specified for GetCollectionByName")
|
panic("no return value specified for GetCollectionByName")
|
||||||
@ -1303,19 +1303,19 @@ func (_m *RootCoordCatalog) GetCollectionByName(ctx context.Context, dbID int64,
|
|||||||
|
|
||||||
var r0 *model.Collection
|
var r0 *model.Collection
|
||||||
var r1 error
|
var r1 error
|
||||||
if rf, ok := ret.Get(0).(func(context.Context, int64, string, uint64) (*model.Collection, error)); ok {
|
if rf, ok := ret.Get(0).(func(context.Context, int64, string, string, uint64) (*model.Collection, error)); ok {
|
||||||
return rf(ctx, dbID, collectionName, ts)
|
return rf(ctx, dbID, dbName, collectionName, ts)
|
||||||
}
|
}
|
||||||
if rf, ok := ret.Get(0).(func(context.Context, int64, string, uint64) *model.Collection); ok {
|
if rf, ok := ret.Get(0).(func(context.Context, int64, string, string, uint64) *model.Collection); ok {
|
||||||
r0 = rf(ctx, dbID, collectionName, ts)
|
r0 = rf(ctx, dbID, dbName, collectionName, ts)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
if ret.Get(0) != nil {
|
||||||
r0 = ret.Get(0).(*model.Collection)
|
r0 = ret.Get(0).(*model.Collection)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if rf, ok := ret.Get(1).(func(context.Context, int64, string, uint64) error); ok {
|
if rf, ok := ret.Get(1).(func(context.Context, int64, string, string, uint64) error); ok {
|
||||||
r1 = rf(ctx, dbID, collectionName, ts)
|
r1 = rf(ctx, dbID, dbName, collectionName, ts)
|
||||||
} else {
|
} else {
|
||||||
r1 = ret.Error(1)
|
r1 = ret.Error(1)
|
||||||
}
|
}
|
||||||
@ -1331,15 +1331,16 @@ type RootCoordCatalog_GetCollectionByName_Call struct {
|
|||||||
// GetCollectionByName is a helper method to define mock.On call
|
// GetCollectionByName is a helper method to define mock.On call
|
||||||
// - ctx context.Context
|
// - ctx context.Context
|
||||||
// - dbID int64
|
// - dbID int64
|
||||||
|
// - dbName string
|
||||||
// - collectionName string
|
// - collectionName string
|
||||||
// - ts uint64
|
// - ts uint64
|
||||||
func (_e *RootCoordCatalog_Expecter) GetCollectionByName(ctx interface{}, dbID interface{}, collectionName interface{}, ts interface{}) *RootCoordCatalog_GetCollectionByName_Call {
|
func (_e *RootCoordCatalog_Expecter) GetCollectionByName(ctx interface{}, dbID interface{}, dbName interface{}, collectionName interface{}, ts interface{}) *RootCoordCatalog_GetCollectionByName_Call {
|
||||||
return &RootCoordCatalog_GetCollectionByName_Call{Call: _e.mock.On("GetCollectionByName", ctx, dbID, collectionName, ts)}
|
return &RootCoordCatalog_GetCollectionByName_Call{Call: _e.mock.On("GetCollectionByName", ctx, dbID, dbName, collectionName, ts)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_c *RootCoordCatalog_GetCollectionByName_Call) Run(run func(ctx context.Context, dbID int64, collectionName string, ts uint64)) *RootCoordCatalog_GetCollectionByName_Call {
|
func (_c *RootCoordCatalog_GetCollectionByName_Call) Run(run func(ctx context.Context, dbID int64, dbName string, collectionName string, ts uint64)) *RootCoordCatalog_GetCollectionByName_Call {
|
||||||
_c.Call.Run(func(args mock.Arguments) {
|
_c.Call.Run(func(args mock.Arguments) {
|
||||||
run(args[0].(context.Context), args[1].(int64), args[2].(string), args[3].(uint64))
|
run(args[0].(context.Context), args[1].(int64), args[2].(string), args[3].(string), args[4].(uint64))
|
||||||
})
|
})
|
||||||
return _c
|
return _c
|
||||||
}
|
}
|
||||||
@ -1349,7 +1350,7 @@ func (_c *RootCoordCatalog_GetCollectionByName_Call) Return(_a0 *model.Collectio
|
|||||||
return _c
|
return _c
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_c *RootCoordCatalog_GetCollectionByName_Call) RunAndReturn(run func(context.Context, int64, string, uint64) (*model.Collection, error)) *RootCoordCatalog_GetCollectionByName_Call {
|
func (_c *RootCoordCatalog_GetCollectionByName_Call) RunAndReturn(run func(context.Context, int64, string, string, uint64) (*model.Collection, error)) *RootCoordCatalog_GetCollectionByName_Call {
|
||||||
_c.Call.Return(run)
|
_c.Call.Return(run)
|
||||||
return _c
|
return _c
|
||||||
}
|
}
|
||||||
|
|||||||
@ -733,8 +733,8 @@ func (mt *MetaTable) getCollectionByNameInternal(ctx context.Context, dbName str
|
|||||||
}
|
}
|
||||||
|
|
||||||
// travel meta information from catalog. No need to check time travel logic again, since catalog already did.
|
// travel meta information from catalog. No need to check time travel logic again, since catalog already did.
|
||||||
ctx1 := contextutil.WithTenantID(ctx, Params.CommonCfg.ClusterName.GetValue())
|
ctx = contextutil.WithTenantID(ctx, Params.CommonCfg.ClusterName.GetValue())
|
||||||
coll, err := mt.catalog.GetCollectionByName(ctx1, db.ID, collectionName, ts)
|
coll, err := mt.catalog.GetCollectionByName(ctx, db.ID, db.Name, collectionName, ts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -617,6 +617,7 @@ func TestMetaTable_GetCollectionByName(t *testing.T) {
|
|||||||
mock.Anything,
|
mock.Anything,
|
||||||
mock.Anything,
|
mock.Anything,
|
||||||
mock.Anything,
|
mock.Anything,
|
||||||
|
mock.Anything,
|
||||||
).Return(nil, errors.New("error mock GetCollectionByName"))
|
).Return(nil, errors.New("error mock GetCollectionByName"))
|
||||||
meta := &MetaTable{
|
meta := &MetaTable{
|
||||||
dbName2Meta: map[string]*model.Database{
|
dbName2Meta: map[string]*model.Database{
|
||||||
@ -638,6 +639,7 @@ func TestMetaTable_GetCollectionByName(t *testing.T) {
|
|||||||
mock.Anything,
|
mock.Anything,
|
||||||
mock.Anything,
|
mock.Anything,
|
||||||
mock.Anything,
|
mock.Anything,
|
||||||
|
mock.Anything,
|
||||||
).Return(&model.Collection{State: pb.CollectionState_CollectionDropped}, nil)
|
).Return(&model.Collection{State: pb.CollectionState_CollectionDropped}, nil)
|
||||||
meta := &MetaTable{
|
meta := &MetaTable{
|
||||||
dbName2Meta: map[string]*model.Database{
|
dbName2Meta: map[string]*model.Database{
|
||||||
@ -660,6 +662,7 @@ func TestMetaTable_GetCollectionByName(t *testing.T) {
|
|||||||
mock.Anything,
|
mock.Anything,
|
||||||
mock.Anything,
|
mock.Anything,
|
||||||
mock.Anything,
|
mock.Anything,
|
||||||
|
mock.Anything,
|
||||||
).Return(&model.Collection{
|
).Return(&model.Collection{
|
||||||
State: pb.CollectionState_CollectionCreated,
|
State: pb.CollectionState_CollectionCreated,
|
||||||
CreateTime: 99,
|
CreateTime: 99,
|
||||||
@ -1654,6 +1657,7 @@ func TestMetaTable_RenameCollection(t *testing.T) {
|
|||||||
mock.Anything,
|
mock.Anything,
|
||||||
mock.Anything,
|
mock.Anything,
|
||||||
mock.Anything,
|
mock.Anything,
|
||||||
|
mock.Anything,
|
||||||
).Return(nil, merr.WrapErrCollectionNotFound("error"))
|
).Return(nil, merr.WrapErrCollectionNotFound("error"))
|
||||||
meta := &MetaTable{
|
meta := &MetaTable{
|
||||||
dbName2Meta: map[string]*model.Database{
|
dbName2Meta: map[string]*model.Database{
|
||||||
@ -1697,6 +1701,7 @@ func TestMetaTable_RenameCollection(t *testing.T) {
|
|||||||
mock.Anything,
|
mock.Anything,
|
||||||
mock.Anything,
|
mock.Anything,
|
||||||
mock.Anything,
|
mock.Anything,
|
||||||
|
mock.Anything,
|
||||||
).Return(nil, merr.WrapErrCollectionNotFound("error"))
|
).Return(nil, merr.WrapErrCollectionNotFound("error"))
|
||||||
meta := &MetaTable{
|
meta := &MetaTable{
|
||||||
dbName2Meta: map[string]*model.Database{
|
dbName2Meta: map[string]*model.Database{
|
||||||
@ -1741,6 +1746,7 @@ func TestMetaTable_RenameCollection(t *testing.T) {
|
|||||||
mock.Anything,
|
mock.Anything,
|
||||||
mock.Anything,
|
mock.Anything,
|
||||||
mock.Anything,
|
mock.Anything,
|
||||||
|
mock.Anything,
|
||||||
).Return(nil, merr.WrapErrCollectionNotFound("error"))
|
).Return(nil, merr.WrapErrCollectionNotFound("error"))
|
||||||
|
|
||||||
// Create database with encryption enabled
|
// Create database with encryption enabled
|
||||||
|
|||||||
@ -96,7 +96,7 @@ class TestMilvusClientAliasInvalid(TestMilvusClientV2Base):
|
|||||||
client = self._client()
|
client = self._client()
|
||||||
alias = cf.gen_unique_str("collection_alias")
|
alias = cf.gen_unique_str("collection_alias")
|
||||||
collection_name = "not_exist_collection_alias"
|
collection_name = "not_exist_collection_alias"
|
||||||
error = {ct.err_code: 100, ct.err_msg: f"collection not found[database=1][collection={collection_name}]"}
|
error = {ct.err_code: 100, ct.err_msg: f"collection not found[database=default][collection={collection_name}]"}
|
||||||
self.create_alias(client, collection_name, alias,
|
self.create_alias(client, collection_name, alias,
|
||||||
check_task=CheckTasks.err_res, check_items=error)
|
check_task=CheckTasks.err_res, check_items=error)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user