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