working created DB over RPC
This commit is contained in:
@@ -73,7 +73,7 @@ async fn main() {
|
|||||||
// Start RPC server if enabled
|
// Start RPC server if enabled
|
||||||
let rpc_handle = if args.enable_rpc {
|
let rpc_handle = if args.enable_rpc {
|
||||||
let rpc_addr = format!("127.0.0.1:{}", args.rpc_port).parse().unwrap();
|
let rpc_addr = format!("127.0.0.1:{}", args.rpc_port).parse().unwrap();
|
||||||
let base_dir = format!("{}/rpc_databases", args.dir);
|
let base_dir = args.dir.clone();
|
||||||
|
|
||||||
match rpc_server::start_rpc_server(rpc_addr, Arc::clone(&server), base_dir).await {
|
match rpc_server::start_rpc_server(rpc_addr, Arc::clone(&server), base_dir).await {
|
||||||
Ok(handle) => {
|
Ok(handle) => {
|
||||||
|
@@ -106,17 +106,36 @@ impl RpcServer for RpcServerImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn create_database(&self, db_index: u64) -> RpcResult<bool> {
|
async fn create_database(&self, db_index: u64) -> RpcResult<bool> {
|
||||||
// Pre-create the database by accessing it through the main server
|
// Lock the main server to create the database
|
||||||
let server_guard = self.main_server.lock().await;
|
let mut server_guard = self.main_server.lock().await;
|
||||||
|
|
||||||
// We can't directly modify selected_db, but we can try to access the storage
|
// Save the current selected_db to restore it later
|
||||||
// This will create the database file if it doesn't exist
|
let original_db = server_guard.selected_db;
|
||||||
// Note: This is a simplified approach - in practice, we'd need to modify the server to allow database pre-creation
|
|
||||||
|
|
||||||
println!("Note: Database {} will be created when first accessed via Redis protocol", db_index);
|
// Temporarily set the selected_db to the target database
|
||||||
println!("Use: redis-cli -p 6379, then: SELECT {}", db_index);
|
server_guard.selected_db = db_index;
|
||||||
|
|
||||||
Ok(true)
|
// Call current_storage() which will create the database file if it doesn't exist
|
||||||
|
match server_guard.current_storage() {
|
||||||
|
Ok(_) => {
|
||||||
|
println!("Successfully created database at index {}", db_index);
|
||||||
|
|
||||||
|
// Restore the original selected_db
|
||||||
|
server_guard.selected_db = original_db;
|
||||||
|
|
||||||
|
Ok(true)
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
// Restore the original selected_db even on error
|
||||||
|
server_guard.selected_db = original_db;
|
||||||
|
|
||||||
|
Err(jsonrpsee::types::ErrorObjectOwned::owned(
|
||||||
|
-32000,
|
||||||
|
format!("Failed to create database {}: {}", db_index, e.0),
|
||||||
|
None::<()>
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn set_database_encryption(&self, db_index: u64, encryption_key: String) -> RpcResult<bool> {
|
async fn set_database_encryption(&self, db_index: u64, encryption_key: String) -> RpcResult<bool> {
|
||||||
|
Reference in New Issue
Block a user