OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AlterColumnRecovery.h
Go to the documentation of this file.
1 /*
2  * Copyright 2023 HEAVY.AI, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include "AlterColumnShared.h"
20 #include "Catalog.h"
21 
23  public:
25 
27 
28  struct ColumnAltered {
31 
33  : old_cd(old_cd), new_cd(new_cd) {}
34  };
35 
36  struct RecoveryInfo {
37  std::list<ColumnDescriptor> renamed_columns;
38  std::list<ColumnDescriptor> added_columns;
39  std::list<ColumnAltered> altered_columns;
40  std::list<ColumnDescriptor> updated_dict_cds;
41 
42  int32_t table_epoch;
44 
45  std::list<std::pair<ColumnDescriptor, ColumnDescriptor>> src_dst_cds;
46  };
47 
48  void rollback(const TableDescriptor* td, const RecoveryInfo& param);
49 
50  void cleanup(const TableDescriptor* td, const TypePairs& src_dst_cds);
51 
52  void checkpoint(const TableDescriptor* td, const TypePairs& src_dst_cds);
53 
55  std::string base_path;
56  std::string db_name;
57  std::string table_name;
58  };
59 
61 
62  std::string serializeRecoveryInformation(const RecoveryInfo& param);
63 
65  const RecoveryParamFilepathInfo& filepath_info);
66 
68  const RecoveryParamFilepathInfo& filepath_info);
69 
70  std::string recoveryFilepath(const RecoveryParamFilepathInfo& filepath_info);
71 
72  RecoveryParamFilepathInfo getRecoveryFilepathInfo(const int32_t table_id = -1);
73 
75 
76  inline static const std::string kRecoveryDirectoryName = "crash_recovery";
77 
78  private:
79  void cleanupDeleteDictionaries(const TableDescriptor* td, const TypePairs& src_dst_cds);
80 
81  void cleanupClearChunk(const ChunkKey& key, const MemoryLevel mem_level);
82 
83  void cleanupClearChunk(const ChunkKey& key);
84 
86  const TypePairs& src_dst_cds);
87 
89  const TypePairs& src_dst_cds);
90 
91  static std::list<ColumnAltered> fromPairedCds(
92  const std::list<std::pair<ColumnDescriptor, ColumnDescriptor>>& altered_columns);
93 
94  std::list<std::pair<ColumnDescriptor, ColumnDescriptor>> toPairedCds(
95  const std::list<ColumnAltered>& altered_columns);
96 
97  void recoverAlterTableAlterColumnFromFile(const std::string& filename);
98 
99  std::list<std::filesystem::path> getRecoveryFiles();
100 
102  int table_id,
103  std::list<std::pair<ColumnDescriptor, ColumnDescriptor>>& pairs_list);
104 
105  static std::filesystem::path getRecoveryPrefix(const std::string& base_path);
106 
108 
109  static std::map<std::string, AlterTableAlterColumnCommandRecoveryMgr>
111 
113 };
114 
115 namespace json_utils {
116 // ColumnDescriptor
117 void set_value(rapidjson::Value& json_val,
118  const ColumnDescriptor& column_desc,
119  rapidjson::Document::AllocatorType& allocator);
120 
121 void get_value(const rapidjson::Value& json_val, ColumnDescriptor& column_desc);
122 } // namespace json_utils
alter_column_shared::TypePairs TypePairs
std::vector< int > ChunkKey
Definition: types.h:36
void cleanupDeleteDictionaries(const TableDescriptor *td, const TypePairs &src_dst_cds)
std::list< std::pair< ColumnDescriptor, ColumnDescriptor > > toPairedCds(const std::list< ColumnAltered > &altered_columns)
class for a per-database catalog. also includes metadata for the current database and the current use...
Definition: Catalog.h:143
void cleanupClearChunk(const ChunkKey &key, const MemoryLevel mem_level)
void set_value(rapidjson::Value &json_val, const ColumnDescriptor &column_desc, rapidjson::Document::AllocatorType &allocator)
RecoveryParamFilepathInfo getRecoveryFilepathInfo(const int32_t table_id=-1)
void recoverAlterTableAlterColumnFromFile(const std::string &filename)
RecoveryInfo deserializeRecoveryInformation(const std::string &filename)
ColumnAltered(const ColumnDescriptor &old_cd, const ColumnDescriptor &new_cd)
void cleanupDropSourceGeoColumns(const TableDescriptor *td, const TypePairs &src_dst_cds)
This file contains the class specification and related data structures for Catalog.
std::list< std::pair< ColumnDescriptor, ColumnDescriptor > > src_dst_cds
void checkpoint(const TableDescriptor *td, const TypePairs &src_dst_cds)
std::string serializeRecoveryInformation(const RecoveryInfo &param)
static const std::string kRecoveryDirectoryName
void cleanupClearRemainingChunks(const TableDescriptor *td, const TypePairs &src_dst_cds)
std::string recoveryFilepath(const RecoveryParamFilepathInfo &filepath_info)
specifies the content in-memory of a row in the column metadata table
std::list< std::pair< const ColumnDescriptor *, ColumnDescriptor * >> TypePairs
TypePairs getSrcDstCds(int table_id, std::list< std::pair< ColumnDescriptor, ColumnDescriptor >> &pairs_list)
static std::filesystem::path getRecoveryPrefix(const std::string &base_path)
std::list< std::filesystem::path > getRecoveryFiles()
void get_value(const rapidjson::Value &json_val, ColumnDescriptor &column_desc)
void readSerializedRecoveryInformation(RecoveryInfo &param, const RecoveryParamFilepathInfo &filepath_info)
static std::map< std::string, AlterTableAlterColumnCommandRecoveryMgr > createRecoveryManagersForCatalogs()
void cleanup(const TableDescriptor *td, const TypePairs &src_dst_cds)
static std::list< ColumnAltered > fromPairedCds(const std::list< std::pair< ColumnDescriptor, ColumnDescriptor >> &altered_columns)
void rollback(const TableDescriptor *td, const RecoveryInfo &param)
void writeSerializedRecoveryInformation(const RecoveryInfo &param, const RecoveryParamFilepathInfo &filepath_info)
AlterTableAlterColumnCommandRecoveryMgr(Catalog_Namespace::Catalog &catalog)