Browse Source

Merge remote-tracking branch 'upstream/main' into feature/code-mode

tumao 3 years ago
parent
commit
992eed8ba4

+ 1 - 1
client/src/context/Root.tsx

@@ -85,8 +85,8 @@ export const RootProvider = (props: { children: React.ReactNode }) => {
     },
     []
   );
+
   const handleCloseDialog = () => {
-    // setDialog(DefaultDialogConfigs);
     setDialog({
       ...dialog,
       open: false,

+ 1 - 1
client/src/context/Types.ts

@@ -25,7 +25,7 @@ export type DialogType = {
      * Usually we control open status in root context,
      * if we need a hoc component depend on setDialog in context,
      * we may need control open status by ourself
-     *  */
+     **/
     handleClose?: () => void;
 
     // used for dialog position

+ 29 - 12
client/src/pages/schema/IndexTypeElement.tsx

@@ -15,8 +15,14 @@ import { rootContext } from '../../context/Root';
 import CreateIndex from './Create';
 import DeleteTemplate from '../../components/customDialog/DeleteDialogTemplate';
 import CustomLinearProgress from '../../components/customProgress/CustomLinearProgress';
+import StatusIcon from '../../components/status/StatusIcon';
+import { ChildrenStatusType } from '../../components/status/Types';
 
 const useStyles = makeStyles((theme: Theme) => ({
+  wrapper: {
+    // give fixed width to prevent table cell stretching
+    width: 150,
+  },
   item: {
     paddingLeft: theme.spacing(1),
   },
@@ -69,8 +75,8 @@ const IndexTypeElement: FC<{
   cb: (collectionName: string) => void;
 }> = ({ data, collectionName, cb }) => {
   const classes = useStyles();
-  // set in progress as defalut status
-  const [status, setStatus] = useState<string>(IndexState.InProgress);
+  // set empty string as defalut status
+  const [status, setStatus] = useState<string>(IndexState.Default);
 
   const { t: indexTrans } = useTranslation('index');
   const { t: btnTrans } = useTranslation('btn');
@@ -86,18 +92,15 @@ const IndexTypeElement: FC<{
   const DeleteIcon = icons.delete;
 
   const fetchStatus = useCallback(async () => {
-    if (data._indexType !== '') {
+    // prevent delete index trigger fetching index status
+    if (data._indexType !== '' && status !== IndexState.Delete) {
       const { state: status } = await IndexHttp.getIndexStatus(
         collectionName,
         data._fieldName
       );
       setStatus(status);
     }
-  }, [collectionName, data._fieldName, data._indexType]);
-
-  useEffect(() => {
-    fetchStatus();
-  }, [fetchStatus]);
+  }, [collectionName, data._fieldName, data._indexType, status]);
 
   const fetchProgress = useCallback(() => {
     if (timer) {
@@ -128,10 +131,13 @@ const IndexTypeElement: FC<{
     }
   }, [collectionName, data._fieldName, status, data._indexType]);
 
-  // get index build progress
   useEffect(() => {
+    /**
+     * fetch index status, then fetch index build progress
+     */
+    fetchStatus();
     fetchProgress();
-  }, [fetchProgress]);
+  }, [fetchStatus, fetchProgress]);
 
   const requestCreateIndex = async (params: ParamPair[]) => {
     const indexCreateParam: IndexCreateParam = {
@@ -140,6 +146,8 @@ const IndexTypeElement: FC<{
       extra_params: params,
     };
     await IndexHttp.createIndex(indexCreateParam);
+    // reset status to default empty string
+    setStatus(IndexState.Default);
     handleCloseDialog();
     openSnackBar(indexTrans('createSuccess'));
     cb(collectionName);
@@ -169,9 +177,11 @@ const IndexTypeElement: FC<{
     };
 
     await IndexHttp.deleteIndex(indexDeleteParam);
+    // use 'delete' as special status for whether fetching index status check
+    setStatus(IndexState.Delete);
+    cb(collectionName);
     handleCloseDialog();
     openSnackBar(successTrans('delete', { name: indexTrans('index') }));
-    cb(collectionName);
   };
 
   const handleDelete = () => {
@@ -215,6 +225,13 @@ const IndexTypeElement: FC<{
         );
       }
       default: {
+        /**
+         * empty string or 'delete' means fetching progress hasn't finished
+         * show loading animation for such situations
+         */
+        if (status === IndexState.Default || status === IndexState.Delete) {
+          return <StatusIcon type={ChildrenStatusType.CREATING} />;
+        }
         return status === IndexState.InProgress ? (
           <CustomLinearProgress
             value={createProgress}
@@ -232,7 +249,7 @@ const IndexTypeElement: FC<{
     }
   };
 
-  return <>{generateElement()}</>;
+  return <div className={classes.wrapper}>{generateElement()}</div>;
 };
 
 export default IndexTypeElement;

+ 3 - 0
client/src/pages/schema/Schema.tsx

@@ -32,6 +32,9 @@ const useStyles = makeStyles((theme: Theme) => ({
   },
 
   paramWrapper: {
+    // set min width to prevent other table cell stretching
+    minWidth: 180,
+
     '& .param': {
       marginRight: theme.spacing(2),
 

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

@@ -4,6 +4,10 @@ export enum IndexState {
   InProgress = 'InProgress',
   Finished = 'Finished',
   Failed = 'Failed',
+
+  // only used by UI
+  Default = '',
+  Delete = 'Delete',
 }
 
 export enum ShowCollectionsType {

+ 1 - 1
server/package.json

@@ -32,7 +32,7 @@
     "@nestjs/websockets": "^8.0.4",
     "@types/passport-jwt": "^3.0.5",
     "@types/passport-local": "^1.0.33",
-    "@zilliz/milvus2-sdk-node": "^1.0.7",
+    "@zilliz/milvus2-sdk-node": "^1.0.11",
     "body-parser": "^1.19.0",
     "cache-manager": "^3.4.4",
     "class-transformer": "^0.4.0",

+ 1 - 1
server/src/cache/config.ts

@@ -2,4 +2,4 @@ export const ttl = 10; //seconds
 export const cacheKeys = {
   LOADEDCOLLECTIONS: 'LOADEDCOLLECTIONS',
   ALLCOLLECTIONS: 'ALLCOLLECTIONS',
-};
+};

+ 20 - 12
server/src/collections/collections.service.ts

@@ -22,60 +22,68 @@ import {
 export class CollectionsService {
   constructor(private milvusService: MilvusService) {}
 
-  get milvusClient() {
-    return this.milvusService.milvusClientGetter;
+  get collectionManager() {
+    return this.milvusService.collectionManager;
+  }
+
+  get dataManager() {
+    return this.milvusService.dataManager;
+  }
+
+  get indexManager() {
+    return this.milvusService.indexManager;
   }
 
   async getCollectionNames(data?: ShowCollectionsReq) {
-    const res = await this.milvusClient.showCollections(data);
+    const res = await this.collectionManager.showCollections(data);
     throwErrorFromSDK(res.status);
     return res;
   }
 
   async createCollection(data: CreateCollectionReq) {
-    const res = await this.milvusClient.createCollection(data);
+    const res = await this.collectionManager.createCollection(data);
     throwErrorFromSDK(res);
     return res;
   }
 
   async describeCollection(data: DescribeCollectionReq) {
-    const res = await this.milvusClient.describeCollection(data);
+    const res = await this.collectionManager.describeCollection(data);
     throwErrorFromSDK(res.status);
     return res;
   }
 
   async dropCollection(data: DropCollectionReq) {
-    const res = await this.milvusClient.dropCollection(data);
+    const res = await this.collectionManager.dropCollection(data);
     throwErrorFromSDK(res);
     return res;
   }
 
   async loadCollection(data: LoadCollectionReq) {
-    const res = await this.milvusClient.loadCollection(data);
+    const res = await this.collectionManager.loadCollection(data);
     throwErrorFromSDK(res);
     return res;
   }
 
   async releaseCollection(data: ReleaseLoadCollectionReq) {
-    const res = await this.milvusClient.releaseCollection(data);
+    const res = await this.collectionManager.releaseCollection(data);
     throwErrorFromSDK(res);
     return res;
   }
 
   async getCollectionStatistics(data: GetCollectionStatisticsReq) {
-    const res = await this.milvusClient.getCollectionStatistics(data);
+    const res = await this.collectionManager.getCollectionStatistics(data);
     throwErrorFromSDK(res.status);
     return res;
   }
 
   async insert(data: InsertReq) {
-    const res = await this.milvusClient.insert(data);
+    const res = await this.dataManager.insert(data);
     throwErrorFromSDK(res.status);
     return res;
   }
 
   async vectorSearch(data: SearchReq) {
-    const res = await this.milvusClient.search(data);
+    const res = await this.dataManager.search(data);
     throwErrorFromSDK(res.status);
     return res;
   }
@@ -88,7 +96,7 @@ export class CollectionsService {
    * @returns
    */
   async getIndexStatus(data: GetIndexStateReq) {
-    const res = await this.milvusClient.getIndexState(data);
+    const res = await this.indexManager.getIndexState(data);
     return res;
   }
 

+ 3 - 5
server/src/collections/dto.ts

@@ -12,11 +12,9 @@ import {
   FieldType,
   ShowCollectionsType,
 } from '@zilliz/milvus2-sdk-node/dist/milvus/types/Collection'; // todo: need improve like export types in root file.
-import {
-  DataType,
-  KeyValuePair,
-} from '@zilliz/milvus2-sdk-node/dist/milvus/types/Common';
+import { DataType } from '@zilliz/milvus2-sdk-node/dist/milvus/types/Common';
 import { ApiProperty } from '@nestjs/swagger';
+import { SearchParam } from '@zilliz/milvus2-sdk-node/dist/milvus/types';
 
 enum VectorTypes {
   Binary = DataType.BinaryVector,
@@ -103,7 +101,7 @@ export class VectorSearch {
   })
   @IsArray()
   @ArrayMinSize(1)
-  search_params: KeyValuePair[];
+  search_params: SearchParam[];
 
   @ApiProperty({
     description: 'Searched vector value',

+ 19 - 2
server/src/milvus/milvus.service.ts

@@ -18,11 +18,28 @@ export class MilvusService {
     return this.milvusClient;
   }
 
+  get collectionManager() {
+    return this.milvusClient.collectionManager;
+  }
+
+  get partitionManager() {
+    return this.milvusClient.partitionManager;
+  }
+
+  get indexManager() {
+    return this.milvusClient.indexManager;
+  }
+
+  get dataManager() {
+    return this.milvusClient.dataManager;
+  }
+
   async connectMilvus(address: string) {
+    // grpc only need address without http
     const milvusAddress = address.replace(/(http|https):\/\//, '');
     try {
       this.milvusClient = new MilvusClient(milvusAddress);
-      await this.milvusClient.hasCollection({
+      await this.milvusClient.collectionManager.hasCollection({
         collection_name: 'not_exist',
       });
       this.milvusAddress = address;
@@ -43,7 +60,7 @@ export class MilvusService {
   }
 
   async flush(data: FlushReq) {
-    const res = await this.milvusClient.flush(data);
+    const res = await this.milvusClient.dataManager.flush(data);
     return res;
   }
 }

+ 8 - 8
server/src/partitions/partitions.service.ts

@@ -16,8 +16,8 @@ import { ROW_COUNT } from '../utils/Const';
 export class PartitionsService {
   constructor(private milvusService: MilvusService) {}
 
-  get milvusClient() {
-    return this.milvusService.milvusClientGetter;
+  get partitionManager() {
+    return this.milvusService.partitionManager;
   }
 
   async getPatitionsInfo(data: ShowPartitionsReq) {
@@ -41,37 +41,37 @@ export class PartitionsService {
   }
 
   async getPartitions(data: ShowPartitionsReq) {
-    const res = await this.milvusClient.showPartitions(data);
+    const res = await this.partitionManager.showPartitions(data);
     throwErrorFromSDK(res.status);
     return res;
   }
 
   async createParition(data: CreatePartitionReq) {
-    const res = await this.milvusClient.createPartition(data);
+    const res = await this.partitionManager.createPartition(data);
     throwErrorFromSDK(res);
     return res;
   }
 
   async deleteParition(data: DropPartitionReq) {
-    const res = await this.milvusClient.dropPartition(data);
+    const res = await this.partitionManager.dropPartition(data);
     throwErrorFromSDK(res);
     return res;
   }
 
   async getPartitionStatistics(data: GetPartitionStatisticsReq) {
-    const res = await this.milvusClient.getPartitionStatistics(data);
+    const res = await this.partitionManager.getPartitionStatistics(data);
     throwErrorFromSDK(res.status);
     return res;
   }
 
   async loadPartitions(data: LoadPartitionsReq) {
-    const res = await this.milvusClient.loadPartitions(data);
+    const res = await this.partitionManager.loadPartitions(data);
     throwErrorFromSDK(res);
     return res;
   }
 
   async releasePartitions(data: ReleasePartitionsReq) {
-    const res = await this.milvusClient.releasePartitions(data);
+    const res = await this.partitionManager.releasePartitions(data);
     throwErrorFromSDK(res);
     return res;
   }

+ 2 - 1
server/src/schema/dto.ts

@@ -1,4 +1,5 @@
 import { ApiProperty } from '@nestjs/swagger';
+import { CreateIndexParam } from '@zilliz/milvus2-sdk-node/dist/milvus/types';
 import {
   IsNotEmpty,
   IsString,
@@ -47,7 +48,7 @@ export class ManageIndex {
   })
   @IsArray()
   @IsOptional()
-  readonly extra_params?: KeyValuePair[];
+  readonly extra_params?: CreateIndexParam[];
 }
 
 export class DescribeIndex {

+ 5 - 5
server/src/schema/schema.controller.ts

@@ -20,7 +20,7 @@ import { SchemaService } from './schema.service';
 @ApiTags('schema')
 @Controller('schema')
 export class SchemaController {
-  constructor(private schemaService: SchemaService) { }
+  constructor(private schemaService: SchemaService) {}
 
   @Post('index')
   @UsePipes(new ValidationPipe())
@@ -28,10 +28,10 @@ export class SchemaController {
     const { type, collection_name, extra_params, field_name } = body;
     return type === ManageType.CREATE
       ? await this.schemaService.createIndex({
-        collection_name,
-        extra_params,
-        field_name,
-      })
+          collection_name,
+          extra_params,
+          field_name,
+        })
       : await this.schemaService.dropIndex({ collection_name, field_name });
   }
 

+ 8 - 8
server/src/schema/schema.service.ts

@@ -11,20 +11,20 @@ import { MilvusService } from '../milvus/milvus.service';
 
 @Injectable()
 export class SchemaService {
-  constructor(private milvusService: MilvusService) { }
+  constructor(private milvusService: MilvusService) {}
 
-  get milvusClient() {
-    return this.milvusService.milvusClientGetter;
+  get indexManager() {
+    return this.milvusService.indexManager;
   }
 
   async createIndex(data: CreateIndexReq) {
-    const res = await this.milvusClient.createIndex(data);
+    const res = await this.indexManager.createIndex(data);
     throwErrorFromSDK(res);
     return res;
   }
 
   async describeIndex(data: DescribeIndexReq) {
-    const res = await this.milvusClient.describeIndex(data);
+    const res = await this.indexManager.describeIndex(data);
     if (res.status.error_code === 'IndexNotExist') {
       return res;
     }
@@ -33,19 +33,19 @@ export class SchemaService {
   }
 
   async dropIndex(data: DropIndexReq) {
-    const res = await this.milvusClient.dropIndex(data);
+    const res = await this.indexManager.dropIndex(data);
     throwErrorFromSDK(res);
     return res;
   }
 
   async getIndexState(data: GetIndexStateReq) {
-    const res = await this.milvusClient.getIndexState(data);
+    const res = await this.indexManager.getIndexState(data);
     throwErrorFromSDK(res.status);
     return res;
   }
 
   async getIndexBuildProgress(data: GetIndexBuildProgressReq) {
-    const res = await this.milvusClient.getIndexBuildProgress(data);
+    const res = await this.indexManager.getIndexBuildProgress(data);
     throwErrorFromSDK(res.status);
     return res;
   }

+ 4 - 4
server/yarn.lock

@@ -1319,10 +1319,10 @@
   resolved "https://registry.yarnpkg.com/@xtuc/long/-/long-4.2.2.tgz#d291c6a4e97989b5c61d9acf396ae4fe133a718d"
   integrity sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ==
 
-"@zilliz/milvus2-sdk-node@^1.0.7":
-  version "1.0.7"
-  resolved "https://registry.yarnpkg.com/@zilliz/milvus2-sdk-node/-/milvus2-sdk-node-1.0.7.tgz#b3d0bedbf9e35662e76e716ddb99dc3fc781fc00"
-  integrity sha512-4DFNqDkELG/s4JHqlT6/yZOtMxBWSca1G+RGfj3UC3pg7ncAUuw7HSpScLJ0uWhdUABWroQC6AD0DLnHNGhjFQ==
+"@zilliz/milvus2-sdk-node@^1.0.11":
+  version "1.0.11"
+  resolved "https://registry.yarnpkg.com/@zilliz/milvus2-sdk-node/-/milvus2-sdk-node-1.0.11.tgz#a8545c2b5d5474de60a5ae2cb65cd06d5cdfba87"
+  integrity sha512-SmpB8txE0mgztxgnL0ssTMij9biji+7ZxmdhN3b0VwrghxfeCvSTRrBYmSE7WTPOK143G4k/trSrESSmcBM+cQ==
   dependencies:
     "@grpc/grpc-js" "^1.2.12"
     "@grpc/proto-loader" "^0.6.0"