Skip to content

Commit

Permalink
Support specifying max DB size in rust (#2963)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminwinger committed Feb 28, 2024
1 parent e056583 commit e09b3ec
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
3 changes: 2 additions & 1 deletion tools/rust_api/include/kuzu_rs.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ std::unique_ptr<std::vector<kuzu::common::LogicalType>> logical_type_get_struct_

/* Database */
std::unique_ptr<kuzu::main::Database> new_database(std::string_view databasePath,
uint64_t bufferPoolSize, uint64_t maxNumThreads, bool enableCompression, bool readOnly);
uint64_t bufferPoolSize, uint64_t maxNumThreads, bool enableCompression, bool readOnly,
uint64_t maxDBSize);

void database_set_logging_level(kuzu::main::Database& database, const std::string& level);

Expand Down
28 changes: 28 additions & 0 deletions tools/rust_api/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ pub struct SystemConfig {
/// When true, new columns will be compressed if possible
/// Defaults to true
enable_compression: bool,
/// Whether or not the database can be written to from this instance
/// Defaults to not read-only
read_only: bool,
/// The maximum size of the database. Defaults to 8TB
max_db_size: u64,
}

impl Default for SystemConfig {
Expand All @@ -46,6 +50,8 @@ impl Default for SystemConfig {
max_num_threads: 0,
enable_compression: true,
read_only: false,
// This is a little weird, but it's a temporary interface
max_db_size: u32::MAX as u64,
}
}
}
Expand All @@ -67,6 +73,10 @@ impl SystemConfig {
self.read_only = read_only;
self
}
pub fn max_db_size(mut self, max_db_size: u64) -> Self {
self.max_db_size = max_db_size;
self
}
}

impl Database {
Expand All @@ -86,6 +96,7 @@ impl Database {
config.max_num_threads,
config.enable_compression,
config.read_only,
config.max_db_size,
)?),
})
}
Expand Down Expand Up @@ -172,4 +183,21 @@ mod tests {
);
Ok(())
}

#[test]
fn test_database_max_size() -> Result<()> {
let temp_dir = tempfile::tempdir()?;
{
// Max DB size of 4GB should be fine
Database::new(
temp_dir.path(),
SystemConfig::default().max_db_size(1 << 32),
)?;
}
{
Database::new(temp_dir.path(), SystemConfig::default().max_db_size(0))
.expect_err("0 is not a valid max DB size");
}
Ok(())
}
}
1 change: 1 addition & 0 deletions tools/rust_api/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ pub(crate) mod ffi {
maxNumThreads: u64,
enableCompression: bool,
readOnly: bool,
maxDBSize: u64,
) -> Result<UniquePtr<Database>>;

fn database_set_logging_level(database: Pin<&mut Database>, level: &CxxString);
Expand Down
5 changes: 4 additions & 1 deletion tools/rust_api/src/kuzu_rs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ std::unique_ptr<std::vector<kuzu::common::LogicalType>> logical_type_get_struct_
}

std::unique_ptr<Database> new_database(std::string_view databasePath, uint64_t bufferPoolSize,
uint64_t maxNumThreads, bool enableCompression, bool readOnly) {
uint64_t maxNumThreads, bool enableCompression, bool readOnly, uint64_t maxDBSize) {
auto systemConfig = SystemConfig();
if (bufferPoolSize > 0) {
systemConfig.bufferPoolSize = bufferPoolSize;
Expand All @@ -75,6 +75,9 @@ std::unique_ptr<Database> new_database(std::string_view databasePath, uint64_t b
}
systemConfig.readOnly = readOnly;
systemConfig.enableCompression = enableCompression;
if (maxDBSize != -1u) {
systemConfig.maxDBSize = maxDBSize;
}
return std::make_unique<Database>(databasePath, systemConfig);
}

Expand Down

0 comments on commit e09b3ec

Please sign in to comment.