Skip to content

Commit

Permalink
update rocksdb to v9.8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Congyuwang committed Dec 13, 2024
2 parents a5a5b7c + 858ce71 commit 669ff78
Show file tree
Hide file tree
Showing 24 changed files with 566 additions and 178 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,35 @@ jobs:
- name: Install dependencies
if: runner.os == 'Windows'
run: choco install llvm -y
- name: Mark working directory as read-only
# to ensure that the tests always use a temporary directory
if: runner.os == 'Linux'
run: |
mkdir -p target
touch Cargo.lock
git submodule update --init --recursive
chmod -R a-w .
chmod -R a+w target Cargo.lock
- name: Run rocksdb tests
run: |
cargo test --all
cargo test --all --features multi-threaded-cf
- name: Mark working directory as writable
if: runner.os == 'Linux'
run: chmod -R a+w .
- name: Free disk space
run: cargo clean
- name: Mark working directory as read-only
# to ensure that the tests always use a temporary directory
if: runner.os == 'Linux'
run: |
mkdir -p target
touch Cargo.lock
chmod -R a-w .
chmod -R a+w target Cargo.lock
- name: Run rocksdb tests (jemalloc)
if: runner.os != 'Windows'
run: cargo test --all --features jemalloc
- name: Mark working directory as writable
if: runner.os == 'Linux'
run: chmod -R a+w .
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
* Document that `default` column family doesn't inherit open options of db (
0xdeafbeef)
* Expose LRU cache options (athre0z)
* Add `with_capacity_bytes` to `WriteBatch` (0xdeafbeef)
* Add `set_compaction_pri` to `Options` (0xdeafbeef)
* Add `lto` feature to enable link-time optimization using `linker-plugin-lto` (0xdeafbeef)

## [Breaking Changes]
* Update jemalloc-sys to 0.6.0 (0xdeafbeef)
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ multi-threaded-cf = []
serde1 = ["serde"]
bindgen-runtime = ["librocksdb-sys/bindgen-runtime"]
bindgen-static = ["librocksdb-sys/bindgen-static"]
lto = ["librocksdb-sys/lto"]

