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

feat: support alterDatabase #351

Merged
merged 3 commits into from
Aug 26, 2024
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
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
Loading