Browse Source

Merge pull request #54 from iynewz/add-consistency-level

[Issue #35] Add consistency level
nameczz 3 years ago
parent
commit
2fc35bed8d

+ 2 - 0
client/src/i18n/cn/collection.ts

@@ -27,6 +27,8 @@ const collectionTrans = {
   createTitle: 'Create Collection',
   general: '1. General Info',
   schema: '2. Define Schema',
+  consistency: '3. Consistency Level',
+  consistencyLevel: 'Consistency Level',
   description: 'Description (Optional)',
   fieldType: 'Field Type',
   vectorFieldType: 'Vector Field Type',

+ 2 - 0
client/src/i18n/en/collection.ts

@@ -27,6 +27,8 @@ const collectionTrans = {
   createTitle: 'Create Collection',
   general: '1. General Info',
   schema: '2. Define Schema',
+  consistency: '3. Consistency Level',
+  consistencyLevel: 'Consistency Level',
   description: 'Description (Optional)',
   fieldType: 'Field Type',
   vectorFieldType: 'Vector Field Type',

+ 5 - 1
client/src/pages/collections/Collections.tsx

@@ -198,7 +198,11 @@ const Collections = () => {
         }
         : v
     );
-    await CollectionHttp.createCollection(data);
+
+    await CollectionHttp.createCollection({
+      ...data,
+      consistency_level: data.consistency_level,
+    });
     handleCloseDialog();
     openSnackBar(
       successTrans('create', { name: collectionTrans('collection') })

+ 24 - 1
client/src/pages/collections/Constants.ts

@@ -1,5 +1,28 @@
 import { KeyValuePair } from '../../types/Common';
-import { DataTypeEnum } from './Types';
+import { DataTypeEnum, ConsistencyLevelEnum } from './Types';
+
+export const CONSISTENCY_LEVEL_OPTIONS: KeyValuePair[] = [
+  {
+    label: 'Strong',
+    value: ConsistencyLevelEnum.Strong,
+  },
+  {
+    label: 'Session',
+    value: ConsistencyLevelEnum.Session,
+  },
+  {
+    label: 'Bounded',
+    value: ConsistencyLevelEnum.Bounded,
+  },
+  {
+    label: 'Eventually',
+    value: ConsistencyLevelEnum.Eventually,
+  },
+  {
+    label: 'Customized',
+    value: ConsistencyLevelEnum.Customized,
+  },
+];
 
 export const VECTOR_FIELDS_OPTIONS: KeyValuePair[] = [
   {

+ 30 - 1
client/src/pages/collections/Create.tsx

@@ -3,6 +3,7 @@ import { FC, useContext, useMemo, useState } from 'react';
 import { useTranslation } from 'react-i18next';
 import DialogTemplate from '../../components/customDialog/DialogTemplate';
 import CustomInput from '../../components/customInput/CustomInput';
+import CustomSelector from '../../components/customSelector/CustomSelector';
 import { ITextfieldConfig } from '../../components/customInput/Types';
 import { rootContext } from '../../context/Root';
 import { useFormValidation } from '../../hooks/Form';
@@ -13,8 +14,10 @@ import {
   CollectionCreateParam,
   CollectionCreateProps,
   DataTypeEnum,
+  ConsistencyLevelEnum,
   Field,
 } from './Types';
+import { CONSISTENCY_LEVEL_OPTIONS } from './Constants';
 
 const useStyles = makeStyles((theme: Theme) => ({
   fieldset: {
@@ -23,7 +26,7 @@ const useStyles = makeStyles((theme: Theme) => ({
     justifyContent: 'space-between',
     alignItems: 'center',
 
-    '&:last-child': {
+    '&:nth-last-child(2)': {
       flexDirection: 'column',
       alignItems: 'flex-start',
     },
@@ -38,6 +41,14 @@ const useStyles = makeStyles((theme: Theme) => ({
   input: {
     width: '48%',
   },
+  select: {
+    width: '160px',
+    marginBottom: '22px',
+
+    '&:first-child': {
+      marginLeft: 0,
+    },
+  },
 }));
 
 const CreateCollection: FC<CollectionCreateProps> = ({ handleCreate }) => {
@@ -53,6 +64,9 @@ const CreateCollection: FC<CollectionCreateProps> = ({ handleCreate }) => {
     autoID: true,
   });
 
+  const [consistencyLevel, setConsistencyLevel] =
+    useState<ConsistencyLevelEnum>(ConsistencyLevelEnum.Session); // Session is the default value of consistency level
+
   const [fields, setFields] = useState<Field[]>([
     {
       data_type: DataTypeEnum.Int64,
@@ -171,6 +185,7 @@ const CreateCollection: FC<CollectionCreateProps> = ({ handleCreate }) => {
         v.is_primary_key && (data.autoID = form.autoID);
         return data;
       }),
+      consistency_level: consistencyLevel,
     };
     handleCreate(param);
   };
@@ -207,6 +222,20 @@ const CreateCollection: FC<CollectionCreateProps> = ({ handleCreate }) => {
             setAutoID={changeIsAutoID}
           />
         </fieldset>
+
+        <fieldset className={classes.fieldset}>
+          <legend>{collectionTrans('consistency')}</legend>
+          <CustomSelector
+            wrapperClass={classes.select}
+            options={CONSISTENCY_LEVEL_OPTIONS}
+            onChange={(e: React.ChangeEvent<{ value: unknown }>) => {
+              setConsistencyLevel(e.target.value as ConsistencyLevelEnum);
+            }}
+            value={consistencyLevel}
+            variant="filled"
+            label={'Consistency'}
+          />
+        </fieldset>
       </form>
     </DialogTemplate>
   );

+ 9 - 0
client/src/pages/collections/Types.ts

@@ -29,6 +29,15 @@ export interface CollectionCreateParam {
   description: string;
   autoID: boolean;
   fields: Field[];
+  consistency_level: string;
+}
+
+export enum ConsistencyLevelEnum {
+  Strong = "Strong",
+  Session = "Session", // default in PyMilvus
+  Bounded = "Bounded",
+  Eventually = "Eventually",
+  Customized = "Customized", // Users pass their own `guarantee_timestamp`.
 }
 
 export enum DataTypeEnum {