OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AlterColumnRecovery.cpp
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 #include "AlterColumnRecovery.h"
18 
19 #include <filesystem>
20 
21 #include "Catalog/SysCatalog.h"
22 #include "LockMgr/LockMgr.h"
24 #include "Shared/JsonUtils.h"
25 #include "Utils/DdlUtils.h"
26 
29  : catalog_(catalog) {}
30 
32  const RecoveryInfo& param) {
33  auto cds = catalog_.getAllColumnMetadataForTable(td->tableId, false, false, true);
34 
35  // Drop any columns that were added
36  for (auto& added_column : param.added_columns) {
37  auto cd_it =
38  std::find_if(cds.begin(), cds.end(), [&added_column](const ColumnDescriptor* cd) {
39  return added_column.columnId == cd->columnId;
40  });
41  auto cd = *cd_it;
42  ChunkKey col_key{catalog_.getCurrentDB().dbId, td->tableId, cd->columnId};
44  auto& data_mgr = catalog_.getDataMgr();
46  data_mgr.deleteChunksWithPrefix(col_key, MemoryLevel::CPU_LEVEL);
47  cds.erase(cd_it);
48  }
49 
50  // Rename any columns back to original name
51  for (auto& renamed_column : param.renamed_columns) {
52  auto cd_it = std::find_if(
53  cds.begin(), cds.end(), [&renamed_column](const ColumnDescriptor* cd) {
54  return renamed_column.columnId == cd->columnId;
55  });
56  if (cd_it != cds.end()) {
57  auto cd = *cd_it;
58  auto old_name = renamed_column.columnName;
59  if (cd->columnName != old_name) {
60  catalog_.renameColumn(td, cd, old_name);
61  }
62  }
63  }
64 
65  // Remove any added dictionary
66  for (auto& added_dict : param.updated_dict_cds) {
67  auto cd_it =
68  std::find_if(cds.begin(), cds.end(), [&added_dict](const ColumnDescriptor* cd) {
69  return added_dict.columnId == cd->columnId;
70  });
71  if (cd_it != cds.end()) {
72  auto cd = *cd_it;
73 
74  // Find all dictionaries, delete dictionaries which are defunct
76  for (const auto& dd : dds) {
77  if (!added_dict.columnType.is_dict_encoded_type() ||
78  dd->dictRef.dictId != added_dict.columnType.get_comp_param()) {
79  auto temp_cd = *cd;
80  temp_cd.columnType.set_comp_param(dd->dictRef.dictId);
81  temp_cd.columnType.setStringDictKey(
82  {catalog_.getDatabaseId(), dd->dictRef.dictId});
84  }
85  }
86  }
87  }
88 
89  // Undo any altered column
90  for (auto& altered_column : param.altered_columns) {
91  auto cd_it = std::find_if(
92  cds.begin(), cds.end(), [&altered_column](const ColumnDescriptor* cd) {
93  return altered_column.new_cd.columnId == cd->columnId;
94  });
95  if (cd_it != cds.end()) {
96  catalog_.alterColumnTypeTransactional(altered_column.old_cd);
97  }
98  }
99 }
100 
102  const TableDescriptor* td,
103  const TypePairs& src_dst_cds) {
104  for (auto& [src_cd, dst_cd] : src_dst_cds) {
105  if (!src_cd->columnType.is_dict_encoded_type()) {
106  continue;
107  }
109  .sql_types_match) {
111  }
112  }
113 }
114 
116  const ChunkKey& key,
117  const MemoryLevel mem_level) {
118  auto& data_mgr = catalog_.getDataMgr();
119  if (mem_level >= data_mgr.levelSizes_.size()) {
120  return;
121  }
122  for (int device = 0; device < data_mgr.levelSizes_[mem_level]; ++device) {
123  if (data_mgr.isBufferOnDevice(key, mem_level, device)) {
124  data_mgr.deleteChunk(key, mem_level, device);
125  }
126  }
127 }
128 
133 }
134 
136  const TableDescriptor* td,
137  const TypePairs& src_dst_cds) {
138  // for (non-geo) cases where the chunk keys change, chunks that remain with old chunk
139  // key must be removed
140  for (auto& [src_cd, dst_cd] : src_dst_cds) {
141  if (src_cd->columnType.is_varlen_indeed() != dst_cd->columnType.is_varlen_indeed()) {
142  ChunkMetadataVector chunk_metadata;
144  chunk_metadata, {catalog_.getDatabaseId(), td->tableId, dst_cd->columnId});
145  std::set<int> fragment_ids;
146  for (const auto& [key, _] : chunk_metadata) {
147  fragment_ids.insert(key[CHUNK_KEY_FRAGMENT_IDX]);
148  }
149  for (const auto& frag_id : fragment_ids) {
150  ChunkKey key = {catalog_.getDatabaseId(), td->tableId, src_cd->columnId, frag_id};
151  if (src_cd->columnType.is_varlen_indeed()) {
152  auto data_key = key;
153  data_key.push_back(1);
154  cleanupClearChunk(data_key);
155  auto index_key = key;
156  index_key.push_back(2);
157  cleanupClearChunk(index_key);
158  } else { // no varlen case
159  cleanupClearChunk(key);
160  }
161  }
162  }
163  }
164 }
165 
167  const TableDescriptor* td,
168  const TypePairs& src_dst_cds) {
169  for (auto& [src_cd, dst_cd] : src_dst_cds) {
170  if (!dst_cd->columnType.is_geometry()) {
171  continue;
172  }
173  auto catalog_cd = catalog_.getMetadataForColumn(src_cd->tableId, src_cd->columnId);
174  catalog_.dropColumnTransactional(*td, *catalog_cd);
175  ChunkKey col_key{catalog_.getCurrentDB().dbId, td->tableId, src_cd->columnId};
176  auto& data_mgr = catalog_.getDataMgr();
178  data_mgr.deleteChunksWithPrefix(col_key, MemoryLevel::CPU_LEVEL);
179  data_mgr.deleteChunksWithPrefix(col_key, MemoryLevel::DISK_LEVEL);
180  }
181 }
182 
183 std::list<AlterTableAlterColumnCommandRecoveryMgr::ColumnAltered>
185  const std::list<std::pair<ColumnDescriptor, ColumnDescriptor>>& altered_columns) {
186  std::list<ColumnAltered> retval;
187  for (const auto& [old_cd, new_cd] : altered_columns) {
188  retval.emplace_back(old_cd, new_cd);
189  }
190  return retval;
191 }
192 
193 std::list<std::pair<ColumnDescriptor, ColumnDescriptor>>
195  const std::list<ColumnAltered>& altered_columns) {
196  std::list<std::pair<ColumnDescriptor, ColumnDescriptor>> retval;
197  for (const auto& [old_cd, new_cd] : altered_columns) {
198  retval.emplace_back(old_cd, new_cd);
199  }
200  return retval;
201 }
202 
205  const std::string& filename) {
206  RecoveryInfo param;
207  auto d = json_utils::read_from_file(filename);
208  CHECK(d.IsObject());
209 
210  json_utils::get_value_from_object(d, param.added_columns, "added_columns");
211 
212  std::list<std::pair<ColumnDescriptor, ColumnDescriptor>> altered_column_pairs;
213  json_utils::get_value_from_object(d, altered_column_pairs, "altered_columns");
214  param.altered_columns = fromPairedCds(altered_column_pairs);
215 
216  json_utils::get_value_from_object(d, param.renamed_columns, "renamed_columns");
217 
218  json_utils::get_value_from_object(d, param.updated_dict_cds, "updated_dict_cds");
219 
220  json_utils::get_value_from_object(d, param.table_epoch, "table_epoch");
221  json_utils::get_value_from_object(d, param.is_vacuumed, "is_vacuumed");
222 
223  json_utils::get_value_from_object(d, param.src_dst_cds, "src_dst_cds");
224 
225  return param;
226 }
227 
229  const std::string& base_path) {
230  return std::filesystem::path(base_path) / std::filesystem::path(kRecoveryDirectoryName);
231 }
232 
234  const RecoveryParamFilepathInfo& filepath_info) {
235  auto prefix = getRecoveryPrefix(filepath_info.base_path);
236 
237  if (filepath_info.table_name.empty()) {
238  return prefix.string();
239  }
240 
241  return (prefix /
242  std::filesystem::path("alter_column_recovery_db_" + filepath_info.db_name +
243  "_table_" + filepath_info.table_name + ".json"))
244  .string();
245 }
246 
249  RecoveryParamFilepathInfo path_info;
250  path_info.base_path = catalog_.getCatalogBasePath();
251  path_info.db_name = catalog_.getCurrentDB().dbName;
252  path_info.table_name =
253  table_id >= 0 ? catalog_.getTableName(table_id).value() : std::string{};
254  return path_info;
255 }
256 
258  RecoveryInfo& param,
259  const RecoveryParamFilepathInfo& filepath_info) {
260  auto filename = recoveryFilepath(filepath_info);
261  std::ifstream ifs(filename);
262  if (!ifs) {
263  throw std::runtime_error{"Error trying to read file \"" + filename +
264  "\". The error was: " + std::strerror(errno)};
265  }
266  std::string json_string;
267  ifs >> json_string;
268  param = deserializeRecoveryInformation(json_string);
269 }
270 
272  const RecoveryInfo& param) {
273  rapidjson::Document d;
274  d.SetObject();
275 
277  d, param.added_columns, "added_columns", d.GetAllocator());
279  d, toPairedCds(param.altered_columns), "altered_columns", d.GetAllocator());
281  d, param.renamed_columns, "renamed_columns", d.GetAllocator());
283  d, param.updated_dict_cds, "updated_dict_cds", d.GetAllocator());
284  json_utils::add_value_to_object(d, param.table_epoch, "table_epoch", d.GetAllocator());
285  json_utils::add_value_to_object(d, param.is_vacuumed, "is_vacuumed", d.GetAllocator());
286 
287  json_utils::add_value_to_object(d, param.src_dst_cds, "src_dst_cds", d.GetAllocator());
288 
289  return json_utils::write_to_string(d);
290 }
291 
293  const RecoveryInfo& param,
294  const RecoveryParamFilepathInfo& filepath_info) {
295  auto filename = recoveryFilepath(filepath_info);
296 
297  // Create crash recovery directory if non-existent
298  auto prefix = getRecoveryPrefix(filepath_info.base_path).string();
299  if (!std::filesystem::exists(prefix)) {
300  if (!std::filesystem::create_directory(prefix)) {
301  throw std::runtime_error{"Error trying to create crash recovery directory \"" +
302  prefix + "\". The error was: " + std::strerror(errno)};
303  }
304  }
305 
306  // Use a temporary file name to indicate file has not been written yet
307  std::ofstream ofs(filename + ".tmp");
308  if (!ofs) {
309  throw std::runtime_error{"Error trying to create file \"" + filename +
310  "\". The error was: " + std::strerror(errno)};
311  }
312  ofs << serializeRecoveryInformation(param);
313  // Rename to target filename to indicate file was successfully written
314  std::filesystem::rename(filename + ".tmp", filename);
315 }
316 
318  const TypePairs& src_dst_cds) {
319  try {
320  cleanupDeleteDictionaries(td, src_dst_cds);
321  } catch (std::exception& except) {
322  LOG(WARNING) << "Alter column type: failed to clear source dictionaries: "
323  << except.what();
324  throw;
325  }
326 
327  try {
328  cleanupClearRemainingChunks(td, src_dst_cds);
329  } catch (std::exception& except) {
330  LOG(WARNING) << "Alter column type: failed to clear remaining chunks: "
331  << except.what();
332  throw;
333  }
334 
335  try {
336  cleanupDropSourceGeoColumns(td, src_dst_cds);
337  } catch (std::exception& except) {
338  LOG(WARNING) << "Alter column type: failed to remove geo's source column : "
339  << except.what();
340  throw;
341  }
342 
343  // Data is removed data, rollback no longer possible
344  checkpoint(td, src_dst_cds);
346 }
347 
349  const TypePairs& src_dst_cds) {
350  for (auto& [src_cd, dst_cd] : src_dst_cds) {
351  if (!dst_cd->columnType.is_dict_encoded_type()) {
352  continue;
353  }
355  .sql_types_match) {
356  continue;
357  }
358  auto string_dictionary =
359  catalog_.getMetadataForDict(dst_cd->columnType.get_comp_param(), true)
360  ->stringDict.get();
361  if (!string_dictionary->checkpoint()) {
362  throw std::runtime_error("Failed to checkpoint dictionary while altering column " +
363  dst_cd->columnName + ".");
364  }
365  }
367 }
368 
369 std::list<std::filesystem::path>
371  std::list<std::filesystem::path> result;
372  std::string path = recoveryFilepath(getRecoveryFilepathInfo());
373 
374  if (!std::filesystem::exists(path)) {
375  return {};
376  }
377 
378  for (const auto& entry : std::filesystem::directory_iterator(path)) {
379  auto entry_path = entry.path().string();
380  if (entry_path.find("alter_column_recovery_db_" + catalog_.name() + "_table_") !=
381  std::string::npos &&
382  entry_path.find(".json") != std::string::npos) {
383  if (entry_path.find(".tmp") != std::string::npos &&
384  entry_path.find(".tmp") == entry_path.size() - std::string{".tmp"}.size()) {
385  if (!std::filesystem::remove(entry_path)) {
386  throw std::runtime_error("Failed to remove incomplete recovery file: " +
387  entry_path);
388  } else {
389  LOG(INFO) << "Removing incomplete ALTER COLUMN recovery file: " + entry_path;
390  }
391  } else {
392  result.emplace_back(entry.path());
393  }
394  }
395  }
396  return result;
397 }
398 
401  int table_id,
402  std::list<std::pair<ColumnDescriptor, ColumnDescriptor>>& pairs_list) {
403  // Source columns must be obtained from catalog to ensure correctness/consistency
404  std::list<std::pair<const ColumnDescriptor*, ColumnDescriptor*>> result;
405  for (auto& [src, dst] : pairs_list) {
406  auto catalog_cd = catalog_.getMetadataForColumn(table_id, src.columnId);
407  if (!catalog_cd) {
408  // If column is missing in catalog, operate under the assumption it was
409  // already successfully removed in cleanup, along with all related
410  // components such as dictionaries
411  continue;
412  }
413  result.emplace_back(catalog_cd, &dst);
414  }
415  return result;
416 }
417 
419  const std::string& filename) {
421 
422  recovery_param = deserializeRecoveryInformation(filename);
423 
424  CHECK_GT(recovery_param.src_dst_cds.size(), 0UL);
425 
426  auto table_id = recovery_param.src_dst_cds.begin()->first.tableId;
427  auto table_name_opt = catalog_.getTableName(table_id);
428  CHECK(table_name_opt.has_value());
429  auto table_name = table_name_opt.value();
430 
431  const auto td_with_lock =
433  catalog_, table_name, false);
434  const auto td = td_with_lock();
435 
436  CHECK(td);
437  LOG(INFO) << "Starting crash recovery for table: " << td->tableName;
438 
439  auto table_epochs = catalog_.getTableEpochs(catalog_.getDatabaseId(), td->tableId);
440  CHECK_GT(table_epochs.size(), 0UL);
441  auto current_first_epoch = table_epochs[0].table_epoch;
442 
443  // The following semantics apply to the three epochs referenced below.
444  //
445  // alter_catalog_checkpoint_epoch: This refers to the checkpoint prior to any
446  // data modification, only operations that have modified the catalog are
447  // expected to have happened.
448  //
449  // alter_data_checkpoint_epoch: This refers to the checkpoint immediately
450  // after data conversion is complete.
451  //
452  // completed_alter_column_checkpoint_epoch: This refers to the checkpoint
453  // after all cleanup operations complete for the alter table command.
454  //
455  // NOTE: If the table may have deleted but unvacuumed elements, there may be
456  // an additional epoch introduced at the start requiring an additional offset.
457  int alter_catalog_checkpoint_epoch = recovery_param.table_epoch;
458 
459  if (recovery_param.is_vacuumed) {
460  alter_catalog_checkpoint_epoch++;
461  }
462  int alter_data_checkpoint_epoch = alter_catalog_checkpoint_epoch + 1;
463  int completed_alter_column_checkpoint_epoch = alter_data_checkpoint_epoch + 1;
464 
465  if (current_first_epoch == alter_catalog_checkpoint_epoch) {
466  rollback(td, recovery_param);
467  // If a vacuum operation was performed prior to alter column, revert the
468  // operation.
469  if (recovery_param.is_vacuumed) {
471  catalog_.getDatabaseId(), td->tableId, recovery_param.table_epoch);
472  }
473  } else if (current_first_epoch == alter_data_checkpoint_epoch) {
474  auto src_dst_cds = getSrcDstCds(table_id, recovery_param.src_dst_cds);
475  try {
476  cleanup(td, src_dst_cds);
477  } catch (std::exception& except) {
478  throw std::runtime_error("Alter column recovery error during cleanup: " +
479  std::string(except.what()));
480  }
481  ChunkKey table_key{catalog_.getCurrentDB().dbId, td->tableId};
483  boost::hash_value(table_key));
486 
487  } else {
488  CHECK_EQ(current_first_epoch, completed_alter_column_checkpoint_epoch);
489  // no-op, last checkpoint reached in processing
490  }
491  LOG(INFO) << "Completed crash recovery for table: " << td->tableName;
492 }
493 
495  auto recovery_files = getRecoveryFiles();
496  if (recovery_files.empty()) {
497  return;
498  }
499 
500  LOG(INFO) << "Starting crash recovery for tables in catalog: " << catalog_.name();
501  for (const auto& filepath : recovery_files) {
502  recoverAlterTableAlterColumnFromFile(filepath.string());
503  std::filesystem::remove(filepath);
504  }
505  LOG(INFO) << "Completed crash recovery for tables in catalog: " << catalog_.name();
506 }
507 
508 std::map<std::string, AlterTableAlterColumnCommandRecoveryMgr>
510  std::map<std::string, AlterTableAlterColumnCommandRecoveryMgr> result;
511 
513  auto base_path = syscat.getCatalogBasePath();
514  auto prefix = getRecoveryPrefix(base_path);
515  if (!std::filesystem::exists(prefix)) {
516  return {};
517  }
518 
519  auto catalog_metadata = syscat.getAllDBMetadata();
520 
521  for (const auto& entry : std::filesystem::directory_iterator(prefix)) {
522  auto entry_path = entry.path().string();
523 
524  for (const auto& db_metadata : catalog_metadata) {
525  if (result.count(db_metadata.dbName)) {
526  continue;
527  }
528  auto match_db = entry_path.find("alter_column_recovery_db_" + db_metadata.dbName);
529  if (match_db == std::string::npos) {
530  continue;
531  }
532  auto catalog = syscat.getCatalog(db_metadata.dbName);
533  CHECK(catalog.get());
534  result.emplace(db_metadata.dbName, *catalog);
535  }
536  }
537 
538  return result;
539 }
540 
543  auto recovery_mgrs = createRecoveryManagersForCatalogs();
544 
545  for (auto& [dbname, recovery_mgr] : recovery_mgrs) {
546  recovery_mgr.resolveIncompleteAlterColumnCommands();
547  }
548 }
549 
550 namespace json_utils {
551 // ColumnDescriptor
552 void set_value(rapidjson::Value& json_val,
553  const ColumnDescriptor& column_desc,
554  rapidjson::Document::AllocatorType& allocator) {
555  json_val.SetObject();
556  auto default_value = column_desc.default_value;
557  if (default_value.has_value()) {
558  add_value_to_object(json_val, true, "has_default_value", allocator);
560  json_val, default_value.value(), "default_value_literal", allocator);
561  } else {
562  add_value_to_object(json_val, false, "has_default_value", allocator);
563  }
564  add_value_to_object(json_val, column_desc.chunks, "chunks", allocator);
565  add_value_to_object(json_val, column_desc.columnId, "column_id", allocator);
566  add_value_to_object(json_val, column_desc.columnName, "column_name", allocator);
567  add_value_to_object(json_val, column_desc.columnType, "column_type", allocator);
568  add_value_to_object(json_val, column_desc.db_id, "db_id", allocator);
569  add_value_to_object(json_val, column_desc.isDeletedCol, "is_deleted_col", allocator);
570  add_value_to_object(json_val, column_desc.isGeoPhyCol, "is_geo_phy_col", allocator);
571  add_value_to_object(json_val, column_desc.isSystemCol, "is_system_col", allocator);
572  add_value_to_object(json_val, column_desc.isVirtualCol, "is_virtual_col", allocator);
573  add_value_to_object(json_val, column_desc.sourceName, "source_name", allocator);
574  add_value_to_object(json_val, column_desc.tableId, "table_id", allocator);
575  add_value_to_object(json_val, column_desc.virtualExpr, "virtual_expr", allocator);
576 }
577 
578 void get_value(const rapidjson::Value& json_val, ColumnDescriptor& column_desc) {
579  CHECK(json_val.IsObject());
580 
581  bool has_default_value;
582  get_value_from_object(json_val, has_default_value, "has_default_value");
583  if (has_default_value) {
584  std::string default_value;
585  get_value_from_object(json_val, default_value, "default_value_literal");
586  column_desc.default_value = default_value;
587  } else {
588  column_desc.default_value = std::nullopt;
589  }
590 
591  get_value_from_object(json_val, column_desc.chunks, "chunks");
592  get_value_from_object(json_val, column_desc.columnId, "column_id");
593  get_value_from_object(json_val, column_desc.columnName, "column_name");
594  get_value_from_object(json_val, column_desc.db_id, "db_id");
595  get_value_from_object(json_val, column_desc.isDeletedCol, "is_deleted_col");
596  get_value_from_object(json_val, column_desc.isGeoPhyCol, "is_geo_phy_col");
597  get_value_from_object(json_val, column_desc.isSystemCol, "is_system_col");
598  get_value_from_object(json_val, column_desc.isVirtualCol, "is_virtual_col");
599  get_value_from_object(json_val, column_desc.sourceName, "source_name");
600  get_value_from_object(json_val, column_desc.tableId, "table_id");
601  get_value_from_object(json_val, column_desc.virtualExpr, "virtual_expr");
602  get_value_from_object(json_val, column_desc.columnType, "column_type");
603 }
604 } // namespace json_utils
static void invalidateCachesByTable(size_t table_key)
std::string virtualExpr
#define CHECK_EQ(x, y)
Definition: Logger.h:301
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)
void deleteChunk(const ChunkKey &key, const MemoryLevel mem_level, const int device_id)
Definition: DataMgr.cpp:597
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)
CompareResult compare_column_descriptors(const ColumnDescriptor *lhs, const ColumnDescriptor *rhs)
Definition: DdlUtils.cpp:52
RecoveryParamFilepathInfo getRecoveryFilepathInfo(const int32_t table_id=-1)
Data_Namespace::DataMgr & getDataMgr() const
Definition: Catalog.h:266
void delDictionaryTransactional(const ColumnDescriptor &cd)
Definition: Catalog.cpp:2277
#define LOG(tag)
Definition: Logger.h:285
#define CHUNK_KEY_FRAGMENT_IDX
Definition: types.h:41
void get_value_from_object(const rapidjson::Value &object, T &value, const std::string &name)
Definition: JsonUtils.h:270
void recoverAlterTableAlterColumnFromFile(const std::string &filename)
RecoveryInfo deserializeRecoveryInformation(const std::string &filename)
#define CHECK_GT(x, y)
Definition: Logger.h:305
void renameColumn(const TableDescriptor *td, const ColumnDescriptor *cd, const std::string &newColumnName)
Definition: Catalog.cpp:4631
std::string sourceName
void resetTableEpochFloor(const int logicalTableId) const
Definition: Catalog.cpp:5050
std::string chunks
rapidjson::Document read_from_file(const std::string &file_path)
Definition: JsonUtils.cpp:201
void cleanupDropSourceGeoColumns(const TableDescriptor *td, const TypePairs &src_dst_cds)
std::string name() const
Definition: Catalog.h:348
static SysCatalog & instance()
Definition: SysCatalog.h:343
This file contains the class specification and related data structures for SysCatalog.
std::list< std::pair< ColumnDescriptor, ColumnDescriptor > > src_dst_cds
void checkpoint(const TableDescriptor *td, const TypePairs &src_dst_cds)
const DBMetadata & getCurrentDB() const
Definition: Catalog.h:265
std::string serializeRecoveryInformation(const RecoveryInfo &param)
std::list< const DictDescriptor * > getAllDictionariesWithColumnInName(const ColumnDescriptor *cd)
Definition: Catalog.cpp:2333
void getChunkMetadataVecForKeyPrefix(ChunkMetadataVector &chunkMetadataVec, const ChunkKey &keyPrefix)
Definition: DataMgr.cpp:546
static const std::string kRecoveryDirectoryName
void cleanupClearRemainingChunks(const TableDescriptor *td, const TypePairs &src_dst_cds)
const ColumnDescriptor * getMetadataForColumn(int tableId, const std::string &colName) const
std::vector< std::pair< ChunkKey, std::shared_ptr< ChunkMetadata >>> ChunkMetadataVector
int getDatabaseId() const
Definition: Catalog.h:326
std::string write_to_string(const rapidjson::Document &document)
Definition: JsonUtils.cpp:225
std::string recoveryFilepath(const RecoveryParamFilepathInfo &filepath_info)
const DictDescriptor * getMetadataForDict(int dict_ref, bool loadDict=true) const
Definition: Catalog.cpp:1907
specifies the content in-memory of a row in the column metadata table
TypePairs getSrcDstCds(int table_id, std::list< std::pair< ColumnDescriptor, ColumnDescriptor >> &pairs_list)
void checkpointWithAutoRollback(const int logical_table_id) const
Definition: Catalog.cpp:5040
std::optional< std::string > default_value
void deleteChunksWithPrefix(const ChunkKey &keyPrefix)
Definition: DataMgr.cpp:572
static std::filesystem::path getRecoveryPrefix(const std::string &base_path)
std::list< std::filesystem::path > getRecoveryFiles()
void setTableEpoch(const int db_id, const int table_id, const int new_epoch)
Definition: Catalog.cpp:3657
void get_value(const rapidjson::Value &json_val, ColumnDescriptor &column_desc)
void add_value_to_object(rapidjson::Value &object, const T &value, const std::string &name, rapidjson::Document::AllocatorType &allocator)
Definition: JsonUtils.h:255
std::list< const ColumnDescriptor * > getAllColumnMetadataForTable(const int tableId, const bool fetchSystemColumns, const bool fetchVirtualColumns, const bool fetchPhysicalColumns) const
Returns a list of pointers to constant ColumnDescriptor structs for all the columns from a particular...
Definition: Catalog.cpp:2175
void dropColumnTransactional(const TableDescriptor &td, const ColumnDescriptor &cd)
Definition: Catalog.cpp:2601
void readSerializedRecoveryInformation(RecoveryInfo &param, const RecoveryParamFilepathInfo &filepath_info)
static std::map< std::string, AlterTableAlterColumnCommandRecoveryMgr > createRecoveryManagersForCatalogs()
std::size_t hash_value(RexAbstractInput const &rex_ab_input)
Definition: RelAlgDag.cpp:3548
void cleanup(const TableDescriptor *td, const TypePairs &src_dst_cds)
#define CHECK(condition)
Definition: Logger.h:291
std::optional< std::string > getTableName(int32_t table_id) const
Definition: Catalog.cpp:1872
void alterColumnTypeTransactional(const ColumnDescriptor &cd)
Definition: Catalog.cpp:2393
static std::list< ColumnAltered > fromPairedCds(const std::list< std::pair< ColumnDescriptor, ColumnDescriptor >> &altered_columns)
SQLTypeInfo columnType
const std::string & getCatalogBasePath() const
Definition: Catalog.h:273
void rollback(const TableDescriptor *td, const RecoveryInfo &param)
void writeSerializedRecoveryInformation(const RecoveryInfo &param, const RecoveryParamFilepathInfo &filepath_info)
std::string columnName
std::vector< TableEpochInfo > getTableEpochs(const int32_t db_id, const int32_t table_id) const
Definition: Catalog.cpp:3831
AlterTableAlterColumnCommandRecoveryMgr(Catalog_Namespace::Catalog &catalog)