Browse Source

Use describeIndex instead of getIndexState

Signed-off-by: ruiyi.jiang <ruiyi.jiang@zilliz.com>
ruiyi.jiang 1 year ago
parent
commit
d114f23a1d

+ 6 - 18
client/src/http/MilvusIndex.ts

@@ -4,7 +4,7 @@ import {
   IndexView,
   IndexView,
 } from '../pages/schema/Types';
 } from '../pages/schema/Types';
 import { ManageRequestMethods } from '../types/Common';
 import { ManageRequestMethods } from '../types/Common';
-import { IndexState } from '../types/Milvus';
+import { IndexDescription, IndexState } from '../types/Milvus';
 import { findKeyValue } from '../utils/Common';
 import { findKeyValue } from '../utils/Common';
 import { getKeyValueListFromJsonString } from '../utils/Format';
 import { getKeyValueListFromJsonString } from '../utils/Format';
 import BaseModel from './BaseModel';
 import BaseModel from './BaseModel';
@@ -13,6 +13,8 @@ export class IndexHttp extends BaseModel implements IndexView {
   params!: { key: string; value: string }[];
   params!: { key: string; value: string }[];
   field_name!: string;
   field_name!: string;
   index_name!: string;
   index_name!: string;
+  indexed_rows!: string | number;
+  state: IndexState = IndexState.Default;
 
 
   constructor(props: {}) {
   constructor(props: {}) {
     super(props);
     super(props);
@@ -21,22 +23,6 @@ export class IndexHttp extends BaseModel implements IndexView {
 
 
   static BASE_URL = `/schema/index`;
   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[]> {
   static async getIndexInfo(collectionName: string): Promise<IndexHttp[]> {
     const path = this.BASE_URL;
     const path = this.BASE_URL;
 
 
@@ -44,7 +30,9 @@ export class IndexHttp extends BaseModel implements IndexView {
       path,
       path,
       params: { collection_name: collectionName },
       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) {
   static async createIndex(param: IndexCreateParam) {

+ 13 - 6
client/src/pages/schema/IndexTypeElement.tsx

@@ -103,12 +103,17 @@ const IndexTypeElement: FC<{
       indexName: string
       indexName: string
     ) => {
     ) => {
       // get fetch data
       // 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
         // if not finished, sleep 3s
         await sleep(3000);
         await sleep(3000);
         // call self again
         // call self again
@@ -116,7 +121,9 @@ const IndexTypeElement: FC<{
       }
       }
 
 
       // update state
       // update state
-      setStatus(state);
+      if (indexDescription) {
+        setStatus(indexDescription.state);
+      }
     };
     };
     // prevent delete index trigger fetching index status
     // prevent delete index trigger fetching index status
     if (data._indexType !== '' && status !== IndexState.Delete) {
     if (data._indexType !== '' && status !== IndexState.Delete) {

+ 11 - 0
client/src/types/Milvus.ts

@@ -10,6 +10,17 @@ export enum IndexState {
   Delete = 'Delete',
   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 {
 export enum ShowCollectionsType {
   All = 0,
   All = 0,
   InMemory = 1,
   InMemory = 1,