working created DB over RPC
This commit is contained in:
@@ -73,7 +73,7 @@ async fn main() {
|
||||
// Start RPC server if enabled
|
||||
let rpc_handle = if args.enable_rpc {
|
||||
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 {
|
||||
Ok(handle) => {
|
||||
|
@@ -106,18 +106,37 @@ impl RpcServer for RpcServerImpl {
|
||||
}
|
||||
|
||||
async fn create_database(&self, db_index: u64) -> RpcResult<bool> {
|
||||
// Pre-create the database by accessing it through the main server
|
||||
let server_guard = self.main_server.lock().await;
|
||||
// Lock the main server to create the database
|
||||
let mut server_guard = self.main_server.lock().await;
|
||||
|
||||
// We can't directly modify selected_db, but we can try to access the storage
|
||||
// This will create the database file if it doesn't exist
|
||||
// Note: This is a simplified approach - in practice, we'd need to modify the server to allow database pre-creation
|
||||
// Save the current selected_db to restore it later
|
||||
let original_db = server_guard.selected_db;
|
||||
|
||||
println!("Note: Database {} will be created when first accessed via Redis protocol", db_index);
|
||||
println!("Use: redis-cli -p 6379, then: SELECT {}", db_index);
|
||||
// Temporarily set the selected_db to the target database
|
||||
server_guard.selected_db = db_index;
|
||||
|
||||
// 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> {
|
||||
// Note: Encryption is determined at database creation time based on db_index
|
||||
|
Reference in New Issue
Block a user