Skip to content

Commit

Permalink
Merge pull request #257 from zilliztech/segments_view
Browse files Browse the repository at this point in the history
segments view
  • Loading branch information
shanghaikid authored Aug 31, 2023
2 parents 94c712f + a34de1a commit b4d6e4e
Show file tree
Hide file tree
Showing 7 changed files with 244 additions and 0 deletions.
14 changes: 14 additions & 0 deletions client/src/http/Collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,20 @@ export class CollectionHttp extends BaseModel implements CollectionView {
return super.search({ path: this.COLLECTIONS_STATISTICS_URL, params: {} });
}

static getPSegments(collectionName: string) {
return super.search({
path: `${this.COLLECTIONS_URL}/${collectionName}/psegments`,
params: {},
});
}

static getQSegments(collectionName: string) {
return super.search({
path: `${this.COLLECTIONS_URL}/${collectionName}/qsegments`,
params: {},
});
}

static insertData(collectionName: string, param: InsertDataParam) {
return super.create({
path: `${this.COLLECTIONS_URL}/${collectionName}/insert`,
Expand Down
13 changes: 13 additions & 0 deletions client/src/i18n/en/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ const collectionTrans = {
schemaTab: 'Schema',
queryTab: 'Data Query',
previewTab: 'Data Preview',
segmentsTab: 'Segments',
startTip: 'Start your data query',
dataQuerylimits:
' Please note that the maximum number of results for your data query is 16384.',
Expand All @@ -100,6 +101,18 @@ const collectionTrans = {
// rename dialog
newColNamePlaceholder: 'New Collection Name',
newNameInfo: 'Only numbers, letters, and underscores are allowed.',

// segement
segements: 'Segments',
segPState: 'Persistent Segment State',
partitionID: 'Partition ID',
segmentID: 'Segment ID',
num_rows: 'Row Count',
q_nodeIds: 'Query Node IDs',
q_index_name: 'Index Name',
q_indexID: 'Index ID',
q_state: 'Query Segment State',
q_mem_size: 'Memory Size',
};

export default collectionTrans;
6 changes: 6 additions & 0 deletions client/src/pages/collections/Collection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { parseLocationSearch } from '@/utils';
import Schema from '../schema/Schema';
import Query from '../query/Query';
import Preview from '../preview/Preview';
import Segments from '../segments/Segments';

import { TAB_ENUM } from './Types';

const useStyles = makeStyles((theme: Theme) => ({
Expand Down Expand Up @@ -77,6 +79,10 @@ const Collection = () => {
label: collectionTrans('queryTab'),
component: <Query collectionName={collectionName} />,
},
{
label: collectionTrans('segmentsTab'),
component: <Segments collectionName={collectionName} />,
},
];

// exclude parititon on cloud
Expand Down
143 changes: 143 additions & 0 deletions client/src/pages/segments/Segments.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import { useEffect, useState, FC } from 'react';
import { useTranslation } from 'react-i18next';
import { CollectionHttp } from '@/http';
import { usePaginationHook } from '@/hooks';
import AttuGrid from '@/components/grid/Grid';
import { ColDefinitionsType } from '@/components/grid/Types';
import { ToolBarConfig } from '@/components/grid/Types';
import CustomToolBar from '@/components/grid/ToolBar';
import { getQueryStyles } from '../query/Styles';
import { Segment } from './Types';

const Segments: FC<{
collectionName: string;
}> = ({ collectionName }) => {
const classes = getQueryStyles();
const [segments, setSegements] = useState<Segment[]>([]);
const { t: collectionTrans } = useTranslation('collection');
const [loading, setLoading] = useState<boolean>(true);

const fetchSegments = async () => {
setLoading(true);

const psegments = await CollectionHttp.getPSegments(collectionName);
const qsegments = await CollectionHttp.getQSegments(collectionName);

const combinedArray = psegments.infos.map((p: any) => {
const q = qsegments.infos.find((q: any) => q.segmentID === p.segmentID);
return {
...p,
...(q &&
Object.keys(q).reduce((acc: any, key) => {
acc[`q_${key}`] = q[key];
return acc;
}, {})),
};
});

setSegements(combinedArray);
setLoading(false);
};

const toolbarConfigs: ToolBarConfig[] = [
{
type: 'iconBtn',
onClick: () => {
fetchSegments();
},
label: collectionTrans('refresh'),
icon: 'refresh',
},
];

const colDefinitions: ColDefinitionsType[] = [
{
id: 'segmentID',
align: 'left',
disablePadding: false,
label: collectionTrans('segmentID'),
},
{
id: 'partitionID',
align: 'left',
disablePadding: false,
label: collectionTrans('partitionID'),
},
{
id: 'state',
align: 'left',
disablePadding: false,
label: collectionTrans('segPState'),
},
{
id: 'num_rows',
align: 'left',
disablePadding: false,
label: collectionTrans('num_rows'),
},
{
id: 'q_nodeIds',
align: 'left',
disablePadding: false,
label: collectionTrans('q_nodeIds'),
},
{
id: 'q_state',
align: 'left',
disablePadding: false,
label: collectionTrans('q_state'),
},
{
id: 'q_index_name',
align: 'left',
disablePadding: false,
label: collectionTrans('q_index_name'),
},
];

useEffect(() => {
fetchSegments();
}, []);

const {
pageSize,
handlePageSize,
currentPage,
handleCurrentPage,
total,
data,
order,
orderBy,
handleGridSort,
} = usePaginationHook(segments);

const handlePageChange = (e: any, page: number) => {
handleCurrentPage(page);
};

return (
<div className={classes.root}>
<CustomToolBar toolbarConfigs={toolbarConfigs} />

<AttuGrid
toolbarConfigs={[]}
colDefinitions={colDefinitions}
rows={data}
rowCount={total}
primaryKey="name"
showPagination={true}
openCheckBox={false}
page={currentPage}
onPageChange={handlePageChange}
rowsPerPage={pageSize}
setRowsPerPage={handlePageSize}
isLoading={loading}
order={order}
orderBy={orderBy}
handleSort={handleGridSort}
/>
</div>
);
};

export default Segments;
17 changes: 17 additions & 0 deletions client/src/pages/segments/Types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export type Segment = {
collectionID: string;
num_rows: string;
partitionID: string;
q_collectionID: string;
q_indexID: string;
q_index_name: string;
q_mem_size: string;
q_nodeID: string;
q_nodeIds: string[];
q_num_rows: string;
q_partitionID: string;
q_segmentID: string;
q_state: string;
segmentID: string;
state: string;
};
30 changes: 30 additions & 0 deletions server/src/collections/collections.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export class CollectionController {
);
this.router.delete('/:name/alias/:alias', this.dropAlias.bind(this));
this.router.get('/:name', this.describeCollection.bind(this));

// load / release
this.router.put('/:name/load', this.loadCollection.bind(this));
this.router.put('/:name/release', this.releaseCollection.bind(this));
this.router.post(
Expand Down Expand Up @@ -81,6 +83,10 @@ export class CollectionController {
this.createAlias.bind(this)
);

// segements
this.router.get('/:name/psegments', this.getPSegement.bind(this));
this.router.get('/:name/qsegments', this.getQSegement.bind(this));

return this.router;
}

Expand Down Expand Up @@ -327,4 +333,28 @@ export class CollectionController {
next(error);
}
}

async getPSegement(req: Request, res: Response, next: NextFunction) {
const name = req.params?.name;
try {
const result = await this.collectionsService.getPersistentSegmentInfo({
collectionName: name,
});
res.send(result);
} catch (error) {
next(error);
}
}

async getQSegement(req: Request, res: Response, next: NextFunction) {
const name = req.params?.name;
try {
const result = await this.collectionsService.getQuerySegmentInfo({
collectionName: name,
});
res.send(result);
} catch (error) {
next(error);
}
}
}
21 changes: 21 additions & 0 deletions server/src/collections/collections.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import {
ShowCollectionsReq,
ShowCollectionsType,
DeleteEntitiesReq,
GetCompactionStateReq,
GetQuerySegmentInfoReq,
GePersistentSegmentInfoReq,
} from '@zilliz/milvus2-sdk-node';
import { throwErrorFromSDK } from '../utils/Error';
import { findKeyValue, genRows } from '../utils/Helper';
Expand Down Expand Up @@ -290,4 +293,22 @@ export class CollectionsService {

return await this.insert({ collection_name, fields_data });
}

async getCompactionState(data: GetCompactionStateReq) {
const res = await this.milvusService.client.getCompactionState(data);
throwErrorFromSDK(res.status);
return res;
}

async getQuerySegmentInfo(data: GetQuerySegmentInfoReq) {
const res = await this.milvusService.client.getQuerySegmentInfo(data);
throwErrorFromSDK(res.status);
return res;
}

async getPersistentSegmentInfo(data: GePersistentSegmentInfoReq) {
const res = await this.milvusService.client.getPersistentSegmentInfo(data);
throwErrorFromSDK(res.status);
return res;
}
}

0 comments on commit b4d6e4e

Please sign in to comment.