diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 097c191a..2bbd8e47 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -128,7 +128,20 @@ jobs: submodules: true - run: rustup update - uses: Swatinem/rust-cache@v2 - - run: cargo test --all-features + - run: cargo test + env: + RUST_BACKTRACE: 1 + + test_linux_speedb: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - run: rustup update + - uses: Swatinem/rust-cache@v2 + - run: cargo test --features speedb + working-directory: ./lib env: RUST_BACKTRACE: 1 @@ -155,7 +168,21 @@ jobs: - run: rustup update - uses: Swatinem/rust-cache@v2 - run: Remove-Item -LiteralPath "C:\msys64\" -Force -Recurse - - run: cargo test --all-features + - run: cargo test + env: + RUST_BACKTRACE: 1 + + test_windows_speedb: + runs-on: windows-latest + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - run: rustup update + - uses: Swatinem/rust-cache@v2 + - run: Remove-Item -LiteralPath "C:\msys64\" -Force -Recurse + - run: cargo test --features speedb + working-directory: ./lib env: RUST_BACKTRACE: 1 @@ -181,7 +208,7 @@ jobs: submodules: true - run: rustup update - uses: Swatinem/rust-cache@v2 - - run: cargo doc --all-features + - run: cargo doc working-directory: ./lib rustdoc_msrv: @@ -192,7 +219,7 @@ jobs: submodules: true - run: rustup update && rustup override set 1.60.0 - uses: Swatinem/rust-cache@v2 - - run: cargo doc --all-features + - run: cargo doc working-directory: ./lib env: RUSTDOCFLAGS: -D warnings diff --git a/.gitmodules b/.gitmodules index d96fd0dc..e4d48066 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,3 +13,6 @@ [submodule "oxrocksdb-sys/lz4"] path = oxrocksdb-sys/lz4 url = https://github.com/lz4/lz4.git +[submodule "oxrocksdb-sys/speedb"] + path = oxrocksdb-sys/speedb + url = https://github.com/oxigraph/speedb.git diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 83c65895..3f54d788 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -20,6 +20,7 @@ all-features = true [features] default = [] http_client = ["oxhttp", "oxhttp/rustls"] +speedb = ["oxrocksdb-sys/speedb"] [dependencies] rand = "0.8" diff --git a/oxrocksdb-sys/Cargo.toml b/oxrocksdb-sys/Cargo.toml index 657f9994..b1040198 100644 --- a/oxrocksdb-sys/Cargo.toml +++ b/oxrocksdb-sys/Cargo.toml @@ -13,6 +13,9 @@ rust-version = "1.60" build = "build.rs" links = "rocksdb" +[features] +speedb = [] + [dependencies] libc = "0.2" diff --git a/oxrocksdb-sys/README.md b/oxrocksdb-sys/README.md index f4587db6..ae925e88 100644 --- a/oxrocksdb-sys/README.md +++ b/oxrocksdb-sys/README.md @@ -3,4 +3,6 @@ Oxigraph RocksDB bindings [RocksDB](http://rocksdb.org/) bindings for [Oxigraph](https://oxigraph.org). +It is also possible to switch to [Speedb](https://www.speedb.dev/) by enabling the `"seedb"` Cargo feature. + Based on [librocksdb-sys](https://crates.io/crates/librocksdb-sys) under Apache v2 license. diff --git a/oxrocksdb-sys/api/build_version.cc b/oxrocksdb-sys/api/build_version.cc index bdc6246f..01b5c44e 100644 --- a/oxrocksdb-sys/api/build_version.cc +++ b/oxrocksdb-sys/api/build_version.cc @@ -4,6 +4,9 @@ #include "rocksdb/utilities/object_registry.h" #include "rocksdb/version.h" +#ifdef SPEEDB +#include "speedb/version.h" +#endif namespace ROCKSDB_NAMESPACE { std::unordered_map ObjectRegistry::builtins_ = {}; @@ -24,9 +27,24 @@ std::string GetRocksVersionAsString(bool with_patch) { } } +#ifdef SPEEDB +std::string GetSpeedbVersionAsString(bool with_patch) { + std::string version = + std::to_string(SPEEDB_MAJOR) + "." + std::to_string(SPEEDB_MINOR); + if (with_patch) { + version += "." + std::to_string(SPEEDB_PATCH); + } + return version; +} +#endif + std::string GetRocksBuildInfoAsString(const std::string& program, bool verbose) { - std::string info = program + " (RocksDB) " + GetRocksVersionAsString(true); + std::string info = program; +#ifdef SPEEDB + info += " (Speedb " + GetSpeedbVersionAsString(true) + " )"; +#endif + info += " (RocksDB " + GetRocksVersionAsString(true) + " )"; if (verbose) { for (const auto& it : GetRocksBuildProperties()) { info.append("\n "); @@ -37,4 +55,8 @@ std::string GetRocksBuildInfoAsString(const std::string& program, } return info; } + +#ifdef SPEEDB +std::string GetRocksDebugPropertiesAsString() { return ""; } +#endif } // namespace ROCKSDB_NAMESPACE diff --git a/oxrocksdb-sys/api/c.cc b/oxrocksdb-sys/api/c.cc index 49c5e55a..628aa739 100644 --- a/oxrocksdb-sys/api/c.cc +++ b/oxrocksdb-sys/api/c.cc @@ -1,4 +1,8 @@ +#ifdef SPEEDB +#include "../speedb/db/c.cc" +#else #include "../rocksdb/db/c.cc" +#endif #include "c.h" diff --git a/oxrocksdb-sys/api/c.h b/oxrocksdb-sys/api/c.h index c0b2887d..68a92c7d 100644 --- a/oxrocksdb-sys/api/c.h +++ b/oxrocksdb-sys/api/c.h @@ -1,6 +1,10 @@ #pragma once +#ifdef SPEEDB +#include "../speedb/include/rocksdb/c.h" +#else #include "../rocksdb/include/rocksdb/c.h" +#endif #ifdef __cplusplus extern "C" { diff --git a/oxrocksdb-sys/build.rs b/oxrocksdb-sys/build.rs index a2605cd6..e6b9050e 100644 --- a/oxrocksdb-sys/build.rs +++ b/oxrocksdb-sys/build.rs @@ -32,29 +32,42 @@ fn bindgen_rocksdb() { fn build_rocksdb() { let target = var("TARGET").unwrap(); + let speedb = cfg!(feature = "speedb"); let mut config = cc::Build::new(); config .cpp(true) - .include("rocksdb/include/") - .include("rocksdb/") + .include(if speedb { + "speedb/include/" + } else { + "rocksdb/include/" + }) + .include(if speedb { "speedb/" } else { "rocksdb/" }) .file("api/c.cc") .file("api/build_version.cc") .define("NDEBUG", Some("1")) .define("LZ4", Some("1")) .include("lz4/lib/"); - let mut lib_sources = include_str!("rocksdb/src.mk") - .split_once("LIB_SOURCES =") - .unwrap() - .1 - .split_once("ifeq") - .unwrap() - .0 - .split('\\') - .map(str::trim) - .filter(|p| !p.is_empty()) - .collect::>(); + let mut lib_sources = if speedb { + include_str!("speedb/src.mk") + } else { + include_str!("rocksdb/src.mk") + } + .split_once("LIB_SOURCES =") + .unwrap() + .1 + .split_once("ifeq") + .unwrap() + .0 + .split('\\') + .map(str::trim) + .filter(|p| !p.is_empty()) + .collect::>(); + + if speedb { + config.define("SPEEDB", None); + } if target.contains("x86_64") { // This is needed to enable hardware CRC32C. Technically, SSE 4.2 is @@ -177,7 +190,11 @@ fn build_rocksdb() { if file == "db/c.cc" || file == "util/build_version.cc" { continue; } - config.file(&format!("rocksdb/{file}")); + config.file(&if speedb { + format!("speedb/{file}") + } else { + format!("rocksdb/{file}") + }); } config.compile("rocksdb"); } diff --git a/oxrocksdb-sys/speedb b/oxrocksdb-sys/speedb new file mode 160000 index 00000000..288398bf --- /dev/null +++ b/oxrocksdb-sys/speedb @@ -0,0 +1 @@ +Subproject commit 288398bf74c5c8d708a2f1823cf5db38975dabc8 diff --git a/oxrocksdb-sys/trim_rocksdb.sh b/oxrocksdb-sys/trim_rocksdb.sh index d76eda76..5fcb96a1 100644 --- a/oxrocksdb-sys/trim_rocksdb.sh +++ b/oxrocksdb-sys/trim_rocksdb.sh @@ -2,3 +2,5 @@ cd "$(dirname "$0")"/rocksdb || return rm -rf java .circleci .github build_tools coverage db_stress_tool docs examples fuzz java microbench ./**/*_test.cc +cd "$(dirname "$0")"/speedb || return +rm -rf java .circleci .github build_tools coverage db_stress_tool docs examples fuzz java microbench ./**/*_test.cc diff --git a/server/Cargo.toml b/server/Cargo.toml index f4c1acff..ba909b21 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -12,6 +12,9 @@ Oxigraph SPARQL HTTP server edition = "2021" rust-version = "1.60" +[features] +speedb = ["oxigraph/speedb"] + [dependencies] anyhow = "1" oxhttp = { version = "0.1", features = ["rayon"] } diff --git a/server/src/main.rs b/server/src/main.rs index cec53526..336f055e 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -1604,6 +1604,11 @@ mod tests { escargot::CargoBuild::new() .bin(env!("CARGO_PKG_NAME")) .manifest_path(format!("{}/Cargo.toml", env!("CARGO_MANIFEST_DIR"))) + .features(if cfg!(feature = "speedb") { + "speedb" + } else { + "" + }) .run()? .command(), ))