MCPcopy Create free account
hub / github.com/ByConity/ByConity / readDbStats

Function readDbStats

src/Interpreters/InterpreterShowStatsQuery.cpp:177–242  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

175}
176
177void readDbStats(ContextPtr context, const String & original_db_name, const String & path)
178{
179 std::ifstream fin(path, std::ios::binary);
180 DbStats db_stats;
181 db_stats.ParseFromIstream(&fin);
182
183 auto version = db_stats.has_version() ? db_stats.version() : DbStats_Version_V1;
184 if (version == DbStats_Version_V1)
185 {
186 version = DbStats_Version_V2;
187 }
188 if (version != PROTO_VERSION)
189 {
190 throw Exception("stats version is incorrect", ErrorCodes::LOGICAL_ERROR);
191 }
192
193 auto db_name = original_db_name;
194 auto catalog = createCatalogAdaptor(context);
195 auto logger = &Poco::Logger::get("load stats");
196
197 auto load_ts = AutoStats::convertToDateTime64(AutoStats::nowTimePoint());
198 for (auto & table_pb : db_stats.tables())
199 {
200 auto table_name = table_pb.table_name();
201 auto table_id_opt = catalog->getTableIdByName(db_name, table_name);
202 if (!table_id_opt)
203 {
204 auto msg = "table " + table_name + " not exist in database " + db_name;
205 logger->warning(msg);
206 continue;
207 }
208
209 StatisticsCollector collector(context, catalog, table_id_opt.value());
210
211 {
212 StatsCollection collection;
213 for (auto & [k, v] : table_pb.blobs())
214 {
215 auto tag = static_cast<StatisticsTag>(k);
216 auto obj = createStatisticsBase(tag, v);
217 if (obj)
218 collection[tag] = std::move(obj);
219 }
220 StatisticsCollector::TableStats table_stats;
221 table_stats.readFromCollection(collection);
222 table_stats.basic->setTimestamp(load_ts);
223 collector.setTableStats(std::move(table_stats));
224 }
225
226 for (auto & column_pb : table_pb.columns())
227 {
228 auto column_name = column_pb.column_name();
229 StatsCollection collection;
230 for (auto & [k, v] : column_pb.blobs())
231 {
232 auto tag = static_cast<StatisticsTag>(k);
233 auto obj = createStatisticsBase(tag, v);
234 collection[tag] = std::move(obj);

Callers 1

executeSpecialMethod · 0.85

Calls 15

createCatalogAdaptorFunction · 0.85
convertToDateTime64Function · 0.85
nowTimePointFunction · 0.85
createStatisticsBaseFunction · 0.85
setTableStatsMethod · 0.80
columnsMethod · 0.80
setColumnStatsMethod · 0.80
writeToCatalogMethod · 0.80
ExceptionClass · 0.70
getFunction · 0.50
versionMethod · 0.45
tablesMethod · 0.45

Tested by

no test coverage detected