diff --git a/Cargo.toml b/Cargo.toml index a1f39f2..2bbc505 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ description = "An in-process property graph database management system built for keywords = ["database", "graph", "ffi"] readme = "lbug-src/README.md" homepage = "https://ladybugdb.com/" -repository = "https://github.com/lbugdb/lbug" +repository = "https://github.com/LadybugDB/ladybug-rust" license = "MIT" categories = ["database"] diff --git a/include/lbug_rs.h b/include/lbug_rs.h index 69eb2e0..065a145 100644 --- a/include/lbug_rs.h +++ b/include/lbug_rs.h @@ -97,7 +97,7 @@ inline uint32_t logical_type_get_decimal_scale(const lbug::common::LogicalType& std::unique_ptr new_database(std::string_view databasePath, uint64_t bufferPoolSize, uint64_t maxNumThreads, bool enableCompression, bool readOnly, uint64_t maxDBSize, bool autoCheckpoint, int64_t checkpointThreshold, - bool throwOnWalReplayFailure, bool enableChecksums); + bool throwOnWalReplayFailure, bool enableChecksums, bool enableMultiWrites); void database_set_logging_level(lbug::main::Database& database, const std::string& level); diff --git a/src/database.rs b/src/database.rs index 0f99fcd..82a9ff4 100644 --- a/src/database.rs +++ b/src/database.rs @@ -43,6 +43,9 @@ pub struct SystemConfig { throw_on_wal_replay_failure: bool, /// If true, the database will use checksums to detect corruption in the WAL file. enable_checksums: bool, + /// If true, multiple concurrent write transactions are allowed. + /// Defaults to false + enable_multi_writes: bool, } #[cfg(test)] @@ -58,6 +61,7 @@ pub(crate) const SYSTEM_CONFIG_FOR_TESTS: SystemConfig = SystemConfig { checkpoint_threshold: -1_i64, throw_on_wal_replay_failure: true, enable_checksums: true, + enable_multi_writes: false, }; impl Default for SystemConfig { @@ -73,6 +77,7 @@ impl Default for SystemConfig { checkpoint_threshold: -1_i64, throw_on_wal_replay_failure: true, enable_checksums: true, + enable_multi_writes: false, } } } @@ -114,6 +119,10 @@ impl SystemConfig { self.enable_checksums = enable_checksums; self } + pub fn enable_multi_writes(mut self, enable_multi_writes: bool) -> Self { + self.enable_multi_writes = enable_multi_writes; + self + } } pub(crate) const IN_MEMORY_DB_NAME: &str = ":memory:"; @@ -138,6 +147,7 @@ impl Database { config.checkpoint_threshold, config.throw_on_wal_replay_failure, config.enable_checksums, + config.enable_multi_writes, )?), }) } @@ -343,4 +353,19 @@ mod tests { assert!(results == HashSet::from(["Alice".to_string(), "Bob".to_string()])); Ok(()) } + + #[test] + fn test_database_enable_multi_writes() -> Result<()> { + let temp_dir = tempfile::tempdir()?; + let db = Database::new( + temp_dir.path().join("test"), + SYSTEM_CONFIG_FOR_TESTS.enable_multi_writes(true), + )?; + let conn1 = Connection::new(&db)?; + conn1.query("BEGIN TRANSACTION")?; + conn1.query("CREATE NODE TABLE t(a INT, b INT, PRIMARY KEY(a))")?; + let conn2 = Connection::new(&db)?; + conn2.query("BEGIN TRANSACTION")?; + Ok(()) + } } diff --git a/src/ffi.rs b/src/ffi.rs index ec48779..cb5df90 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -196,6 +196,7 @@ pub(crate) mod ffi { checkpoint_threshold: i64, throw_on_wal_replay_failure: bool, enable_checksums: bool, + enableMultiWrites: bool, ) -> Result>; } diff --git a/src/lbug_rs.cpp b/src/lbug_rs.cpp index 84e9e02..ac6574f 100644 --- a/src/lbug_rs.cpp +++ b/src/lbug_rs.cpp @@ -68,7 +68,7 @@ std::unique_ptr> logical_type_get_struct_ std::unique_ptr new_database(std::string_view databasePath, uint64_t bufferPoolSize, uint64_t maxNumThreads, bool enableCompression, bool readOnly, uint64_t maxDBSize, bool autoCheckpoint, int64_t checkpointThreshold, bool throwOnWalReplayFailure, - bool enableChecksums) { + bool enableChecksums, bool enableMultiWrites) { auto systemConfig = SystemConfig(); if (bufferPoolSize > 0) { systemConfig.bufferPoolSize = bufferPoolSize; @@ -87,6 +87,7 @@ std::unique_ptr new_database(std::string_view databasePath, uint64_t b } systemConfig.throwOnWalReplayFailure = throwOnWalReplayFailure; systemConfig.enableChecksums = enableChecksums; + systemConfig.enableMultiWrites = enableMultiWrites; return std::make_unique(databasePath, systemConfig); }