Skip to content

Commit

Permalink
[store] refactor: SledTree::open need not to be async
Browse files Browse the repository at this point in the history
  • Loading branch information
drmingdrmer committed Sep 11, 2021
1 parent 607985a commit 71e0608
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion store/src/meta_service/raft_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl RaftLog {
config: &configs::Config,
) -> common_exception::Result<RaftLog> {
let tree_name = config.tree_name(TREE_RAFT_LOG);
let inner = SledTree::open(db, &tree_name, config.meta_sync()).await?;
let inner = SledTree::open(db, &tree_name, config.meta_sync())?;
let rl = RaftLog { inner };
Ok(rl)
}
Expand Down
2 changes: 1 addition & 1 deletion store/src/meta_service/raft_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl RaftState {
create: Option<()>,
) -> common_exception::Result<RaftState> {
let tree_name = config.tree_name(TREE_RAFT_STATE);
let inner = SledTree::open(db, &tree_name, config.meta_sync()).await?;
let inner = SledTree::open(db, &tree_name, config.meta_sync())?;

let state = inner.key_space::<RaftStateKV>();
let curr_id = state.get(&RaftStateKey::Id)?.map(NodeId::from);
Expand Down
2 changes: 1 addition & 1 deletion store/src/meta_service/sled_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub struct SledTree {

impl SledTree {
/// Open SledTree
pub async fn open<N: AsRef<[u8]> + Display>(
pub fn open<N: AsRef<[u8]> + Display>(
db: &sled::Db,
tree_name: N,
sync: bool,
Expand Down
56 changes: 28 additions & 28 deletions store/src/meta_service/sled_tree_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async fn test_sledtree_open() -> anyhow::Result<()> {

let tc = new_sled_test_context();
let db = &tc.db;
SledTree::open(db, tc.config.tree_name("foo"), true).await?;
SledTree::open(db, tc.config.tree_name("foo"), true)?;

Ok(())
}
Expand All @@ -50,7 +50,7 @@ async fn test_sledtree_append() -> anyhow::Result<()> {

let tc = new_sled_test_context();
let db = &tc.db;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true).await?;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true)?;

let logs: Vec<(LogIndex, Entry<LogEntry>)> = vec![
(8, Entry {
Expand Down Expand Up @@ -109,7 +109,7 @@ async fn test_sledtree_append_values_and_range_get() -> anyhow::Result<()> {

let tc = new_sled_test_context();
let db = &tc.db;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true).await?;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true)?;

let logs: Vec<Entry<LogEntry>> = vec![
Entry {
Expand Down Expand Up @@ -185,7 +185,7 @@ async fn test_sledtree_range_keys() -> anyhow::Result<()> {

let tc = new_sled_test_context();
let db = &tc.db;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true).await?;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true)?;

let logs: Vec<Entry<LogEntry>> = vec![
Entry {
Expand Down Expand Up @@ -238,7 +238,7 @@ async fn test_sledtree_range_kvs() -> anyhow::Result<()> {

let tc = new_sled_test_context();
let db = &tc.db;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true).await?;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true)?;

let logs: Vec<Entry<LogEntry>> = vec![
Entry {
Expand Down Expand Up @@ -274,7 +274,7 @@ async fn test_sledtree_range() -> anyhow::Result<()> {

let tc = new_sled_test_context();
let db = &tc.db;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true).await?;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true)?;

let logs: Vec<Entry<LogEntry>> = vec![
Entry {
Expand Down Expand Up @@ -366,7 +366,7 @@ async fn test_sledtree_scan_prefix() -> anyhow::Result<()> {

let tc = new_sled_test_context();
let db = &tc.db;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true).await?;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true)?;

let files: Vec<(String, String)> = vec![
("a".to_string(), "x".to_string()),
Expand All @@ -391,7 +391,7 @@ async fn test_sledtree_insert() -> anyhow::Result<()> {

let tc = new_sled_test_context();
let db = &tc.db;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true).await?;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true)?;

assert!(tree.get::<sled_key_space::Logs>(&5)?.is_none());

Expand Down Expand Up @@ -456,7 +456,7 @@ async fn test_sledtree_contains_key() -> anyhow::Result<()> {

let tc = new_sled_test_context();
let db = &tc.db;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true).await?;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true)?;

assert!(tree.get::<sled_key_space::Logs>(&5)?.is_none());

Expand Down Expand Up @@ -496,7 +496,7 @@ async fn test_sledtree_update_and_fetch() -> anyhow::Result<()> {

let tc = new_sled_test_context();
let db = &tc.db;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true).await?;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true)?;

let v = tree
.update_and_fetch::<sled_key_space::Files, _>(&"foo".to_string(), |v| {
Expand All @@ -522,7 +522,7 @@ async fn test_sledtree_get() -> anyhow::Result<()> {

let tc = new_sled_test_context();
let db = &tc.db;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true).await?;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true)?;

assert!(tree.get::<sled_key_space::Logs>(&5)?.is_none());

Expand Down Expand Up @@ -566,7 +566,7 @@ async fn test_sledtree_last() -> anyhow::Result<()> {

let tc = new_sled_test_context();
let db = &tc.db;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true).await?;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true)?;

assert!(tree.last::<sled_key_space::Logs>()?.is_none());

Expand Down Expand Up @@ -620,7 +620,7 @@ async fn test_sledtree_remove() -> anyhow::Result<()> {

let tc = new_sled_test_context();
let db = &tc.db;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true).await?;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true)?;

let logs: Vec<Entry<LogEntry>> = vec![
Entry {
Expand Down Expand Up @@ -661,7 +661,7 @@ async fn test_sledtree_range_remove() -> anyhow::Result<()> {

let tc = new_sled_test_context();
let db = &tc.db;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true).await?;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true)?;

let logs: Vec<Entry<LogEntry>> = vec![
Entry {
Expand Down Expand Up @@ -742,7 +742,7 @@ async fn test_sledtree_multi_types() -> anyhow::Result<()> {

let tc = new_sled_test_context();
let db = &tc.db;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true).await?;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true)?;

let logs: Vec<Entry<LogEntry>> = vec![
Entry {
Expand Down Expand Up @@ -811,7 +811,7 @@ async fn test_as_append() -> anyhow::Result<()> {

let tc = new_sled_test_context();
let db = &tc.db;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true).await?;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true)?;
let log_tree = tree.key_space::<sled_key_space::Logs>();

let logs: Vec<(LogIndex, Entry<LogEntry>)> = vec![
Expand Down Expand Up @@ -871,7 +871,7 @@ async fn test_as_append_values_and_range_get() -> anyhow::Result<()> {

let tc = new_sled_test_context();
let db = &tc.db;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true).await?;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true)?;
let log_tree = tree.key_space::<sled_key_space::Logs>();

let logs: Vec<Entry<LogEntry>> = vec![
Expand Down Expand Up @@ -948,7 +948,7 @@ async fn test_as_range_keys() -> anyhow::Result<()> {

let tc = new_sled_test_context();
let db = &tc.db;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true).await?;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true)?;
let log_tree = tree.key_space::<sled_key_space::Logs>();

let logs: Vec<Entry<LogEntry>> = vec![
Expand Down Expand Up @@ -1002,7 +1002,7 @@ async fn test_as_range_kvs() -> anyhow::Result<()> {

let tc = new_sled_test_context();
let db = &tc.db;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true).await?;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true)?;
let log_tree = tree.key_space::<sled_key_space::Logs>();

let logs: Vec<Entry<LogEntry>> = vec![
Expand Down Expand Up @@ -1035,7 +1035,7 @@ async fn test_as_scan_prefix() -> anyhow::Result<()> {

let tc = new_sled_test_context();
let db = &tc.db;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true).await?;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true)?;
let file_tree = tree.key_space::<sled_key_space::Files>();
let kv_tree = tree.key_space::<sled_key_space::GenericKV>();

Expand Down Expand Up @@ -1079,7 +1079,7 @@ async fn test_as_insert() -> anyhow::Result<()> {

let tc = new_sled_test_context();
let db = &tc.db;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true).await?;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true)?;
let log_tree = tree.key_space::<sled_key_space::Logs>();

assert_eq!(None, log_tree.get(&5)?);
Expand Down Expand Up @@ -1141,7 +1141,7 @@ async fn test_as_contains_key() -> anyhow::Result<()> {

let tc = new_sled_test_context();
let db = &tc.db;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true).await?;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true)?;
let log_tree = tree.key_space::<sled_key_space::Logs>();

assert_eq!(None, log_tree.get(&5)?);
Expand Down Expand Up @@ -1182,7 +1182,7 @@ async fn test_as_update_and_fetch() -> anyhow::Result<()> {

let tc = new_sled_test_context();
let db = &tc.db;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true).await?;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true)?;
let file_tree = tree.key_space::<sled_key_space::Files>();

let v = file_tree
Expand All @@ -1205,7 +1205,7 @@ async fn test_as_get() -> anyhow::Result<()> {

let tc = new_sled_test_context();
let db = &tc.db;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true).await?;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true)?;
let log_tree = tree.key_space::<sled_key_space::Logs>();

assert_eq!(None, log_tree.get(&5)?);
Expand Down Expand Up @@ -1246,7 +1246,7 @@ async fn test_as_last() -> anyhow::Result<()> {

let tc = new_sled_test_context();
let db = &tc.db;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true).await?;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true)?;
let log_tree = tree.key_space::<sled_key_space::Logs>();

assert_eq!(None, log_tree.last()?);
Expand Down Expand Up @@ -1282,7 +1282,7 @@ async fn test_as_remove() -> anyhow::Result<()> {

let tc = new_sled_test_context();
let db = &tc.db;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true).await?;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true)?;
let log_tree = tree.key_space::<sled_key_space::Logs>();

let logs: Vec<Entry<LogEntry>> = vec![
Expand Down Expand Up @@ -1316,7 +1316,7 @@ async fn test_as_range_remove() -> anyhow::Result<()> {

let tc = new_sled_test_context();
let db = &tc.db;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true).await?;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true)?;
let log_tree = tree.key_space::<sled_key_space::Logs>();

let logs: Vec<Entry<LogEntry>> = vec![
Expand Down Expand Up @@ -1379,7 +1379,7 @@ async fn test_as_multi_types() -> anyhow::Result<()> {

let tc = new_sled_test_context();
let db = &tc.db;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true).await?;
let tree = SledTree::open(db, tc.config.tree_name("foo"), true)?;
let log_tree = tree.key_space::<sled_key_space::Logs>();
let sm_meta = tree.key_space::<StateMachineMeta>();

Expand Down
2 changes: 1 addition & 1 deletion store/src/meta_service/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ impl StateMachine {

let tree_name = StateMachine::tree_name(config, sm_id);

let sm_tree = SledTree::open(&db, &tree_name, config.meta_sync()).await?;
let sm_tree = SledTree::open(&db, &tree_name, config.meta_sync())?;

let sm = StateMachine {
config: config.clone(),
Expand Down

0 comments on commit 71e0608

Please sign in to comment.