Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use describeIndex instead of getIndexState #287

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 6 additions & 34 deletions client/src/http/MilvusIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Expand All @@ -21,30 +23,16 @@ 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;

const res = await super.findAll({
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) {
Expand All @@ -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 || '';
}
Expand Down
19 changes: 13 additions & 6 deletions client/src/pages/schema/IndexTypeElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,27 @@ 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
fetchStatus(collectionName, fieldName, indexName);
}

// update state
setStatus(state);
if (indexDescription) {
setStatus(indexDescription.state);
}
};
// prevent delete index trigger fetching index status
if (data._indexType !== '' && status !== IndexState.Delete) {
Expand Down
11 changes: 11 additions & 0 deletions client/src/types/Milvus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 7 additions & 7 deletions server/src/collections/collections.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -167,7 +167,7 @@ export class CollectionsService {
collection_name: name,
});

const indexRes = await this.getIndexStatus({
const indexRes = await this.getIndexInfo({
collection_name: item.name,
});

Expand Down Expand Up @@ -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,
});
Expand Down Expand Up @@ -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,
});
}
}
Expand Down
37 changes: 0 additions & 37 deletions server/src/schema/schema.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}
}
}
12 changes: 0 additions & 12 deletions server/src/schema/schema.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Loading