Skip to content

Commit

Permalink
feat(services/redb): fix code
Browse files Browse the repository at this point in the history
Signed-off-by: owl <[email protected]>
  • Loading branch information
oowl committed Jun 24, 2023
1 parent 660d3df commit 4c228ef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,7 @@ OPENDAL_WASABI_BUCKET=<bucket>
OPENDAL_WASABI_ENDPOINT=<endpoint>
OPENDAL_WASABI_ACCESS_KEY_ID=<ak>
OPENDAL_WASABI_SECRET_ACCESS_KEY=<sk>
# redb
OPENDAL_REDB_TEST=false
OPENDAL_REDB_DATADIR=/path/to/database
OPENDAL_REDB_TABLE=redb-table
18 changes: 11 additions & 7 deletions core/src/services/redb/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand All @@ -185,7 +188,7 @@ 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));
};
Expand All @@ -210,7 +213,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) {
Expand All @@ -219,7 +223,7 @@ 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));
};
Expand All @@ -231,4 +235,4 @@ impl kv::Adapter for Adapter {
};
result
}
}
}

0 comments on commit 4c228ef

Please sign in to comment.