未验证 提交 6436f596 编写于 作者: C Cai Yudong 提交者: GitHub

add GetIndexStates (#6213)

* add GetIndexStates
Signed-off-by: Nyudong.cai <yudong.cai@zilliz.com>

* rename indexservice to index_coord
Signed-off-by: Nyudong.cai <yudong.cai@zilliz.com>
上级 cc1b5a56
......@@ -333,25 +333,38 @@ func (i *IndexCoord) BuildIndex(ctx context.Context, req *indexpb.BuildIndexRequ
}
func (i *IndexCoord) GetIndexStates(ctx context.Context, req *indexpb.GetIndexStatesRequest) (*indexpb.GetIndexStatesResponse, error) {
log.Debug("IndexCoord get index states ...", zap.Int64s("IndexBuildIDs", req.IndexBuildIDs))
var indexStates []*indexpb.IndexInfo
for _, indexID := range req.IndexBuildIDs {
indexState, err := i.metaTable.GetIndexState(indexID)
if err != nil {
indexState.Reason = err.Error()
var (
cntNone = 0
cntUnissued = 0
cntInprogress = 0
cntFinished = 0
cntFailed = 0
)
indexStates := i.metaTable.GetIndexStates(req.IndexBuildIDs)
for _, state := range indexStates {
switch state.State {
case commonpb.IndexState_IndexStateNone:
cntNone++
case commonpb.IndexState_Unissued:
cntUnissued++
case commonpb.IndexState_InProgress:
cntInprogress++
case commonpb.IndexState_Finished:
cntFinished++
case commonpb.IndexState_Failed:
cntFailed++
}
indexStates = append(indexStates, indexState)
}
log.Debug("IndexCoord get index states success",
zap.Int("total", len(indexStates)), zap.Int("None", cntNone), zap.Int("Unissued", cntUnissued),
zap.Int("InProgress", cntInprogress), zap.Int("Finished", cntFinished), zap.Int("Failed", cntFailed))
ret := &indexpb.GetIndexStatesResponse{
Status: &commonpb.Status{
ErrorCode: commonpb.ErrorCode_Success,
},
States: indexStates,
}
log.Debug("IndexCoord get index states success",
zap.Any("index status", ret.Status),
zap.Any("index states", ret.States))
return ret, nil
}
......
......@@ -245,24 +245,28 @@ func (mt *metaTable) MarkIndexAsDeleted(indexID UniqueID) error {
return nil
}
func (mt *metaTable) GetIndexState(indexBuildID UniqueID) (*indexpb.IndexInfo, error) {
func (mt *metaTable) GetIndexStates(indexBuildIDs []UniqueID) []*indexpb.IndexInfo {
mt.lock.Lock()
defer mt.lock.Unlock()
ret := &indexpb.IndexInfo{
IndexBuildID: indexBuildID,
var indexStates []*indexpb.IndexInfo
for _, id := range indexBuildIDs {
state := &indexpb.IndexInfo{
IndexBuildID: id,
}
meta, ok := mt.indexBuildID2Meta[indexBuildID]
meta, ok := mt.indexBuildID2Meta[id]
if !ok {
return ret, fmt.Errorf("index not exists with ID = %d", indexBuildID)
}
if meta.indexMeta.MarkDeleted {
return ret, fmt.Errorf("index not exists with ID = %d", indexBuildID)
}
ret.IndexID = meta.indexMeta.Req.IndexID
ret.IndexName = meta.indexMeta.Req.IndexName
ret.Reason = meta.indexMeta.FailReason
ret.State = meta.indexMeta.State
return ret, nil
state.Reason = fmt.Sprintf("index %d not exists", id)
} else if meta.indexMeta.MarkDeleted {
state.Reason = fmt.Sprintf("index %d has been deleted", id)
} else {
state.State = meta.indexMeta.State
state.IndexID = meta.indexMeta.Req.IndexID
state.IndexName = meta.indexMeta.Req.IndexName
state.Reason = meta.indexMeta.FailReason
}
indexStates = append(indexStates, state)
}
return indexStates
}
func (mt *metaTable) GetIndexFilePathInfo(indexBuildID UniqueID) (*indexpb.IndexFilePathInfo, error) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册