-
Notifications
You must be signed in to change notification settings - Fork 33
feat(conf): support configuring DB storage directory #243
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
base: feat/raft
Are you sure you want to change the base?
Changes from 1 commit
4642b03
70d4f76
bc86a5b
3dbe348
4f68455
95ce678
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,6 +60,7 @@ mod tests { | |
|
|
||
| assert_eq!(50, config.timeout); | ||
| assert_eq!("/data/kiwi_rs/logs", config.log_dir); | ||
| assert_eq!("./db", config.db_dir); | ||
| assert!(!config.redis_compatible_mode); | ||
| assert_eq!(3, config.db_instance_num); | ||
|
|
||
|
|
@@ -78,6 +79,7 @@ mod tests { | |
| timeout: 100, | ||
| redis_compatible_mode: false, | ||
| log_dir: "".to_string(), | ||
| db_dir: "./db".to_string(), | ||
| memory: 1024, | ||
| rocksdb_max_subcompactions: 0, | ||
| rocksdb_max_background_jobs: 4, | ||
|
|
@@ -104,4 +106,26 @@ mod tests { | |
| invalid_config.port = 8080; | ||
| assert!(invalid_config.validate().is_ok()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_db_dir_default() { | ||
| let config = Config::default(); | ||
| assert_eq!("./db", config.db_dir); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_db_dir_from_config_file() { | ||
| use std::io::Write; | ||
|
|
||
| let config_path = "/tmp/kiwi_test_db_dir.conf"; | ||
| let mut f = std::fs::File::create(config_path).unwrap(); | ||
| writeln!(f, "port 7379").unwrap(); | ||
| writeln!(f, "db-dir /data/kiwi/db").unwrap(); | ||
| drop(f); | ||
|
|
||
| let config = Config::load(config_path).unwrap(); | ||
| assert_eq!("/data/kiwi/db", config.db_dir); | ||
|
|
||
| let _ = std::fs::remove_file(config_path); | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -99,7 +99,7 @@ impl ServerFactory { | |
| } | ||
| } | ||
| #[cfg(unix)] | ||
| "unix" => Some(Box::new(unix::UnixServer::new(addr))), | ||
| "unix" => Some(Box::new(unix::UnixServer::new(addr, None))), | ||
| #[cfg(not(unix))] | ||
|
Comment on lines
101
to
105
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch. The |
||
| "unix" => None, | ||
| _ => None, | ||
|
|
@@ -110,13 +110,14 @@ impl ServerFactory { | |
| pub fn create_legacy_server( | ||
| protocol: &str, | ||
| addr: Option<String>, | ||
| db_dir: Option<&str>, | ||
| ) -> Option<Box<dyn ServerTrait>> { | ||
| match protocol.to_lowercase().as_str() { | ||
| "tcp" => TcpServer::new(addr) | ||
| "tcp" => TcpServer::new(addr, db_dir) | ||
| .ok() | ||
| .map(|s| Box::new(s) as Box<dyn ServerTrait>), | ||
| #[cfg(unix)] | ||
| "unix" => Some(Box::new(unix::UnixServer::new(addr))), | ||
| "unix" => Some(Box::new(unix::UnixServer::new(addr, db_dir))), | ||
| #[cfg(not(unix))] | ||
| "unix" => None, | ||
| _ => None, | ||
|
|
@@ -172,9 +173,10 @@ impl ServerFactory { | |
| protocol: &str, | ||
| addr: Option<String>, | ||
| raft_node: Arc<dyn Send + Sync>, | ||
| db_dir: Option<&str>, | ||
| ) -> Option<Box<dyn ServerTrait>> { | ||
| match protocol.to_lowercase().as_str() { | ||
| "tcp" => ClusterTcpServer::new(addr, raft_node) | ||
| "tcp" => ClusterTcpServer::new(addr, raft_node, db_dir) | ||
| .ok() | ||
| .map(|s| Box::new(s) as Box<dyn ServerTrait>), | ||
| _ => None, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,10 +33,10 @@ pub struct UnixServer { | |
| } | ||
|
|
||
| impl UnixServer { | ||
| pub fn new(path: Option<String>) -> Self { | ||
| pub fn new(path: Option<String>, db_dir: Option<&str>) -> Self { | ||
| let path = path.unwrap_or_else(|| "/tmp/kiwidb.sock".to_string()); | ||
| let storage_options = Arc::new(StorageOptions::default()); | ||
| let db_path = PathBuf::from("./db"); | ||
| let db_path = PathBuf::from(db_dir.unwrap_or("./db")); | ||
| let mut storage = Storage::new(1, 0); | ||
| storage.open(storage_options, db_path).unwrap(); | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| let executor = Arc::new(CmdExecutorBuilder::new().build()); | ||
|
Comment on lines
38
to
44
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in the same change — |
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.