Skip to content
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
17 changes: 15 additions & 2 deletions milvus/grpc/Collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1208,14 +1208,27 @@ export class Collection extends Database {
*/
async compact(data: CompactReq): Promise<CompactionResponse> {
checkCollectionName(data);
const collectionInfo = await this.describeCollection(data);

const describeReq: DescribeCollectionReq = {
collection_name: data.collection_name,
};
if (data.db_name) {
describeReq.db_name = data.db_name;
}
if (typeof data.timeout !== 'undefined') {
describeReq.timeout = data.timeout;
}

const collectionInfo = await this.describeCollection(describeReq);
const { timeout, ...compactionReq } = data;
const res = await promisify(
this.channelPool,
'ManualCompaction',
{
...compactionReq,
collectionID: collectionInfo.collectionID,
},
data.timeout || this.timeout
timeout || this.timeout
);
return res;
}
Expand Down
16 changes: 10 additions & 6 deletions test/grpc/Compaction.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
MilvusClient,
DataType,
ErrorCode,
ERROR_REASONS,
} from '../../milvus';
import { MilvusClient, DataType, ErrorCode, ERROR_REASONS } from '../../milvus';
import {
IP,
generateInsertData,
Expand Down Expand Up @@ -69,6 +64,15 @@ describe(`Compaction API`, () => {
expect(res).toHaveProperty('compactionID');
});

it(`Compact should forward target_size to server`, async () => {
const res = await milvusClient.compact({
collection_name: COLLECTION_NAME,
target_size: 1,
});
expect(res.status.error_code).toEqual(ErrorCode.IllegalArgument);
expect(res.status.reason).toContain('targetSize 1 MB');
});

it(`GetCompactionState should contain failedPlanNo`, async () => {
const compactRes = await milvusClient.compact({
collection_name: COLLECTION_NAME,
Expand Down
73 changes: 73 additions & 0 deletions test/utils/Compaction.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { ErrorCode, MilvusClient } from '../../milvus';

describe('utils/Compaction', () => {
it('should forward advanced compaction params to ManualCompaction', async () => {
const client = new MilvusClient({
address: 'localhost:19530',
__SKIP_CONNECT__: true,
});

let describeParams: any;
let compactionParams: any;
(client as any).channelPool = {
acquire: jest.fn().mockResolvedValue({
DescribeCollection: (params: any, _options: any, cb: any) => {
describeParams = params;
cb(null, {
status: { error_code: ErrorCode.SUCCESS, reason: '' },
collectionID: '100',
schema: { fields: [], functions: [] },
consistency_level: 'Bounded',
properties: [],
aliases: [],
virtual_channel_names: [],
physical_channel_names: [],
start_positions: [],
});
},
ManualCompaction: (params: any, _options: any, cb: any) => {
compactionParams = params;
cb(null, {
status: { error_code: ErrorCode.SUCCESS, reason: '' },
compactionID: '1',
compactionPlanCount: 1,
});
},
}),
release: jest.fn(),
};

const res = await client.compact({
collection_name: 'test_collection',
db_name: 'test_db',
timetravel: '123',
majorCompaction: true,
partition_id: '456',
channel: 'by-dev-rootcoord-dml_0',
segment_ids: [111, 222],
l0Compaction: true,
target_size: '536870912',
timeout: 1000,
});

expect(res.status.error_code).toEqual(ErrorCode.SUCCESS);
expect(describeParams).toEqual({
collection_name: 'test_collection',
db_name: 'test_db',
timeout: 1000,
});
expect(compactionParams).toEqual({
collection_name: 'test_collection',
db_name: 'test_db',
collectionID: '100',
timetravel: '123',
majorCompaction: true,
partition_id: '456',
channel: 'by-dev-rootcoord-dml_0',
segment_ids: [111, 222],
l0Compaction: true,
target_size: '536870912',
});
expect(compactionParams).not.toHaveProperty('timeout');
});
});