OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
InternalStorageStatsDataWrapper.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2022 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 
18 
19 #include <filesystem>
20 
21 #include "Catalog/SysCatalog.h"
22 #include "ImportExport/Importer.h"
23 
24 namespace foreign_storage {
27 
29  const int db_id,
30  const ForeignTable* foreign_table)
31  : InternalSystemDataWrapper(db_id, foreign_table) {}
32 
33 namespace {
35  import_buffer->add_value(import_buffer->getColumnDesc(), "", true, {});
36 }
37 
39  const std::vector<StorageDetails>& storage_details,
40  std::map<std::string, import_export::TypedImportBuffer*>& import_buffers) {
41  for (const auto& storage_detail : storage_details) {
42  set_node_name(import_buffers);
43  if (import_buffers.find("database_id") != import_buffers.end()) {
44  import_buffers["database_id"]->addInt(storage_detail.database_id);
45  }
46  if (import_buffers.find("database_name") != import_buffers.end()) {
47  import_buffers["database_name"]->addDictStringWithTruncation(
48  get_db_name(storage_detail.database_id));
49  }
50  if (import_buffers.find("table_id") != import_buffers.end()) {
51  import_buffers["table_id"]->addInt(storage_detail.table_id);
52  }
53  if (import_buffers.find("table_name") != import_buffers.end()) {
54  import_buffers["table_name"]->addDictStringWithTruncation(
55  get_table_name(storage_detail.database_id, storage_detail.table_id));
56  }
57  if (import_buffers.find("epoch") != import_buffers.end()) {
58  import_buffers["epoch"]->addInt(storage_detail.storage_stats.epoch);
59  }
60  if (import_buffers.find("epoch_floor") != import_buffers.end()) {
61  import_buffers["epoch_floor"]->addInt(storage_detail.storage_stats.epoch_floor);
62  }
63  if (import_buffers.find("fragment_count") != import_buffers.end()) {
64  auto import_buffer = import_buffers["fragment_count"];
65  if (storage_detail.storage_stats.fragment_count.has_value()) {
66  import_buffer->addInt(storage_detail.storage_stats.fragment_count.value());
67  } else {
68  set_null(import_buffer);
69  }
70  }
71  if (import_buffers.find("shard_id") != import_buffers.end()) {
72  import_buffers["shard_id"]->addInt(storage_detail.shard_id);
73  }
74  if (import_buffers.find("data_file_count") != import_buffers.end()) {
75  import_buffers["data_file_count"]->addInt(
76  storage_detail.storage_stats.data_file_count);
77  }
78  if (import_buffers.find("metadata_file_count") != import_buffers.end()) {
79  import_buffers["metadata_file_count"]->addInt(
80  storage_detail.storage_stats.metadata_file_count);
81  }
82  if (import_buffers.find("total_data_file_size") != import_buffers.end()) {
83  import_buffers["total_data_file_size"]->addBigint(
84  storage_detail.storage_stats.total_data_file_size);
85  }
86  if (import_buffers.find("total_data_page_count") != import_buffers.end()) {
87  import_buffers["total_data_page_count"]->addBigint(
88  storage_detail.storage_stats.total_data_page_count);
89  }
90  if (import_buffers.find("total_free_data_page_count") != import_buffers.end()) {
91  auto import_buffer = import_buffers["total_free_data_page_count"];
92  if (storage_detail.storage_stats.total_free_data_page_count.has_value()) {
93  import_buffer->addBigint(
94  storage_detail.storage_stats.total_free_data_page_count.value());
95  } else {
96  set_null(import_buffer);
97  }
98  }
99  if (import_buffers.find("total_metadata_file_size") != import_buffers.end()) {
100  import_buffers["total_metadata_file_size"]->addBigint(
101  storage_detail.storage_stats.total_metadata_file_size);
102  }
103  if (import_buffers.find("total_metadata_page_count") != import_buffers.end()) {
104  import_buffers["total_metadata_page_count"]->addBigint(
105  storage_detail.storage_stats.total_metadata_page_count);
106  }
107  if (import_buffers.find("total_free_metadata_page_count") != import_buffers.end()) {
108  auto import_buffer = import_buffers["total_free_metadata_page_count"];
109  if (storage_detail.storage_stats.total_free_metadata_page_count.has_value()) {
110  import_buffer->addBigint(
111  storage_detail.storage_stats.total_free_metadata_page_count.value());
112  } else {
113  set_null(import_buffer);
114  }
115  }
116  if (import_buffers.find("total_dictionary_data_file_size") != import_buffers.end()) {
117  import_buffers["total_dictionary_data_file_size"]->addBigint(
118  storage_detail.total_dictionary_data_file_size);
119  }
120  }
121 }
122 } // namespace
123 
125  const std::string& table_name) {
127  storage_details_.clear();
128  const auto global_file_mgr =
130  CHECK(global_file_mgr);
131  auto& sys_catalog = Catalog_Namespace::SysCatalog::instance();
132  for (const auto& catalog : sys_catalog.getCatalogsForAllDbs()) {
133  if (catalog->name() != shared::kInfoSchemaDbName) {
134  std::set<std::string> found_dict_paths;
135  for (const auto& [table_id, shard_id] :
136  catalog->getAllPersistedTableAndShardIds()) {
137  uint64_t total_dictionary_file_size{0};
138  auto logical_table_id = catalog->getLogicalTableId(table_id);
139  for (const auto& dict_path :
140  catalog->getTableDictDirectoryPaths(logical_table_id)) {
141  if (found_dict_paths.find(dict_path) == found_dict_paths.end()) {
142  found_dict_paths.emplace(dict_path);
143  } else {
144  // Skip shared dictionaries.
145  continue;
146  }
147  CHECK(std::filesystem::is_directory(dict_path));
148  for (const auto& file_entry : std::filesystem::directory_iterator(dict_path)) {
149  CHECK(file_entry.is_regular_file());
150  total_dictionary_file_size += static_cast<uint64_t>(file_entry.file_size());
151  }
152  }
153  auto db_id = catalog->getDatabaseId();
154  storage_details_.emplace_back(db_id,
155  logical_table_id,
156  shard_id,
157  total_dictionary_file_size,
158  global_file_mgr->getStorageStats(db_id, table_id));
159  }
160  }
161  }
162  row_count_ = storage_details_.size();
163 }
164 
166  const std::string& table_name,
167  std::map<std::string, import_export::TypedImportBuffer*>& import_buffers) {
170 }
171 } // namespace foreign_storage
#define CHECK_EQ(x, y)
Definition: Logger.h:301
void populateChunkBuffersForTable(const std::string &table_name, std::map< std::string, import_export::TypedImportBuffer * > &import_buffers) override
void populate_import_buffers_for_storage_details(const std::vector< StorageDetails > &storage_details, std::map< std::string, import_export::TypedImportBuffer * > &import_buffers)
const std::string kInfoSchemaDbName
Data_Namespace::DataMgr & getDataMgr() const
Definition: SysCatalog.h:234
static SysCatalog & instance()
Definition: SysCatalog.h:343
This file contains the class specification and related data structures for SysCatalog.
void set_node_name(std::map< std::string, import_export::TypedImportBuffer * > &import_buffers)
CONSTEXPR DEVICE void set_null(T &value)
File_Namespace::GlobalFileMgr * getGlobalFileMgr() const
Definition: DataMgr.cpp:649
static constexpr const char * STORAGE_DETAILS_SYS_TABLE_NAME
Definition: Catalog.h:121
#define CHECK(condition)
Definition: Logger.h:291
void initializeObjectsForTable(const std::string &table_name) override
std::string get_db_name(int32_t db_id)
const ColumnDescriptor * getColumnDesc() const
Definition: Importer.h:325
void add_value(const ColumnDescriptor *cd, const std::string_view val, const bool is_null, const CopyParams &copy_params, const bool check_not_null=true)
Definition: Importer.cpp:529
std::string get_table_name(int32_t db_id, int32_t table_id)