You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: open.rs
    path of file: ./repos/incubator-horaedb/src/analytic_engine/src/instance
    
    the code of the file until where you have to start completion: // 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.

//! Open logic of instance

use std::{
    collections::HashMap,
    sync::{Arc, RwLock},
};

use common_types::table::ShardId;
use logger::{error, info};
use object_store::ObjectStoreRef;
use snafu::ResultExt;
use table_engine::{engine::TableDef, table::TableId};
use wal::manager::WalManagerRef;

use crate::{
    compaction::{
        runner::{local_runner::LocalCompactionRunner, CompactionRunnerPtr, CompactionRunnerRef},
        scheduler::SchedulerImpl,
    },
    context::OpenContext,
    engine,
    instance::{
        engine::{OpenManifest, OpenTablesOfShard, ReadMeta
    
    async fn recover_table_datas(&mut self) -> Result<()> {
        info!(
            "ShardOpener recover table datas begin, shard_id:{}",
            self.shard_id
        );

        // Replay wal logs of tables.
        let mut replay_table_datas = Vec::with_capacity(self.stages.len());
        for (table_id, stage) in self.stages.iter_mut() {
            match stage {
                // Only do the wal recovery work in `RecoverTableData` state.
                TableOpenStage::RecoverTableData(ctx) => {
                    replay_table_datas.push(ctx.table_data.clone());
                }
                // Table was found opened, or failed in meta recovery stage.
                TableOpenStage::Failed(_) | TableOpenStage::Success(_) => {}
                TableOpenStage::RecoverTableMeta(_) => {
                    return OpenTablesOfShard {
                        msg: format!(
                            "unexpected stage, stage:{stage:?}, table_id:{table_id}, shard_id:{}",
                            self.shard_id
                        ),
                    }
                    .fail();
                }
            }
        }

        if replay_table_datas.is_empty() {
            info!(
                "ShardOpener recover empty table datas finish, shard_id:{}",
                self.shard_id
            );

            return Ok(());
        }

        let replay_mode = match self.recover_mode {
            RecoverMode::TableBased => ReplayMode::TableBased,
            RecoverMode::ShardBased => ReplayMode::RegionBased,
        };
        let mut wal_replayer = WalReplayer::new(
            &replay_table_datas,
            self.shard_id,
            self.wal_manager.clone(),
            self.wal_replay_batch_size,
            self.flusher.clone(),
            self.max_retry_flush_limit,
            replay_mode,
        );
        let mut table_results = wal_replayer.replay().await?;

        // Process the replay results.
        for table_data in replay_table_datas {
            let table_id = table_data.id;
            // Each `table_data` has its related `stage` in `stages`, impossible to panic
            // here.
            let stage = self.stages.get_mut(&table_id).unwrap();
            let failed_table_opt = table_results.remove(&table_id);

            match (&stage, failed_table_opt) {
                (TableOpenStage::RecoverTableData(ctx), None) => {
                    let space_table = SpaceAndTable::new(ctx.space.clone(), ctx.table_data.clone());
                    *stage = TableOpenStage::Success(Some(space_table));
                }

                (TableOpenStage::RecoverTableData(_), Some(e)) => {
                    error!("ShardOpener replay wals of single table failed, table:{}, table_id:{}, shard_id:{}, err:{e}", table_data.name, table_data.id, self.shard_id);
                    *stage = TableOpenStage::Failed(e);
                }

                (other_stage, _) => {
                    return OpenTablesOfShard {
                        msg: format!("unexpected stage, stage:{other_stage:?}, table_id:{table_id}, shard_id:{}", self.shard_id),
                    }.fail();
                }
            }
        }

        info!(
            "ShardOpener recover table datas finish, shard_id:{}",
            self.shard_id
        );
        Ok(())
    }