This is an automated email from the ASF dual-hosted git repository.
Xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git
The following commit(s) were added to refs/heads/main by this push:
new 0feb9edce3 chore(services/redb): upgrade redb to 5.0 (#8759)
0feb9edce3 is described below
commit 0feb9edce33ec63161f7e579bd5c40f9d33146d6
Author: Xuanwo <[email protected]>
AuthorDate: Mon Nov 23 07:51:48 2026 +0800
chore(services/redb): upgrade redb to 5.0 (#8759)
redb 5 removes the inherent `get()` and `range()` methods of
`ReadOnlyTable`, makes `Range` borrow the table, and adds `range_owned()`
for iterators that keep the read transaction alive. Read the table
through `ReadableTable` and hold `OwnedRange` in the lister so listing
can continue after `scan()` returns.
`TableDefinition<&str, &[u8]>` keeps its encoding in redb 5, so existing
databases need no data migration.
Split out of #8705.
---
core/Cargo.lock | 7 ++-
core/core/src/docs/upgrade.md | 16 ++++++
core/services/redb/Cargo.toml | 3 +-
core/services/redb/src/core.rs | 9 ++-
core/services/redb/src/lister.rs | 4 +-
core/services/redb/tests/shared_database.rs | 88 +++++++++++++++++++++++++++++
6 files changed, 119 insertions(+), 8 deletions(-)
diff --git a/core/Cargo.lock b/core/Cargo.lock
index 7e65f333ef..b78fe220b4 100644
--- a/core/Cargo.lock
+++ b/core/Cargo.lock
@@ -8546,8 +8546,9 @@ name = "opendal-service-redb"
version = "0.59.5"
dependencies = [
"opendal-core",
- "redb 4.1.0",
+ "redb 5.0.0",
"serde",
+ "tempfile",
"tokio",
]
@@ -10280,9 +10281,9 @@ dependencies = [
[[package]]
name = "redb"
-version = "4.1.0"
+version = "5.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8e925444704b5f17d32bf42f5b6e2df050bceebc3dcd6e71cc73dafe8092e839"
+checksum = "11175cc688ba1b9d3cec4fe582fd82cb97e2a82e28ccc8101b7b8030a8003280"
dependencies = [
"libc",
]
diff --git a/core/core/src/docs/upgrade.md b/core/core/src/docs/upgrade.md
index 166d494737..cece716d7c 100644
--- a/core/core/src/docs/upgrade.md
+++ b/core/core/src/docs/upgrade.md
@@ -102,6 +102,22 @@ available bytes. Keep using `oio::Read::read` for an exact
bounded range.
`raw::ConcurrentTasks::create_task` has been removed. Submit inputs with
`execute()` and collect outputs in submission order with `next()`. These
methods keep task ownership, completion accounting, and retry handling inside
the queue. If code needs input data after successful completion, include that
data in the factory's output type.
+## Services
+
+### Redb requires `redb` 5
+
+`RedbBuilder::database` takes an `Arc<redb::Database>`, so the `redb` version
OpenDAL builds
+with appears in your dependency graph. `opendal` now depends on `redb` 5.
Upgrade your own
+`redb` dependency to `5.x` when you pass an externally created database to the
builder.
+
+`redb` 5 changed the file locking protocol. Open the same database file with
matching `redb` 5.x
+versions in every process, because `redb` 5 does not reliably detect a `redb`
4.2 or earlier
+process that keeps the file open.
+
+Existing databases need no data migration. `redb` 5 changed the encoding of
`Option<&str>`,
+`Option<String>`, `Option<bool>`, and `Option<char>` only, and the Redb
service stores entries
+in a `TableDefinition<&str, &[u8]>` table.
+
# Upgrade to v0.59
## Public API
diff --git a/core/services/redb/Cargo.toml b/core/services/redb/Cargo.toml
index ad8ae4383a..cd03fd3eec 100644
--- a/core/services/redb/Cargo.toml
+++ b/core/services/redb/Cargo.toml
@@ -33,8 +33,9 @@ all-features = true
[dependencies]
opendal-core = { path = "../../core", version = "0.59.5", default-features =
false }
-redb = { version = "4" }
+redb = { version = "5" }
serde = { workspace = true, features = ["derive"] }
[dev-dependencies]
+tempfile = "3"
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
diff --git a/core/services/redb/src/core.rs b/core/services/redb/src/core.rs
index f6f2fd0866..af9995b5ee 100644
--- a/core/services/redb/src/core.rs
+++ b/core/services/redb/src/core.rs
@@ -20,6 +20,7 @@ use std::sync::Arc;
use opendal_core::*;
use redb::ReadableDatabase;
+use redb::ReadableTable;
#[derive(Clone)]
pub struct RedbCore {
@@ -38,14 +39,18 @@ impl Debug for RedbCore {
}
impl RedbCore {
- pub fn scan(&self, prefix: &str) -> Result<redb::Range<'static, &'static
str, &'static [u8]>> {
+ /// Scan all keys starting with `prefix`.
+ ///
+ /// The returned [`redb::OwnedRange`] keeps the read transaction alive, so
callers can
+ /// keep iterating after this method returns and drops its own transaction
handle.
+ pub fn scan(&self, prefix: &str) -> Result<redb::OwnedRange<&'static str,
&'static [u8]>> {
let read_txn = self.db.begin_read().map_err(parse_transaction_error)?;
let table_define: redb::TableDefinition<&str, &[u8]> =
redb::TableDefinition::new(&self.table);
let table = read_txn
.open_table(table_define)
.map_err(parse_table_error)?;
- table.range(prefix..).map_err(parse_storage_error)
+ table.range_owned(prefix..).map_err(parse_storage_error)
}
pub fn get(&self, path: &str) -> Result<Option<Buffer>> {
diff --git a/core/services/redb/src/lister.rs b/core/services/redb/src/lister.rs
index a4f6441526..79d7c3cc4f 100644
--- a/core/services/redb/src/lister.rs
+++ b/core/services/redb/src/lister.rs
@@ -23,14 +23,14 @@ use super::core::parse_storage_error;
pub struct RedbLister {
root: String,
prefix: String,
- range: Option<redb::Range<'static, &'static str, &'static [u8]>>,
+ range: Option<redb::OwnedRange<&'static str, &'static [u8]>>,
}
impl RedbLister {
pub fn new(
root: String,
prefix: String,
- range: redb::Range<'static, &'static str, &'static [u8]>,
+ range: redb::OwnedRange<&'static str, &'static [u8]>,
) -> Self {
Self {
root,
diff --git a/core/services/redb/tests/shared_database.rs
b/core/services/redb/tests/shared_database.rs
new file mode 100644
index 0000000000..be6e32abf2
--- /dev/null
+++ b/core/services/redb/tests/shared_database.rs
@@ -0,0 +1,88 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::sync::Arc;
+
+use opendal_core::Operator;
+use opendal_service_redb::Redb;
+
+const TABLE: redb::TableDefinition<&str, &[u8]> =
redb::TableDefinition::new("opendal");
+
+#[tokio::test]
+async fn shared_database_supports_write_read_and_list() {
+ let dir = tempfile::tempdir().unwrap();
+ let db =
Arc::new(redb::Database::create(dir.path().join("opendal.redb")).unwrap());
+
+ let op = Operator::new(
+ Redb::default()
+ .database(db.clone())
+ .table("opendal")
+ .root("/"),
+ )
+ .unwrap();
+
+ op.write("dir/a", "a").await.unwrap();
+ op.write("dir/b", "bb").await.unwrap();
+ op.write("other/c", "ccc").await.unwrap();
+
+ assert_eq!(op.read("dir/b").await.unwrap().to_vec(), b"bb".to_vec());
+ assert_eq!(list_paths(&op, "dir/").await, vec!["dir/a", "dir/b"]);
+
+ let another =
Operator::new(Redb::default().database(db).table("another").root("/")).unwrap();
+ another.write("dir/a", "another table").await.unwrap();
+
+ assert_eq!(
+ another.read("dir/a").await.unwrap().to_vec(),
+ b"another table".to_vec()
+ );
+ assert_eq!(list_paths(&op, "dir/").await, vec!["dir/a", "dir/b"]);
+}
+
+#[tokio::test]
+async fn rows_written_through_redb_are_listed_and_readable() {
+ let dir = tempfile::tempdir().unwrap();
+ let db =
Arc::new(redb::Database::create(dir.path().join("opendal.redb")).unwrap());
+
+ let write_txn = db.begin_write().unwrap();
+ {
+ let mut table = write_txn.open_table(TABLE).unwrap();
+ table
+ .insert("dir/external", b"external".as_slice())
+ .unwrap();
+ }
+ write_txn.commit().unwrap();
+
+ let op =
Operator::new(Redb::default().database(db).table("opendal").root("/")).unwrap();
+
+ assert_eq!(
+ op.read("dir/external").await.unwrap().to_vec(),
+ b"external".to_vec()
+ );
+ assert_eq!(list_paths(&op, "dir/").await, vec!["dir/external"]);
+}
+
+async fn list_paths(op: &Operator, path: &str) -> Vec<String> {
+ let mut paths = op
+ .list(path)
+ .await
+ .unwrap()
+ .into_iter()
+ .map(|entry| entry.path().to_string())
+ .collect::<Vec<_>>();
+ paths.sort();
+ paths
+}