common_meta/ddl/alter_logical_tables/
table_cache_keys.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 table::metadata::RawTableInfo;
16use table::table_name::TableName;
17
18use crate::ddl::alter_logical_tables::AlterLogicalTablesProcedure;
19use crate::instruction::CacheIdent;
20
21impl AlterLogicalTablesProcedure {
22    pub(crate) fn build_table_cache_keys_to_invalidate(&self) -> Vec<CacheIdent> {
23        let mut cache_keys = self
24            .data
25            .table_info_values
26            .iter()
27            .flat_map(|table| {
28                vec![
29                    CacheIdent::TableId(table.table_info.ident.table_id),
30                    CacheIdent::TableName(extract_table_name(&table.table_info)),
31                ]
32            })
33            .collect::<Vec<_>>();
34        cache_keys.push(CacheIdent::TableId(self.data.physical_table_id));
35        // Safety: physical_table_info already filled in previous steps
36        let physical_table_info = &self.data.physical_table_info.as_ref().unwrap().table_info;
37        cache_keys.push(CacheIdent::TableName(extract_table_name(
38            physical_table_info,
39        )));
40
41        cache_keys
42    }
43}
44
45fn extract_table_name(table_info: &RawTableInfo) -> TableName {
46    TableName::new(
47        &table_info.catalog_name,
48        &table_info.schema_name,
49        &table_info.name,
50    )
51}