This is an automated email from the ASF dual-hosted git repository.

tanruixiang pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-horaedb.git


The following commit(s) were added to refs/heads/dev by this push:
     new bb4db609 chore: refactor for better readability (#1400)
bb4db609 is described below

commit bb4db609811939130067f0ab3ba9310950156b3f
Author: Jiacai Liu <[email protected]>
AuthorDate: Mon Dec 25 11:16:00 2023 +0800

    chore: refactor for better readability (#1400)
    
    ## Rationale
    Reduce two `match`to only one.
    
    ## Detailed Changes
    
    
    ## Test Plan
    CI
---
 analytic_engine/src/instance/open.rs | 51 ++++++++++++++----------------------
 1 file changed, 19 insertions(+), 32 deletions(-)

diff --git a/analytic_engine/src/instance/open.rs 
b/analytic_engine/src/instance/open.rs
index 8c840bf8..0f9ad18a 100644
--- a/analytic_engine/src/instance/open.rs
+++ b/analytic_engine/src/instance/open.rs
@@ -294,48 +294,38 @@ impl ShardOpener {
 
     /// Recover table meta data from manifest based on shard.
     async fn recover_table_metas(&mut self) -> Result<()> {
-        info!(
-            "ShardOpener recover table metas begin, shard_id:{}",
-            self.shard_id
-        );
+        let shard_id = self.shard_id;
+        let table_num = self.stages.len();
+        info!("ShardOpener recover table metas begin, shard_id:{shard_id}, 
table_num:{table_num}");
 
         for (table_id, state) in self.stages.iter_mut() {
             match state {
                 // Only do the meta recovery work in `RecoverTableMeta` state.
-                TableOpenStage::RecoverTableMeta(ctx) => {
-                    let result = match Self::recover_single_table_meta(
+                TableOpenStage::RecoverTableMeta(RecoverTableMetaContext { 
table_def, space }) => {
+                    match Self::recover_single_table_meta(
                         self.manifest.as_ref(),
-                        self.shard_id,
-                        &ctx.table_def,
+                        shard_id,
+                        table_def,
                     )
                     .await
+                    .map(|_| space.find_table_by_id(*table_id))
                     {
-                        Ok(()) => {
-                            let table_data = 
ctx.space.find_table_by_id(*table_id);
-                            Ok(table_data.map(|data| (data, 
ctx.space.clone())))
-                        }
-                        Err(e) => {
-                            error!("ShardOpener recover single table meta 
failed, table:{:?}, shard_id:{}, err:{e}", ctx.table_def, self.shard_id);
-                            Err(e)
-                        }
-                    };
-
-                    match result {
-                        Ok(Some((table_data, space))) => {
+                        Ok(Some(table_data)) => {
                             *state = 
TableOpenStage::RecoverTableData(RecoverTableDataContext {
                                 table_data,
-                                space,
-                            })
+                                space: space.clone(),
+                            });
                         }
                         Ok(None) => {
-                            error!(
-                                "ShardOpener trie to open a dropped table, 
table:{:?}, shard_id:{}",
-                                ctx.table_def, self.shard_id
-                            );
+                            error!("ShardOpener tried to open a dropped table, 
table:{table_def:?}, shard_id:{shard_id}");
+                            // TODO: is this an error?
                             *state = TableOpenStage::Success(None);
                         }
-                        Err(e) => *state = TableOpenStage::Failed(e),
-                    }
+                        Err(e) => {
+                            error!("ShardOpener recover single table meta 
failed, table:{table_def:?}, shard_id:{shard_id}, err:{e}");
+                            *state = TableOpenStage::Failed(e)
+                        }
+                    };
                 }
                 // Table was found to be opened in init stage.
                 TableOpenStage::Success(_) => {}
@@ -348,10 +338,7 @@ impl ShardOpener {
             }
         }
 
-        info!(
-            "ShardOpener recover table metas finish, shard_id:{}",
-            self.shard_id
-        );
+        info!("ShardOpener recover table metas finish, shard_id:{shard_id}, 
table_num:{table_num}",);
         Ok(())
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to