Skip to content

Commit

Permalink
feat: support alterDatabase (#351)
Browse files Browse the repository at this point in the history
* support alterdatabase

Signed-off-by: ryjiang <jiangruiyi@gmail.com>

* update comments

Signed-off-by: ryjiang <jiangruiyi@gmail.com>

* fix build

Signed-off-by: ryjiang <jiangruiyi@gmail.com>

---------

Signed-off-by: ryjiang <jiangruiyi@gmail.com>
  • Loading branch information
shanghaikid authored Aug 26, 2024
1 parent e386f84 commit c4fe3d3
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
38 changes: 38 additions & 0 deletions milvus/grpc/Database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import {
DropDatabasesRequest,
DescribeDatabaseRequest,
DescribeDatabaseResponse,
AlterDatabaseRequest,
AlterDatabaseResponse,
ResStatus,
promisify,
parseToKeyValue,
} from '../';

export class Database extends BaseClient {
Expand Down Expand Up @@ -145,4 +148,39 @@ export class Database extends BaseClient {
);
return promise;
}

/**
* Modifies database properties.
*
* @param {AlterDatabaseRequest} data - The request parameters.
* @param {string} data.db_name - The name of the database to modify.
* @param {Object} data.properties - The properties to modify. For example, to change the TTL, use {"database.replica.number": 18000}.
* @param {number} [data.timeout] - An optional duration of time in milliseconds to allow for the RPC. If it is set to undefined, the client keeps waiting until the server responds or error occurs. Default is undefined.
*
* @returns {Promise<ResStatus>} The response status of the operation.
* @returns {string} status.error_code - The error code of the operation.
* @returns {string} status.reason - The reason for the error, if any.
*
* @example
* ```
* const milvusClient = new milvusClient(MILUVS_ADDRESS);
* const resStatus = await milvusClient.alterDatabase({
* database: 'my-db',
* properties: {"database.replica.number": 18000}
* });
* ```
*/
async alterDatabase(data: AlterDatabaseRequest): Promise<ResStatus> {
const promise = await promisify(
this.channelPool,
'AlterDatabase',
{
db_name: data.db_name,
properties: parseToKeyValue(data.properties),
},
data?.timeout || this.timeout
);

return promise;
}
}
7 changes: 7 additions & 0 deletions milvus/types/Database.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { GrpcTimeOut, resStatusResponse, KeyValuePair } from './Common';
import { Properties } from './';

// base
export interface databaseReq extends GrpcTimeOut {
Expand All @@ -21,3 +22,9 @@ export interface DescribeDatabaseResponse extends resStatusResponse {
created_timestamp: number; // created timestamp
properties: KeyValuePair[]; // properties
}
export interface AlterDatabaseRequest extends GrpcTimeOut {
db_name: string; // database name
db_id?: string; // database id
properties: Properties;
}
export interface AlterDatabaseResponse extends resStatusResponse {}
17 changes: 16 additions & 1 deletion test/grpc/Database.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MilvusClient, ErrorCode, DEFAULT_DB } from '../../milvus';
import { IP, genCollectionParams, GENERATE_NAME } from '../tools';

let milvusClient = new MilvusClient({ address: IP, logLevel: 'debug' });
let milvusClient = new MilvusClient({ address: IP, logLevel: 'info' });
const DEFAULT = 'default';
const DB_NAME = GENERATE_NAME('database');
const DB_NAME2 = GENERATE_NAME('database');
Expand Down Expand Up @@ -159,6 +159,21 @@ describe(`Database API`, () => {
expect(dropCollections.error_code).toEqual(ErrorCode.SUCCESS);
});

it(`alter database should be ok`, async () => {
const alter = await milvusClient.alterDatabase({
db_name: DB_NAME2,
properties: { 'database.diskQuota.mb': 2048 },
});
expect(alter.error_code).toEqual(ErrorCode.SUCCESS);

const describe = await milvusClient.describeDatabase({
db_name: DB_NAME2,
});
expect(describe.properties).toEqual([
{ key: 'database.diskQuota.mb', value: '2048' },
]);
});

// it(`drop database should be ok`, async () => {
// const all = await milvusClient.listDatabases();

Expand Down

0 comments on commit c4fe3d3

Please sign in to comment.