1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#include <DataTypes/DataTypeString.h>
#include <DataTypes/DataTypesNumber.h>
#include <DataTypes/DataTypeDateTime.h>
#include <DataTypes/DataTypeArray.h>
#include <Storages/System/StorageSystemErrors.h>
#include <Interpreters/Context.h>
#include <Common/ErrorCodes.h>
namespace DB
{
NamesAndTypesList StorageSystemErrors::getNamesAndTypes()
{
return {
{ "name", std::make_shared<DataTypeString>() },
{ "code", std::make_shared<DataTypeInt32>() },
{ "value", std::make_shared<DataTypeUInt64>() },
{ "last_error_time", std::make_shared<DataTypeDateTime>() },
{ "last_error_message", std::make_shared<DataTypeString>() },
{ "last_error_trace", std::make_shared<DataTypeArray>(std::make_shared<DataTypeUInt64>()) },
{ "remote", std::make_shared<DataTypeUInt8>() },
};
}
void StorageSystemErrors::fillData(MutableColumns & res_columns, ContextPtr context, const SelectQueryInfo &) const
{
auto add_row = [&](std::string_view name, size_t code, const auto & error, bool remote)
{
if (error.count || context->getSettingsRef().system_events_show_zero_values)
{
size_t col_num = 0;
res_columns[col_num++]->insert(name);
res_columns[col_num++]->insert(code);
res_columns[col_num++]->insert(error.count);
res_columns[col_num++]->insert(error.error_time_ms / 1000);
res_columns[col_num++]->insert(error.message);
{
Array trace_array;
trace_array.reserve(error.trace.size());
for (size_t i = 0; i < error.trace.size(); ++i)
trace_array.emplace_back(reinterpret_cast<intptr_t>(error.trace[i]));
res_columns[col_num++]->insert(trace_array);
}
res_columns[col_num++]->insert(remote);
}
};
for (size_t i = 0, end = ErrorCodes::end(); i < end; ++i)
{
const auto & error = ErrorCodes::values[i].get();
std::string_view name = ErrorCodes::getName(static_cast<ErrorCodes::ErrorCode>(i));
if (name.empty())
continue;
add_row(name, i, error.local, /* remote= */ false);
add_row(name, i, error.remote, /* remote= */ true);
}
}
}
|