common_meta/ddl/drop_table/
metadata.rs

1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use common_catalog::format_full_table_name;
16use snafu::OptionExt;
17use store_api::metric_engine_consts::METRIC_ENGINE_NAME;
18
19use crate::ddl::drop_table::DropTableProcedure;
20use crate::ddl::utils::extract_region_wal_options;
21use crate::error::{self, Result};
22
23impl DropTableProcedure {
24    /// Fetches the table info and physical table route.
25    pub(crate) async fn fill_table_metadata(&mut self) -> Result<()> {
26        let task = &self.data.task;
27        let (physical_table_id, physical_table_route_value) = self
28            .context
29            .table_metadata_manager
30            .table_route_manager()
31            .get_physical_table_route(task.table_id)
32            .await?;
33
34        if physical_table_id == self.data.table_id() {
35            let table_info_value = self
36                .context
37                .table_metadata_manager
38                .table_info_manager()
39                .get(task.table_id)
40                .await?
41                .with_context(|| error::TableInfoNotFoundSnafu {
42                    table: format_full_table_name(&task.catalog, &task.schema, &task.table),
43                })?
44                .into_inner();
45
46            let engine = table_info_value.table_info.meta.engine;
47            // rollback only if dropping the metric physical table fails
48            self.data.allow_rollback = engine.as_str() == METRIC_ENGINE_NAME;
49
50            // Deletes topic-region mapping if dropping physical table
51            let datanode_table_values = self
52                .context
53                .table_metadata_manager
54                .datanode_table_manager()
55                .regions(physical_table_id, &physical_table_route_value)
56                .await?;
57            self.data.region_wal_options = extract_region_wal_options(&datanode_table_values)?;
58        }
59
60        self.data.physical_region_routes = physical_table_route_value.region_routes;
61        self.data.physical_table_id = Some(physical_table_id);
62
63        Ok(())
64    }
65}