add GetIndexStates (#6213)

* add GetIndexStates

Signed-off-by: yudong.cai <yudong.cai@zilliz.com>

* rename indexservice to index_coord

Signed-off-by: yudong.cai <yudong.cai@zilliz.com>
This commit is contained in:
Cai Yudong 2021-06-30 14:32:19 +08:00 committed by GitHub
parent cc1b5a56c6
commit 6436f596de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 26 deletions

View File

@ -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
}

View File

@ -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[id]
if !ok {
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)
}
meta, ok := mt.indexBuildID2Meta[indexBuildID]
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
return indexStates
}
func (mt *metaTable) GetIndexFilePathInfo(indexBuildID UniqueID) (*indexpb.IndexFilePathInfo, error) {