diff --git a/.env.example b/.env.example index 259947f431a1..1a0a02c6f503 100644 --- a/.env.example +++ b/.env.example @@ -114,3 +114,7 @@ OPENDAL_WASABI_BUCKET= OPENDAL_WASABI_ENDPOINT= OPENDAL_WASABI_ACCESS_KEY_ID= OPENDAL_WASABI_SECRET_ACCESS_KEY= +# redb +OPENDAL_REDB_TEST=false +OPENDAL_REDB_DATADIR=/path/to/database +OPENDAL_REDB_TABLE=redb-table diff --git a/.github/workflows/service_test_redb.yml b/.github/workflows/service_test_redb.yml index 315cf745338f..910bc3482ea0 100644 --- a/.github/workflows/service_test_redb.yml +++ b/.github/workflows/service_test_redb.yml @@ -43,6 +43,12 @@ jobs: - uses: actions/checkout@v3 - name: Setup Rust toolchain uses: ./.github/actions/setup + - name: Prepare for tests + shell: bash + working-directory: core + run: mkdir -p $OPENDAL_REDB_DATADIR + env: + OPENDAL_REDB_DATADIR: /tmp/opendal/redb/ - name: Test shell: bash working-directory: core diff --git a/core/src/services/redb/backend.rs b/core/src/services/redb/backend.rs index 3acdca60c2f0..0241075f3bb1 100644 --- a/core/src/services/redb/backend.rs +++ b/core/src/services/redb/backend.rs @@ -68,6 +68,7 @@ impl Builder for RedbBuilder { let mut builder = RedbBuilder::default(); map.get("datadir").map(|v| builder.datadir(v)); + map.get("table").map(|v| builder.table(v)); map.get("root").map(|v| builder.root(v)); builder @@ -146,8 +147,9 @@ impl kv::Adapter for Adapter { return Err(Error::new(ErrorKind::Unexpected, "error from redb").set_source(e)); } }; - - let table_define: redb::TableDefinition<&str, &[u8]> = redb::TableDefinition::new(&self.table); + + let table_define: redb::TableDefinition<&str, &[u8]> = + redb::TableDefinition::new(&self.table); let table = match read_txn.open_table(table_define) { Ok(table) => table, @@ -176,7 +178,8 @@ impl kv::Adapter for Adapter { } }; - let table_define: redb::TableDefinition<&str, &[u8]> = redb::TableDefinition::new(&self.table); + let table_define: redb::TableDefinition<&str, &[u8]> = + redb::TableDefinition::new(&self.table); { let mut table = match write_txn.open_table(table_define) { @@ -185,17 +188,16 @@ impl kv::Adapter for Adapter { return Err(Error::new(ErrorKind::Unexpected, "error from redb").set_source(e)); } }; - + if let Err(e) = table.insert(path, value) { return Err(Error::new(ErrorKind::Unexpected, "error from redb").set_source(e)); }; } - let result = match write_txn.commit() { + match write_txn.commit() { Ok(()) => Ok(()), Err(e) => Err(Error::new(ErrorKind::Unexpected, "error from redb").set_source(e)), - }; - result + } } async fn delete(&self, path: &str) -> Result<()> { @@ -210,7 +212,8 @@ impl kv::Adapter for Adapter { } }; - let table_define: redb::TableDefinition<&str, &[u8]> = redb::TableDefinition::new(&self.table); + let table_define: redb::TableDefinition<&str, &[u8]> = + redb::TableDefinition::new(&self.table); { let mut table = match write_txn.open_table(table_define) { @@ -219,16 +222,15 @@ impl kv::Adapter for Adapter { return Err(Error::new(ErrorKind::Unexpected, "error from redb").set_source(e)); } }; - + if let Err(e) = table.remove(path) { return Err(Error::new(ErrorKind::Unexpected, "error from redb").set_source(e)); }; } - let result = match write_txn.commit() { + match write_txn.commit() { Ok(()) => Ok(()), Err(e) => Err(Error::new(ErrorKind::Unexpected, "error from redb").set_source(e)), - }; - result + } } -} \ No newline at end of file +}