Skip to content

Commit

Permalink
classify error codes
Browse files Browse the repository at this point in the history
  • Loading branch information
zcdb committed Apr 19, 2024
1 parent fde1a88 commit 4a89ced
Show file tree
Hide file tree
Showing 25 changed files with 626 additions and 527 deletions.
4 changes: 2 additions & 2 deletions internal/client/client.go
Expand Up @@ -587,7 +587,7 @@ func (r *routerRequest) searchFromPartition(ctx context.Context, partitionID ent
for _, item := range searchResult.ResultItems {
source, sortValues, pkey, err := GetSource(item, space, sortFieldMap, pd.SearchRequest.SortFields)
if err != nil {
err := &vearchpb.Error{Code: vearchpb.ErrorEnum_PARSING_RESULT_ERROR, Msg: "router call ps rpc service err nodeID:" + fmt.Sprint(nodeID)}
err := &vearchpb.Error{Code: vearchpb.ErrorEnum_SEARCH_RESPONSE_PARSE_ERR, Msg: "router call ps rpc service err nodeID:" + fmt.Sprint(nodeID)}
replyPartition.SearchResponse.Head.Err = err
}
item.PKey = pkey
Expand Down Expand Up @@ -933,7 +933,7 @@ func (r *routerRequest) queryFromPartition(ctx context.Context, partitionID enti
for _, item := range searchResult.ResultItems {
source, sortValues, pkey, err := GetSource(item, space, sortFieldMap, pd.QueryRequest.SortFields)
if err != nil {
err := &vearchpb.Error{Code: vearchpb.ErrorEnum_PARSING_RESULT_ERROR, Msg: "router call ps rpc service err nodeID:" + fmt.Sprint(nodeID)}
err := &vearchpb.Error{Code: vearchpb.ErrorEnum_QUERY_RESPONSE_PARSE_ERR, Msg: "router call ps rpc service err nodeID:" + fmt.Sprint(nodeID)}
replyPartition.SearchResponse.Head.Err = err
}
item.PKey = pkey
Expand Down
12 changes: 6 additions & 6 deletions internal/client/master.go
Expand Up @@ -92,7 +92,7 @@ func (m *masterClient) QueryDBId2Name(ctx context.Context, id int64) (string, er
return "", err
}
if bytes == nil {
return "", vearchpb.NewError(vearchpb.ErrorEnum_DB_NOTEXISTS, nil)
return "", vearchpb.NewError(vearchpb.ErrorEnum_DB_NOT_EXIST, nil)
}
return string(bytes), nil
}
Expand All @@ -102,7 +102,7 @@ func (m *masterClient) QueryDBName2Id(ctx context.Context, name string) (int64,
if bytes, err := m.Get(ctx, entity.DBKeyName(name)); err != nil {
return -1, err
} else if bytes == nil {
return -1, vearchpb.NewError(vearchpb.ErrorEnum_DB_NOTEXISTS, nil)
return -1, vearchpb.NewError(vearchpb.ErrorEnum_DB_NOT_EXIST, nil)
} else {
return cast.ToInt64E(string(bytes))
}
Expand Down Expand Up @@ -132,7 +132,7 @@ func (m *masterClient) QueryServer(ctx context.Context, id entity.NodeID) (*enti
}
if bytes == nil {
log.Error("server can not find on master, maybe server is offline, nodeId:[%d]", id)
return nil, vearchpb.NewError(vearchpb.ErrorEnum_PS_NOTEXISTS, nil)
return nil, vearchpb.NewError(vearchpb.ErrorEnum_PS_NOT_EXIST, nil)
}

p := new(entity.Server)
Expand All @@ -148,7 +148,7 @@ func (m *masterClient) QueryServer(ctx context.Context, id entity.NodeID) (*enti
func (m *masterClient) QueryUser(ctx context.Context, username string) (*entity.User, error) {
bytes, err := m.Get(ctx, entity.UserKey(username))
if bytes == nil {
return nil, vearchpb.NewError(vearchpb.ErrorEnum_USER_NOT_EXISTS, err)
return nil, vearchpb.NewError(vearchpb.ErrorEnum_USER_NOT_EXIST, err)
}
user := new(entity.User)
if err = vjson.Unmarshal(bytes, user); err != nil {
Expand Down Expand Up @@ -343,7 +343,7 @@ func (m *masterClient) QueryPartitions(ctx context.Context) ([]*entity.Partition
func (m *masterClient) QuerySpaceByID(ctx context.Context, dbID entity.DBID, spaceID entity.SpaceID) (*entity.Space, error) {
bytes, err := m.Store.Get(ctx, entity.SpaceKey(dbID, spaceID))
if bytes == nil {
return nil, vearchpb.NewError(vearchpb.ErrorEnum_SPACE_NOTEXISTS, err)
return nil, vearchpb.NewError(vearchpb.ErrorEnum_SPACE_NOT_EXIST, err)
}
space := &entity.Space{}
if err := vjson.Unmarshal(bytes, space); err != nil {
Expand All @@ -363,7 +363,7 @@ func (m *masterClient) QuerySpaceByName(ctx context.Context, dbID int64, spaceNa
return s, nil
}
}
return nil, vearchpb.NewError(vearchpb.ErrorEnum_SPACE_NOTEXISTS, nil)
return nil, vearchpb.NewError(vearchpb.ErrorEnum_SPACE_NOT_EXIST, nil)
}

// QueryAliasByName query alias by alias name
Expand Down
4 changes: 2 additions & 2 deletions internal/client/master_cache.go
Expand Up @@ -161,7 +161,7 @@ func (cliCache *clientCache) SpaceByCache(ctx context.Context, db, space string)

if err != nil {
return nil, fmt.Errorf("db:[%s] space:[%s] err:[%s]", db, space,
vearchpb.NewError(vearchpb.ErrorEnum_SPACE_NOTEXISTS, nil))
vearchpb.NewError(vearchpb.ErrorEnum_SPACE_NOT_EXIST, nil))
}

for i := 0; i < retryNum; i++ {
Expand All @@ -172,7 +172,7 @@ func (cliCache *clientCache) SpaceByCache(ctx context.Context, db, space string)
}
}

return nil, fmt.Errorf("db:[%s] space:[%s] err:[%s]", db, space, vearchpb.NewError(vearchpb.ErrorEnum_SPACE_NOTEXISTS, nil))
return nil, fmt.Errorf("db:[%s] space:[%s] err:[%s]", db, space, vearchpb.NewError(vearchpb.ErrorEnum_SPACE_NOT_EXIST, nil))
}

func (cliCache *clientCache) reloadSpaceCache(ctx context.Context, sync bool, db string, spaceName string) error {
Expand Down
10 changes: 5 additions & 5 deletions internal/master/cluster_service.go
Expand Up @@ -177,7 +177,7 @@ func (ms *masterService) deleteDBService(ctx context.Context, dbstr string) (err
}

if len(spaces) > 0 {
return vearchpb.NewError(vearchpb.ErrorEnum_DB_Not_Empty, nil)
return vearchpb.NewError(vearchpb.ErrorEnum_DB_NOT_EMPTY, nil)
}

err = ms.Master().STM(context.Background(),
Expand Down Expand Up @@ -209,7 +209,7 @@ func (ms *masterService) updateDBIpList(ctx context.Context, dbModify *entity.DB
bs, err := ms.Master().Get(ctx, entity.DBKeyBody(id))
errutil.ThrowError(err)
if bs == nil {
return nil, vearchpb.NewError(vearchpb.ErrorEnum_DB_NOTEXISTS, nil)
return nil, vearchpb.NewError(vearchpb.ErrorEnum_DB_NOT_EXIST, nil)
}
err = vjson.Unmarshal(bs, db)
errutil.ThrowError(err)
Expand Down Expand Up @@ -261,7 +261,7 @@ func (ms *masterService) queryDBService(ctx context.Context, dbstr string) (db *
}

if bs == nil {
return nil, vearchpb.NewError(vearchpb.ErrorEnum_DB_NOTEXISTS, nil)
return nil, vearchpb.NewError(vearchpb.ErrorEnum_DB_NOT_EXIST, nil)
}

if err := vjson.Unmarshal(bs, db); err != nil {
Expand Down Expand Up @@ -300,11 +300,11 @@ func (ms *masterService) createSpaceService(ctx context.Context, dbName string,
// spaces is existed
if _, err := ms.Master().QuerySpaceByName(ctx, space.DBId, space.Name); err != nil {
vErr := vearchpb.NewError(vearchpb.ErrorEnum_INTERNAL_ERROR, err)
if vErr.GetError().Code != vearchpb.ErrorEnum_SPACE_NOTEXISTS {
if vErr.GetError().Code != vearchpb.ErrorEnum_SPACE_NOT_EXIST {
return vErr
}
} else {
return vearchpb.NewError(vearchpb.ErrorEnum_DUP_SPACE, nil)
return vearchpb.NewError(vearchpb.ErrorEnum_SPACE_EXIST, nil)
}

log.Info("create space, db: %s, spaceName: %s, space :[%s]", dbName, space.Name, vjson.ToJsonString(space))
Expand Down
2 changes: 1 addition & 1 deletion internal/master/schedule_job.go
Expand Up @@ -34,7 +34,7 @@ func walkPartitions(masterServer *Server, partitions []*entity.Partition) {
log.Debug("Start Walking Partitions!")
for _, partition := range partitions {
if space, err := masterServer.client.Master().QuerySpaceByID(ctx, partition.DBId, partition.SpaceId); err != nil {
if vearchpb.NewError(vearchpb.ErrorEnum_INTERNAL_ERROR, err).GetError().Code == vearchpb.ErrorEnum_SPACE_NOTEXISTS {
if vearchpb.NewError(vearchpb.ErrorEnum_INTERNAL_ERROR, err).GetError().Code == vearchpb.ErrorEnum_SPACE_NOT_EXIST {
log.Warnf("Could not find Space contains partition,PartitionID:[%d] so remove it from etcd!", partition.Id)
partitionKey := entity.PartitionKey(partition.Id)
if err := masterServer.client.Master().Delete(ctx, partitionKey); err != nil {
Expand Down
154 changes: 95 additions & 59 deletions internal/proto/errors.proto
Expand Up @@ -5,68 +5,104 @@ option optimize_for = SPEED;
option go_package = "./vearchpb";

enum ErrorEnum {
// basic 0-99
SUCCESS = 0;
// cluster 1-99
INTERNAL_ERROR = 1;
UNKNOWN_ERROR = 2;
PARTITION_DUPLICATE = 3;
PARTITION_NOT_EXIST = 4;
PARTITION_NOT_LEADER = 5;
PARTITION_NO_LEADER = 6;
PARTITION_IS_INVALID = 7;
PARTITION_IS_CLOSED = 8;
MASTER_PS_NOT_ENOUGH_SELECT = 9;
USER_NOT_EXISTS = 10;
AUTHENTICATION_FAILED = 11;
SERVICE_UNAVAILABLE = 12;
RPC_PARAM_ERROR = 13;
METHOD_NOT_IMPLEMENT = 14;
ROUTER_NO_PS_CLIENT = 15;
ROUTER_CALL_PS_RPC_ERR = 16;
RECOVER = 17;
CREATE_RPCCLIENT_FAILED = 18;
CALL_RPCCLIENT_FAILED = 19;

// schema 100-199
DB_NOTEXISTS = 100;
DB_Not_Empty = 101;
DUP_SPACE = 102;
PARAM_ERROR = 103;
TIMEOUT = 104;
SPACE_NOTEXISTS = 105;
PS_NOTEXISTS = 106;
DOCUMENT_NOT_EXIST = 107;
PRIMARY_IS_INVALID = 108;
PARSING_RESULT_ERROR = 109;
FLUSH_ERR = 111;
ALIAS_NOT_EXIST = 112;
ALIAS_EXIST = 113;

// document 200-299
// document upsert 200-219
UPSERT_INVALID_PARAMS = 200;
// document delete 220-239
DELETE_BY_QUERY_SERACH_ERR = 220;
DELETE_BY_QUERY_SEARCH_ID_IS_0 = 221;
DELETE_INVALID_PARAMS_SHOULD_NOT_HAVE_VECTOR_FIELD = 222;
DELETE_INVALID_PARAMS_BOTH_DOCUMENT_IDS_AND_VECTOR = 223;
DELETE_INVALID_PARAMS_LENGTH_OF_DOCUMENT_IDS_BEYOND_500 = 224;
DELETE_INVALID_PARAMS_SHOULD_HAVE_ONE_OF_DOCUMENT_IDS_OR_FILTER = 225;
// document query 240-259
QUERY_INVALID_PARAMS_LENGTH_OF_DOCUMENT_IDS_BEYOND_500 = 240;
QUERY_INVALID_PARAMS_SHOULD_HAVE_ONE_OF_DOCUMENT_IDS_OR_FILTER = 241;
QUERY_INVALID_PARAMS_SHOULD_NOT_HAVE_VECTOR_FIELD = 242;
QUERY_INVALID_PARAMS_BOTH_DOCUMENT_IDS_AND_FILTER = 243;
// document search 260-299
SEARCH_INVALID_PARAMS_SHOULD_HAVE_VECTOR_FIELD = 260;
SEARCH_ERROR = 261;
GAMMA_SEARCH_QUERY_NUM_LESS_0 = 262;
GAMMA_SEARCH_NO_CREATE_INDEX = 263;
GAMMA_SEARCH_INDEX_QUERY_ERR = 264;
GAMMA_SEARCH_OTHER_ERR = 265;

// index 300-399
FORCE_MERGE_BUILD_INDEX_ERR = 301;
AUTHENTICATION_FAILED = 3;
RECOVER = 4;
TIMEOUT = 5;
PARAM_ERROR = 6;

// cluster 100-199
// master 100-119
MASTER_PS_NOT_ENOUGH_SELECT = 100;

// router 120-139
ROUTER_NO_PS_CLIENT = 120;
ROUTER_CALL_PS_RPC_ERR = 121;

// partition server 140-159
PARTITION_DUPLICATE = 140;
PARTITION_NOT_EXIST = 141;
PARTITION_NOT_LEADER = 142;
PARTITION_NO_LEADER = 143;
PARTITION_IS_INVALID = 144;
PARTITION_IS_CLOSED = 145;
PS_NOT_EXIST = 146;

// server 160-179

// user 180-199
USER_NOT_EXIST = 180;

// schema 200-399
// db 200-219
DB_NOT_EXIST = 200;
DB_EXIST = 201;
DB_NOT_EMPTY = 202;

// space 220-239
SPACE_EXIST = 220;
SPACE_NOT_EXIST = 221;

// alias 240-259
ALIAS_NOT_EXIST = 240;
ALIAS_EXIST = 241;

// document 260-279
DOCUMENT_NOT_EXIST = 260;
PRIMARY_KEY_IS_INVALID = 261;

// field 280-299
// scalar field 280-289
// vector field 290-299

// filter 300-319
FILTER_OPERATOR_TYPE_ERR = 300;
FILTER_CONDITION_OPERATOR_TYPE_ERR = 301;

// data interface 400-499
// document upsert 400-419
UPSERT_INVALID_PARAMS = 400;

// document delete 420-439
DELETE_BY_QUERY_SERACH_ERR = 420;
DELETE_BY_QUERY_SEARCH_ID_IS_0 = 421;
DELETE_INVALID_PARAMS_SHOULD_NOT_HAVE_VECTOR_FIELD = 422;
DELETE_INVALID_PARAMS_BOTH_DOCUMENT_IDS_AND_VECTOR = 423;
DELETE_INVALID_PARAMS_LENGTH_OF_DOCUMENT_IDS_BEYOND_500 = 424;
DELETE_INVALID_PARAMS_SHOULD_HAVE_ONE_OF_DOCUMENT_IDS_OR_FILTER = 425;

// document query 440-459
QUERY_INVALID_PARAMS_LENGTH_OF_DOCUMENT_IDS_BEYOND_500 = 440;
QUERY_INVALID_PARAMS_SHOULD_HAVE_ONE_OF_DOCUMENT_IDS_OR_FILTER = 441;
QUERY_INVALID_PARAMS_SHOULD_NOT_HAVE_VECTOR_FIELD = 442;
QUERY_INVALID_PARAMS_BOTH_DOCUMENT_IDS_AND_FILTER = 443;
QUERY_RESPONSE_PARSE_ERR = 444;

// document search 460-479
SEARCH_INVALID_PARAMS_SHOULD_HAVE_VECTOR_FIELD = 460;
SEARCH_ERROR = 461;
GAMMA_SEARCH_QUERY_NUM_LESS_0 = 462;
GAMMA_SEARCH_NO_CREATE_INDEX = 463;
GAMMA_SEARCH_INDEX_QUERY_ERR = 464;
GAMMA_SEARCH_OTHER_ERR = 465;
SEARCH_RESPONSE_PARSE_ERR = 466;

// index interface 500-599
FORCE_MERGE_BUILD_INDEX_ERR = 500;

// meta interface 600-699
// flush
FLUSH_ERR = 600;

// service 700
SERVICE_UNAVAILABLE = 700;
RPC_PARAM_ERROR = 701;
METHOD_NOT_IMPLEMENT = 702;
CREATE_RPCCLIENT_FAILED = 703;
CALL_RPCCLIENT_FAILED = 704;
}

message Error {
Expand Down

0 comments on commit 4a89ced

Please sign in to comment.