From 8076c9ae10167b71368fdcdaae18ebe821ba55b2 Mon Sep 17 00:00:00 2001 From: ryjiang Date: Thu, 7 May 2026 13:49:21 +0800 Subject: [PATCH] fix: forward compact advanced params Signed-off-by: ryjiang --- milvus/grpc/Collection.ts | 17 +++++++- test/grpc/Compaction.spec.ts | 16 +++++--- test/utils/Compaction.spec.ts | 73 +++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 8 deletions(-) create mode 100644 test/utils/Compaction.spec.ts diff --git a/milvus/grpc/Collection.ts b/milvus/grpc/Collection.ts index 03fc1909..a7fb3856 100644 --- a/milvus/grpc/Collection.ts +++ b/milvus/grpc/Collection.ts @@ -1208,14 +1208,27 @@ export class Collection extends Database { */ async compact(data: CompactReq): Promise { 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; } diff --git a/test/grpc/Compaction.spec.ts b/test/grpc/Compaction.spec.ts index 46cbd256..f4edc8a5 100644 --- a/test/grpc/Compaction.spec.ts +++ b/test/grpc/Compaction.spec.ts @@ -1,9 +1,4 @@ -import { - MilvusClient, - DataType, - ErrorCode, - ERROR_REASONS, -} from '../../milvus'; +import { MilvusClient, DataType, ErrorCode, ERROR_REASONS } from '../../milvus'; import { IP, generateInsertData, @@ -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, diff --git a/test/utils/Compaction.spec.ts b/test/utils/Compaction.spec.ts new file mode 100644 index 00000000..b6822a4e --- /dev/null +++ b/test/utils/Compaction.spec.ts @@ -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'); + }); +});