Browse Source

Merge pull request #287 from zilliztech/attu-285

Use describeIndex instead of getIndexState
ryjiang 1 year ago
parent
commit
2e9e3e74fd

+ 6 - 34
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<IndexHttp[]> {
     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) {
@@ -64,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 || '';
   }

+ 13 - 6
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) {

+ 11 - 0
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,

+ 7 - 7
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,
         });
       }
     }

+ 0 - 37
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);
-    }
-  }
 }

+ 0 - 12
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;
-  }
 }