From d114f23a1dcebab2c81fef1a700f4d520d493c3a Mon Sep 17 00:00:00 2001 From: "ruiyi.jiang" Date: Mon, 16 Oct 2023 17:33:52 +0800 Subject: [PATCH 1/2] Use describeIndex instead of getIndexState Signed-off-by: ruiyi.jiang --- client/src/http/MilvusIndex.ts | 24 +++++--------------- client/src/pages/schema/IndexTypeElement.tsx | 19 +++++++++++----- client/src/types/Milvus.ts | 11 +++++++++ 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/client/src/http/MilvusIndex.ts b/client/src/http/MilvusIndex.ts index 15eb150d..e7661678 100644 --- a/client/src/http/MilvusIndex.ts +++ b/client/src/http/MilvusIndex.ts @@ -4,7 +4,7 @@ import { IndexView, } from '../pages/schema/Types'; import { ManageRequestMethods } from '../types/Common'; -import { IndexState } from '../types/Milvus'; +import { IndexDescription, IndexState } from '../types/Milvus'; import { findKeyValue } from '../utils/Common'; import { getKeyValueListFromJsonString } from '../utils/Format'; import BaseModel from './BaseModel'; @@ -13,6 +13,8 @@ export class IndexHttp extends BaseModel implements IndexView { params!: { key: string; value: string }[]; field_name!: string; index_name!: string; + indexed_rows!: string | number; + state: IndexState = IndexState.Default; constructor(props: {}) { super(props); @@ -21,22 +23,6 @@ export class IndexHttp extends BaseModel implements IndexView { static BASE_URL = `/schema/index`; - static async getIndexStatus( - collectionName: string, - fieldName: string, - indexName: string - ): Promise<{ state: IndexState }> { - const path = `${this.BASE_URL}/state`; - return super.search({ - path, - params: { - collection_name: collectionName, - field_name: fieldName, - index_name: indexName, - }, - }); - } - static async getIndexInfo(collectionName: string): Promise { const path = this.BASE_URL; @@ -44,7 +30,9 @@ export class IndexHttp extends BaseModel implements IndexView { path, params: { collection_name: collectionName }, }); - return res.index_descriptions.map((index: any) => new this(index)); + return res.index_descriptions.map( + (index: IndexDescription) => new this(index) + ); } static async createIndex(param: IndexCreateParam) { diff --git a/client/src/pages/schema/IndexTypeElement.tsx b/client/src/pages/schema/IndexTypeElement.tsx index e2e521ca..614f9161 100644 --- a/client/src/pages/schema/IndexTypeElement.tsx +++ b/client/src/pages/schema/IndexTypeElement.tsx @@ -103,12 +103,17 @@ const IndexTypeElement: FC<{ indexName: string ) => { // get fetch data - const { state } = await IndexHttp.getIndexStatus( - collectionName, - fieldName, - indexName + const index_descriptions = await IndexHttp.getIndexInfo(collectionName); + + const indexDescription = index_descriptions.find( + i => i.field_name === fieldName ); - if (state !== IndexState.Finished && running) { + + if ( + indexDescription && + indexDescription.state !== IndexState.Finished && + running + ) { // if not finished, sleep 3s await sleep(3000); // call self again @@ -116,7 +121,9 @@ const IndexTypeElement: FC<{ } // update state - setStatus(state); + if (indexDescription) { + setStatus(indexDescription.state); + } }; // prevent delete index trigger fetching index status if (data._indexType !== '' && status !== IndexState.Delete) { diff --git a/client/src/types/Milvus.ts b/client/src/types/Milvus.ts index 87495528..f3133a55 100644 --- a/client/src/types/Milvus.ts +++ b/client/src/types/Milvus.ts @@ -10,6 +10,17 @@ export enum IndexState { Delete = 'Delete', } +export type IndexDescription = { + fields_name: string; + index_name: string; + indexed_rows: string | number; + state: IndexState; +}; + +export interface DescribeIndexResponse { + index_descriptions: IndexDescription[]; +} + export enum ShowCollectionsType { All = 0, InMemory = 1, From ff242bc2553fb3bc512369fb3a054148cf4403c1 Mon Sep 17 00:00:00 2001 From: "ruiyi.jiang" Date: Mon, 16 Oct 2023 19:13:23 +0800 Subject: [PATCH 2/2] remove unused API Signed-off-by: ruiyi.jiang --- client/src/http/MilvusIndex.ts | 16 -------- server/src/collections/collections.service.ts | 14 +++---- server/src/schema/schema.controller.ts | 37 ------------------- server/src/schema/schema.service.ts | 12 ------ 4 files changed, 7 insertions(+), 72 deletions(-) diff --git a/client/src/http/MilvusIndex.ts b/client/src/http/MilvusIndex.ts index e7661678..acf393a4 100644 --- a/client/src/http/MilvusIndex.ts +++ b/client/src/http/MilvusIndex.ts @@ -52,22 +52,6 @@ export class IndexHttp extends BaseModel implements IndexView { return super.batchDelete({ path, data: { ...param, type } }); } - static async getIndexBuildProgress( - collectionName: string, - fieldName: string, - indexName: string - ) { - const path = `${this.BASE_URL}/progress`; - return super.search({ - path, - params: { - collection_name: collectionName, - field_name: fieldName, - index_name: indexName, - }, - }); - } - get _indexType() { return this.params.find(p => p.key === 'index_type')?.value || ''; } diff --git a/server/src/collections/collections.service.ts b/server/src/collections/collections.service.ts index 10e21353..a394e0f0 100644 --- a/server/src/collections/collections.service.ts +++ b/server/src/collections/collections.service.ts @@ -141,8 +141,8 @@ export class CollectionsService { * @param data * @returns */ - async getIndexStatus(data: GetIndexStateReq) { - const res = await this.milvusService.client.getIndexState(data); + async getIndexInfo(data: GetIndexStateReq) { + const res = await this.milvusService.client.describeIndex(data); return res; } @@ -167,7 +167,7 @@ export class CollectionsService { collection_name: name, }); - const indexRes = await this.getIndexStatus({ + const indexRes = await this.getIndexInfo({ collection_name: item.name, }); @@ -204,7 +204,7 @@ export class CollectionsService { id: collectionInfo.collectionID, loadedPercentage, createdTime: parseInt(collectionInfo.created_utc_timestamp, 10), - index_status: indexRes.state, + index_descriptions: indexRes, consistency_level: collectionInfo.consistency_level, replicas: replicas && replicas.replicas, }); @@ -261,19 +261,19 @@ export class CollectionsService { /** * Get all collection index status - * @returns {collection_name:string, index_status: IndexState}[] + * @returns {collection_name:string, index_descriptions: index_descriptions}[] */ async getCollectionsIndexStatus() { const data = []; const res = await this.getCollections(); if (res.data.length > 0) { for (const item of res.data) { - const indexRes = await this.getIndexStatus({ + const indexRes = await this.getIndexInfo({ collection_name: item.name, }); data.push({ collection_name: item.name, - index_status: indexRes.state, + index_descriptions: indexRes, }); } } diff --git a/server/src/schema/schema.controller.ts b/server/src/schema/schema.controller.ts index ad0fc4be..3ea3b250 100644 --- a/server/src/schema/schema.controller.ts +++ b/server/src/schema/schema.controller.ts @@ -23,10 +23,6 @@ export class SchemaController { this.router.get('/index', this.describeIndex.bind(this)); - this.router.get('/index/progress', this.getIndexBuildProgress.bind(this)); - - this.router.get('/index/state', this.getIndexState.bind(this)); - return this.router; } @@ -64,37 +60,4 @@ export class SchemaController { next(error); } } - - async getIndexBuildProgress(req: Request, res: Response, next: NextFunction) { - const collection_name = '' + req.query?.collection_name; - const index_name = '' + req.query?.index_name; - const field_name = '' + req.query?.field_name; - try { - const result = await this.schemaService.getIndexBuildProgress({ - collection_name, - index_name, - field_name, - }); - res.send(result); - } catch (error) { - next(error); - } - } - - async getIndexState(req: Request, res: Response, next: NextFunction) { - const collection_name = '' + req.query?.collection_name; - const index_name = '' + req.query?.index_name; - const field_name = '' + req.query?.field_name; - - try { - const result = await this.schemaService.getIndexState({ - collection_name, - index_name, - field_name, - }); - res.send(result); - } catch (error) { - next(error); - } - } } diff --git a/server/src/schema/schema.service.ts b/server/src/schema/schema.service.ts index dc1a2980..a7cff0d6 100644 --- a/server/src/schema/schema.service.ts +++ b/server/src/schema/schema.service.ts @@ -31,16 +31,4 @@ export class SchemaService { throwErrorFromSDK(res); return res; } - - async getIndexState(data: GetIndexStateReq) { - const res = await this.milvusService.client.getIndexState(data); - throwErrorFromSDK(res.status); - return res; - } - - async getIndexBuildProgress(data: GetIndexBuildProgressReq) { - const res = await this.milvusService.client.getIndexBuildProgress(data); - throwErrorFromSDK(res.status); - return res; - } }