Database Operations
Relevant source files
The following files were used as context for generating this wiki page:
Database operations in the Milvus Rust SDK provide the fundamental mechanisms for managing isolated data environments within a Milvus instance. These operations include the creation, deletion, and description of databases, as well as the ability to switch the client context to a specific database for subsequent collection and data manipulations. The system supports advanced configuration through database-level properties, allowing for resource isolation and access control at the database scope.
The database management module is integrated into the primary Client struct, leveraging gRPC-based communication with the Milvus server. It utilizes interceptors to inject database context into requests, ensuring that operations like create_collection or search are routed to the correct logical database container.
Sources: src/database.rs:1-25, src/database.rs:356-385
Database Management Lifecycle
The lifecycle of a database involves its definition via options, creation on the server, and eventually its removal. The SDK provides a builder pattern to configure database properties before creation.
Database Creation and Configuration
Users can define specific properties such as replica numbers and resource groups using CreateDbOptions. These options are converted into key-value pairs for the gRPC CreateDatabaseRequest.
The diagram shows the transition from user-defined options to the final gRPC call handled by the server.
Sources: src/database.rs:50-85, src/database.rs:194-220, src/proto/milvus.proto.milvus.rs:2150-2155
Database Properties
The following table summarizes the configurable properties available during database creation or alteration:
| Property Key | Type | Description |
|---|---|---|
database.replica.number | i32 | Number of replicas to maintain for the database. |
database.resource_groups | Vec<String> | Resource groups dedicated to this database. |
database.diskQuota.mb | i32 | Disk quota allocated in megabytes (MB). |
database.max.collections | i32 | Maximum number of collections allowed. |
database.force.deny.writing | bool | Whether to deny all write operations. |
database.force.deny.reading | bool | Whether to deny all read operations. |
Sources: src/database.rs:388-435
Context Switching
A critical feature of the SDK is the ability to switch the active database context using using_database. This operation reconfigures the internal gRPC client with a DbInterceptor and clears the local CollectionCache to prevent cross-database schema conflicts.
The sequence diagram illustrates how the client state is updated to ensure subsequent calls are scoped to the selected database.
Sources: src/database.rs:356-385
API Reference: Database Operations
| Method | Parameters | Description |
|---|---|---|
create_database | db_name, options | Creates a new database with optional properties. |
describe_database | db_name | Returns DescribeDbResponse (ID, name, timestamp, properties). |
alter_database_properties | db_name, options | Updates existing database configuration. |
drop_database_properties | db_name, keys | Removes specific keys from the database properties. |
list_databases | None | Retrieves a list of all existing database names. |
drop_database | db_name | Permanently deletes a database and all its data. |
Sources: src/database.rs:125-190, src/database.rs:279-325
Stability and HPC Testing
Database operations are validated under high-performance computing (HPC) scenarios to ensure stability. Soak tests run for extended durations (e.g., 60 minutes) performing repeated cycles of creation, usage, and deletion to identify memory leaks or connection drops.
// Example cycle from a soak test
async fn run_full_sdk_cycle(client: &Client, collection_name: &str, partition_name: &str) -> Result<()> {
// 1. Creation and cleaning
if client.has_collection(collection_name).await? {
client.drop_collection(collection_name).await?;
}
// ... subsequent operations in the current database context ...
Ok(())
}
Sources: tests/aggressivehpctesting/phase_3_soak_test.rs:65-80, examples/database.rs:10-50
Database operations provide the multi-tenancy foundation for the Milvus Rust SDK, ensuring isolated management of collections and resources through logical database containers and dynamic client-side context switching.