[dependencies]
libc = "0.2"
librocksdb-sys = { path = "librocksdb-sys", version = "0.17.0", default-features = false, features = [
librocksdb-sys = { path = "librocksdb-sys", version = "0.17.1", default-features = false, features = [
"static",
] }
serde = { version = "1", features = ["derive"], optional = true }
Expand Down
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,29 @@ The feature `mt_static` will request the library to be built with [/MT](https://
flag, which results in library using the static version of the run-time library.
*This can be useful in case there's a conflict in the dependecy tree between different
run-time versions.*

## Switch between static and dynamic linking for bindgen (features `bindgen-static` and `bindgen-runtime`)

The feature `bindgen-runtime` will enable the `runtime` feature of bindgen, which dynamically
links to libclang. This is suitable for most platforms, and is enabled by default.

The feature `bindgen-static` will enable the `static` feature of bindgen, which statically
links to libclang. This is suitable for musllinux platforms, such as Alpine linux.
To build on Alpine linux for example, make these changes to your Cargo.toml:

```toml
[dependencies.rocksdb]
default-features = false
features = ["bindgen-static", "snappy", "lz4", "zstd", "zlib", "bzip2"]
```

Notice that `runtime` and `static` features are mutually exclusive, and won't compile if both enabled.

## LTO
Enable the `lto` feature to enable link-time optimization. It will compile rocksdb with `-flto` flag. This feature is disabled by default.

> [!IMPORTANT]
> You must use clang as `CC`. Eg. `CC=/usr/bin/clang CXX=/usr/bin/clang++`. Clang llvm version must be the same as the one used by rust compiler.
> On the rust side you should use `RUSTFLAGS="-Clinker-plugin-lto -Clinker=clang -Clink-arg=-fuse-ld=lld"`.
Check the [Rust documentation](https://doc.rust-lang.org/rustc/linker-plugin-lto.html) for more information.
1 change: 0 additions & 1 deletion clippy.toml

This file was deleted.

3 changes: 2 additions & 1 deletion librocksdb-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "librocksdb-sys"
version = "0.17.0+9.0.0"
version = "0.17.1+9.8.4"
edition = "2018"
rust-version = "1.71.1"
authors = [
Expand Down Expand Up @@ -29,6 +29,7 @@ zstd = ["zstd-sys"]
zlib = ["libz-sys"]
bzip2 = ["bzip2-sys"]
rtti = []
lto = []

[dependencies]
libc = "0.2"
Expand Down
24 changes: 24 additions & 0 deletions librocksdb-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ fn build_rocksdb() {
config.define("USE_RTTI", Some("1"));
}

// https://github.com/facebook/rocksdb/blob/be7703b27d9b3ac458641aaadf27042d86f6869c/Makefile#L195
if cfg!(feature = "lto") {
config.flag("-flto");
if !config.get_compiler().is_like_clang() {
panic!(
"LTO is only supported with clang. Either disable the `lto` feature\
or set `CC=/usr/bin/clang CXX=/usr/bin/clang++` environment variables."
);
}
}

config.include(".");
config.define("NDEBUG", Some("1"));

Expand Down Expand Up @@ -166,10 +177,23 @@ fn build_rocksdb() {
config.define("OS_LINUX", None);
config.define("ROCKSDB_PLATFORM_POSIX", None);
config.define("ROCKSDB_LIB_IO_POSIX", None);
config.define("ROCKSDB_SCHED_GETCPU_PRESENT", None);
} else if target.contains("dragonfly") {
config.define("OS_DRAGONFLYBSD", None);
config.define("ROCKSDB_PLATFORM_POSIX", None);
config.define("ROCKSDB_LIB_IO_POSIX", None);
} else if target.contains("freebsd") {
config.define("OS_FREEBSD", None);
config.define("ROCKSDB_PLATFORM_POSIX", None);
config.define("ROCKSDB_LIB_IO_POSIX", None);
} else if target.contains("netbsd") {
config.define("OS_NETBSD", None);
config.define("ROCKSDB_PLATFORM_POSIX", None);
config.define("ROCKSDB_LIB_IO_POSIX", None);
} else if target.contains("openbsd") {
config.define("OS_OPENBSD", None);
config.define("ROCKSDB_PLATFORM_POSIX", None);
config.define("ROCKSDB_LIB_IO_POSIX", None);
} else if target.contains("windows") {
link("rpcrt4", false);
link("shlwapi", false);
Expand Down
8 changes: 4 additions & 4 deletions librocksdb-sys/build_version.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@

// The build script may replace these values with real values based
// on whether or not GIT is available and the platform settings
static const std::string rocksdb_build_git_sha = "f4441966592636253fd5ab0bb9ed44fc2697fc53";
static const std::string rocksdb_build_git_tag = "rocksdb_build_git_tag:v9.0.0";
static const std::string rocksdb_build_git_sha = "3c27a3dde0993210c5cc30d99717093f7537916f";
static const std::string rocksdb_build_git_tag = "rocksdb_build_git_tag:v9.7.4";
#define HAS_GIT_CHANGES 0
#if HAS_GIT_CHANGES == 0
// If HAS_GIT_CHANGES is 0, the GIT date is used.
// Use the time the branch/tag was last modified
static const std::string rocksdb_build_date = "rocksdb_build_date:2024-03-11 11:26:24";
static const std::string rocksdb_build_date = "rocksdb_build_date:2024-11-01 15:32:35";
#else
// If HAS_GIT_CHANGES is > 0, the branch/tag has modifications.
// Use the time the build was created.
static const std::string rocksdb_build_date = "rocksdb_build_date:2024-03-11 11:26:24";
static const std::string rocksdb_build_date = "rocksdb_build_date:2024-11-01 15:32:35";
#endif

std::unordered_map<std::string, ROCKSDB_NAMESPACE::RegistrarFunc> ROCKSDB_NAMESPACE::ObjectRegistry::builtins_ = {};
Expand Down
2 changes: 1 addition & 1 deletion librocksdb-sys/rocksdb
Submodule rocksdb updated 174 files
6 changes: 5 additions & 1 deletion src/compaction_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,11 @@ fn test_filter(level: u32, key: &[u8], value: &[u8]) -> Decision {
fn compaction_filter_test() {
use crate::{Options, DB};

let path = "_rust_rocksdb_filter_test";
let tempdir = tempfile::Builder::new()
.prefix("_rust_rocksdb_filter_test")
.tempdir()
.expect("Failed to create temporary path for the _rust_rocksdb_filter_test");
let path = tempdir.path();
let mut opts = Options::default();
opts.create_if_missing(true);
opts.set_compaction_filter("test", test_filter);
Expand Down
6 changes: 5 additions & 1 deletion src/compaction_filter_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ mod tests {

#[test]
fn compaction_filter_factory_test() {
let path = "_rust_rocksdb_filter_factory_test";
let tempdir = tempfile::Builder::new()
.prefix("_rust_rocksdb_filter_factory_test")
.tempdir()
.expect("Failed to create temporary path for the _rust_rocksdb_filter_factory_test.");
let path = tempdir.path();
let mut opts = Options::default();
opts.create_if_missing(true);
opts.set_compaction_filter_factory(TestFactory(CString::new("TestFactory").unwrap()));
Expand Down
18 changes: 17 additions & 1 deletion src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2543,6 +2543,19 @@ impl<T: ThreadMode, D: DBInner> DBCommon<T, D> {
}
}
}

/// Returns the DB identity. This is typically ASCII bytes, but that is not guaranteed.
pub fn get_db_identity(&self) -> Result<Vec<u8>, Error> {
unsafe {
let mut length: usize = 0;
let identity_ptr = ffi::rocksdb_get_db_identity(self.inner.inner(), &mut length);
let identity_vec = raw_data(identity_ptr, length);
ffi::rocksdb_free(identity_ptr as *mut c_void);
// In RocksDB: get_db_identity copies a std::string so it should not fail, but
// the API allows it to be overridden, so it might
identity_vec.ok_or_else(|| Error::new("get_db_identity returned NULL".to_string()))
}
}
}

impl<I: DBInner> DBCommon<SingleThreaded, I> {
Expand Down Expand Up @@ -2573,8 +2586,11 @@ impl<I: DBInner> DBCommon<SingleThreaded, I> {
impl<I: DBInner> DBCommon<MultiThreaded, I> {
/// Creates column family with given name and options
pub fn create_cf<N: AsRef<str>>(&self, name: N, opts: &Options) -> Result<(), Error> {
// Note that we acquire the cfs lock before inserting: otherwise we might race
// another caller who observed the handle as missing.
let mut cfs = self.cfs.cfs.write().unwrap();
let inner = self.create_inner_cf_handle(name.as_ref(), opts)?;
self.cfs.cfs.write().unwrap().insert(
cfs.insert(
name.as_ref().to_string(),
Arc::new(UnboundColumnFamily { inner }),
);
Expand Down
36 changes: 30 additions & 6 deletions src/db_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ pub type DBRawIterator<'a> = DBRawIteratorWithThreadMode<'a, DB>;
/// ```
/// use rocksdb::{DB, Options};
///
/// let path = "_path_for_rocksdb_storage4";
/// let tempdir = tempfile::Builder::new()
/// .prefix("_path_for_rocksdb_storage4")
/// .tempdir()
/// .expect("Failed to create temporary path for the _path_for_rocksdb_storage4.");
/// let path = tempdir.path();
/// {
/// let db = DB::open_default(path).unwrap();
/// let mut iter = db.raw_iterator();
Expand Down Expand Up @@ -145,7 +149,11 @@ impl<'a, D: DBAccess> DBRawIteratorWithThreadMode<'a, D> {
/// ```rust
/// use rocksdb::{DB, Options};
///
/// let path = "_path_for_rocksdb_storage5";
/// let tempdir = tempfile::Builder::new()
/// .prefix("_path_for_rocksdb_storage5")
/// .tempdir()
/// .expect("Failed to create temporary path for the _path_for_rocksdb_storage5.");
/// let path = tempdir.path();
/// {
/// let db = DB::open_default(path).unwrap();
/// let mut iter = db.raw_iterator();
Expand Down Expand Up @@ -182,7 +190,11 @@ impl<'a, D: DBAccess> DBRawIteratorWithThreadMode<'a, D> {
/// ```rust
/// use rocksdb::{DB, Options};
///
/// let path = "_path_for_rocksdb_storage6";
/// let tempdir = tempfile::Builder::new()
/// .prefix("_path_for_rocksdb_storage6")
/// .tempdir()
/// .expect("Failed to create temporary path for the _path_for_rocksdb_storage6.");
/// let path = tempdir.path();
/// {
/// let db = DB::open_default(path).unwrap();
/// let mut iter = db.raw_iterator();
Expand Down Expand Up @@ -222,7 +234,11 @@ impl<'a, D: DBAccess> DBRawIteratorWithThreadMode<'a, D> {
/// ```rust
/// use rocksdb::{DB, Options};
///
/// let path = "_path_for_rocksdb_storage7";
/// let tempdir = tempfile::Builder::new()
/// .prefix("_path_for_rocksdb_storage7")
/// .tempdir()
/// .expect("Failed to create temporary path for the _path_for_rocksdb_storage7.");
/// let path = tempdir.path();
/// {
/// let db = DB::open_default(path).unwrap();
/// let mut iter = db.raw_iterator();
Expand Down Expand Up @@ -261,7 +277,11 @@ impl<'a, D: DBAccess> DBRawIteratorWithThreadMode<'a, D> {
/// ```rust
/// use rocksdb::{DB, Options};
///
/// let path = "_path_for_rocksdb_storage8";
/// let tempdir = tempfile::Builder::new()
/// .prefix("_path_for_rocksdb_storage8")
/// .tempdir()
/// .expect("Failed to create temporary path for the _path_for_rocksdb_storage8.");
/// let path = tempdir.path();
/// {
/// let db = DB::open_default(path).unwrap();
/// let mut iter = db.raw_iterator();
Expand Down Expand Up @@ -395,7 +415,11 @@ pub type DBIterator<'a> = DBIteratorWithThreadMode<'a, DB>;
/// ```
/// use rocksdb::{DB, Direction, IteratorMode, Options};
///
/// let path = "_path_for_rocksdb_storage2";
/// let tempdir = tempfile::Builder::new()
/// .prefix("_path_for_rocksdb_storage2")
/// .tempdir()
/// .expect("Failed to create temporary path for the _path_for_rocksdb_storage2.");
/// let path = tempdir.path();
/// {
/// let db = DB::open_default(path).unwrap();
/// let mut iter = db.iterator(IteratorMode::Start); // Always iterates forward
Expand Down
Loading

0 comments on commit 669ff78

Please sign in to comment.