From e1ea2c06cde250ea4988e96fe9ed7e667d269134 Mon Sep 17 00:00:00 2001 From: despiegk Date: Sun, 20 Apr 2025 06:44:16 +0200 Subject: [PATCH] ... --- ourdb/MIGRATION.md | 168 ------------------------------ ourdb/README.md | 7 +- ourdb/benches/ourdb_benchmarks.rs | 20 ++-- ourdb/examples/advanced_usage.rs | 2 +- ourdb/examples/benchmark.rs | 6 +- 5 files changed, 18 insertions(+), 185 deletions(-) delete mode 100644 ourdb/MIGRATION.md diff --git a/ourdb/MIGRATION.md b/ourdb/MIGRATION.md deleted file mode 100644 index 68bc21b..0000000 --- a/ourdb/MIGRATION.md +++ /dev/null @@ -1,168 +0,0 @@ -# OurDB Migration Guide: V to Rust - -This guide helps you migrate from the V implementation of OurDB to the new Rust implementation. - -## Overview - -The Rust implementation of OurDB maintains the same core functionality and data format as the V implementation, allowing for a smooth transition. However, there are some API differences due to Rust's type system and idioms. - -## Key Differences - -### 1. Configuration - -**V Implementation:** -```v -// Create a new OurDB instance -mut db := ourdb.new_db(path: '/path/to/db', incremental_mode: true) -``` - -**Rust Implementation:** -```rust -// Create a new OurDB instance -let config = OurDBConfig { - path: PathBuf::from("/path/to/db"), - incremental_mode: true, - file_size: None, // Use default (500MB) - keysize: None, // Use default (4 bytes) -}; -let mut db = OurDB::new(config)?; -``` - -### 2. Setting Values - -**V Implementation:** -```v -// Set a value with auto-generated ID -id := db.set(data: 'Hello, World!'.bytes())! - -// Set a value with explicit ID -db.set(id: 42, data: 'Hello, World!'.bytes())! -``` - -**Rust Implementation:** -```rust -// Set a value with auto-generated ID -let id = db.set(OurDBSetArgs { - id: None, - data: b"Hello, World!" -})?; - -// Set a value with explicit ID -db.set(OurDBSetArgs { - id: Some(42), - data: b"Hello, World!" -})?; -``` - -### 3. Getting Values - -**V Implementation:** -```v -// Get a value -data := db.get(42)! -``` - -**Rust Implementation:** -```rust -// Get a value -let data = db.get(42)?; -``` - -### 4. Getting History - -**V Implementation:** -```v -// Get history (up to 5 versions) -history := db.get_history(42, 5)! -``` - -**Rust Implementation:** -```rust -// Get history (up to 5 versions) -let history = db.get_history(42, 5)?; -``` - -### 5. Deleting Values - -**V Implementation:** -```v -// Delete a value -db.delete(42)! -``` - -**Rust Implementation:** -```rust -// Delete a value -db.delete(42)?; -``` - -### 6. Error Handling - -**V Implementation:** -```v -// V uses the ! operator for error propagation -result := db.operation()! -``` - -**Rust Implementation:** -```rust -// Rust uses the ? operator for error propagation -let result = db.operation()?; -``` - -### 7. Closing the Database - -**V Implementation:** -```v -// Close the database -db.close()! -``` - -**Rust Implementation:** -```rust -// Close the database -db.close()?; -``` - -## Data Migration - -The Rust implementation uses the same file format as the V implementation, so your existing database files should be compatible. However, it's always recommended to back up your data before migrating. - -To migrate an existing database: - -1. Back up your existing database directory -2. Point the Rust implementation to the same directory -3. Test that all your data is accessible - -Example: -```rust -// Open an existing database created with the V implementation -let config = OurDBConfig { - path: PathBuf::from("/path/to/existing/db"), - incremental_mode: true, // Must match the original configuration - file_size: None, - keysize: None, -}; -let mut db = OurDB::new(config)?; - -// Verify data access -let data = db.get(some_known_id)?; -println!("Retrieved: {:?}", data); -``` - -## Performance Considerations - -The Rust implementation may have different performance characteristics compared to the V implementation. If your application is performance-sensitive, consider running benchmarks to compare the two implementations. - -## Additional Features in Rust Implementation - -The Rust implementation includes some additional features not present in the V implementation: - -1. More comprehensive error types -2. Better memory management -3. Improved thread safety -4. More extensive testing - -## Need Help? - -If you encounter any issues during migration, please refer to the documentation or open an issue in the repository. diff --git a/ourdb/README.md b/ourdb/README.md index cda806a..8e68bbe 100644 --- a/ourdb/README.md +++ b/ourdb/README.md @@ -117,6 +117,8 @@ Run an example with: ```bash cargo run --example basic_usage +cargo run --example advanced_usage +cargo run --example benchmark ``` ## Performance @@ -125,9 +127,8 @@ OurDB is designed for efficiency and minimal overhead. The benchmark example can Typical performance metrics on modern hardware: -- **Write**: 50,000+ operations per second -- **Read**: 100,000+ operations per second -- **Update**: 40,000+ operations per second +- **Write**: 10,000+ operations per second +- **Read**: 50,000+ operations per second ## License diff --git a/ourdb/benches/ourdb_benchmarks.rs b/ourdb/benches/ourdb_benchmarks.rs index f1a796e..19d40c0 100644 --- a/ourdb/benches/ourdb_benchmarks.rs +++ b/ourdb/benches/ourdb_benchmarks.rs @@ -14,7 +14,7 @@ fn criterion_benchmark(c: &mut Criterion) { path: db_path.clone(), incremental_mode: true, file_size: Some(10 * 1024 * 1024), // 10MB - keysize: None, + keysize: Some(6), // Use keysize=6 to allow non-zero file_nr }; let mut db = OurDB::new(config).unwrap(); @@ -36,7 +36,7 @@ fn criterion_benchmark(c: &mut Criterion) { path: db_path.clone(), incremental_mode: true, file_size: Some(10 * 1024 * 1024), // 10MB - keysize: None, + keysize: Some(6), // Use keysize=6 to allow non-zero file_nr }; let mut setup_db = OurDB::new(setup_config).unwrap(); @@ -59,7 +59,7 @@ fn criterion_benchmark(c: &mut Criterion) { path: db_path.clone(), incremental_mode: true, file_size: Some(10 * 1024 * 1024), - keysize: None, + keysize: Some(6), // Use keysize=6 to allow non-zero file_nr }; let mut db = OurDB::new(config).unwrap(); @@ -78,7 +78,7 @@ fn criterion_benchmark(c: &mut Criterion) { path: db_path.clone(), incremental_mode: true, file_size: Some(10 * 1024 * 1024), - keysize: None, + keysize: Some(6), // Use keysize=6 to allow non-zero file_nr }; let mut db = OurDB::new(config).unwrap(); @@ -102,7 +102,7 @@ fn criterion_benchmark(c: &mut Criterion) { path: db_path.clone(), incremental_mode: true, file_size: Some(10 * 1024 * 1024), - keysize: None, + keysize: Some(6), // Use keysize=6 to allow non-zero file_nr }; let mut db = OurDB::new(config).unwrap(); @@ -125,7 +125,7 @@ fn criterion_benchmark(c: &mut Criterion) { path: delete_path.clone(), incremental_mode: true, file_size: Some(10 * 1024 * 1024), - keysize: None, + keysize: Some(6), // Use keysize=6 to allow non-zero file_nr }; let mut db = OurDB::new(config).unwrap(); @@ -165,7 +165,7 @@ fn criterion_benchmark(c: &mut Criterion) { path: kv_path.clone(), incremental_mode: false, // Key-value mode file_size: Some(10 * 1024 * 1024), - keysize: None, + keysize: Some(6), // Use keysize=6 to allow non-zero file_nr }; let mut db = OurDB::new(config).unwrap(); @@ -192,7 +192,7 @@ fn criterion_benchmark(c: &mut Criterion) { path: inc_path.clone(), incremental_mode: true, // Incremental mode file_size: Some(10 * 1024 * 1024), - keysize: None, + keysize: Some(6), // Use keysize=6 to allow non-zero file_nr }; let mut db = OurDB::new(config).unwrap(); @@ -221,7 +221,7 @@ fn criterion_benchmark(c: &mut Criterion) { path: size_path.clone(), incremental_mode: true, file_size: Some(10 * 1024 * 1024), - keysize: None, + keysize: Some(6), // Use keysize=6 to allow non-zero file_nr }; let mut db = OurDB::new(config).unwrap(); @@ -244,7 +244,7 @@ fn criterion_benchmark(c: &mut Criterion) { path: size_path.clone(), incremental_mode: true, file_size: Some(10 * 1024 * 1024), - keysize: None, + keysize: Some(6), // Use keysize=6 to allow non-zero file_nr }; let mut db = OurDB::new(config).unwrap(); diff --git a/ourdb/examples/advanced_usage.rs b/ourdb/examples/advanced_usage.rs index 48b7004..d54056c 100644 --- a/ourdb/examples/advanced_usage.rs +++ b/ourdb/examples/advanced_usage.rs @@ -135,7 +135,7 @@ fn performance_benchmark(base_path: &PathBuf) -> Result<(), ourdb::Error> { let config = OurDBConfig { path: db_path, incremental_mode: true, - file_size: Some(10 * 1024 * 1024), // 10MB + file_size: Some(1024 * 1024), // 10MB keysize: Some(4), // 4-byte keys }; diff --git a/ourdb/examples/benchmark.rs b/ourdb/examples/benchmark.rs index ee02804..fae0c04 100644 --- a/ourdb/examples/benchmark.rs +++ b/ourdb/examples/benchmark.rs @@ -26,7 +26,7 @@ fn main() -> Result<(), ourdb::Error> { let config = OurDBConfig { path: db_path.clone(), incremental_mode, - file_size: Some(50 * 1024 * 1024), // 50MB + file_size: Some(1024 * 1024), keysize: Some(keysize), }; @@ -131,7 +131,7 @@ fn main() -> Result<(), ourdb::Error> { } fn parse_args(args: &[String]) -> (usize, usize, bool, u8) { - let mut num_operations = 10000; + let mut num_operations = 100000; let mut record_size = 100; let mut incremental_mode = true; let mut keysize = 4; @@ -167,7 +167,7 @@ fn print_usage() { println!("Usage: cargo run --example benchmark [OPTIONS]"); println!(); println!("Options:"); - println!(" --ops N Number of operations to perform (default: 10000)"); + println!(" --ops N Number of operations to perform (default: 100000)"); println!(" --size N Size of each record in bytes (default: 100)"); println!(" --keyvalue Use key-value mode instead of incremental mode"); println!(" --keysize N Key size in bytes (2, 3, 4, or 6) (default: 4)");