common_meta/ddl/create_logical_tables/
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 crate::ddl::create_logical_tables::CreateLogicalTablesProcedure;
16use crate::error::Result;
17use crate::key::table_route::TableRouteValue;
18
19impl CreateLogicalTablesProcedure {
20    pub(crate) async fn fill_physical_table_info(&mut self) -> Result<()> {
21        let physical_region_numbers = self
22            .context
23            .table_metadata_manager
24            .table_route_manager()
25            .get_physical_table_route(self.data.physical_table_id)
26            .await
27            .map(|(_, route)| TableRouteValue::Physical(route).region_numbers())?;
28
29        self.data.physical_region_numbers = physical_region_numbers;
30
31        Ok(())
32    }
33
34    pub(crate) async fn allocate_table_ids(&mut self) -> Result<()> {
35        for (task, table_id) in self
36            .data
37            .tasks
38            .iter_mut()
39            .zip(self.data.table_ids_already_exists.iter())
40        {
41            let table_id = if let Some(table_id) = table_id {
42                *table_id
43            } else {
44                self.context
45                    .table_metadata_allocator
46                    .allocate_table_id(&task.create_table.table_id)
47                    .await?
48            };
49            task.set_table_id(table_id);
50
51            // sort columns in task
52            task.sort_columns();
53        }
54
55        Ok(())
56    }
57}