2017-04-01 09:19:00 +00:00
|
|
|
#include <Columns/ColumnsNumber.h>
|
|
|
|
#include <Columns/ColumnArray.h>
|
|
|
|
#include <Columns/ColumnString.h>
|
|
|
|
#include <DataTypes/DataTypeArray.h>
|
|
|
|
#include <DataTypes/DataTypesNumber.h>
|
|
|
|
#include <DataTypes/DataTypeDateTime.h>
|
|
|
|
#include <DataTypes/DataTypeDate.h>
|
|
|
|
#include <DataTypes/DataTypeString.h>
|
2018-01-23 22:56:46 +00:00
|
|
|
#include <DataTypes/DataTypeEnum.h>
|
2019-10-10 16:30:30 +00:00
|
|
|
#include <Storages/MergeTree/IMergeTreeDataPart.h>
|
2017-06-25 00:01:10 +00:00
|
|
|
#include <Storages/MergeTree/MergeTreeData.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Interpreters/PartLog.h>
|
2020-05-20 20:16:32 +00:00
|
|
|
#include <Interpreters/Context.h>
|
2017-03-07 17:13:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2017-06-25 00:01:10 +00:00
|
|
|
|
2017-03-07 17:13:54 +00:00
|
|
|
Block PartLogElement::createBlock()
|
|
|
|
{
|
2018-01-23 22:56:46 +00:00
|
|
|
auto event_type_datatype = std::make_shared<DataTypeEnum8>(
|
2018-09-09 02:23:24 +00:00
|
|
|
DataTypeEnum8::Values
|
|
|
|
{
|
2019-08-01 16:37:50 +00:00
|
|
|
{"NewPart", static_cast<Int8>(NEW_PART)},
|
|
|
|
{"MergeParts", static_cast<Int8>(MERGE_PARTS)},
|
|
|
|
{"DownloadPart", static_cast<Int8>(DOWNLOAD_PART)},
|
|
|
|
{"RemovePart", static_cast<Int8>(REMOVE_PART)},
|
|
|
|
{"MutatePart", static_cast<Int8>(MUTATE_PART)},
|
2019-09-03 11:32:25 +00:00
|
|
|
{"MovePart", static_cast<Int8>(MOVE_PART)},
|
|
|
|
}
|
|
|
|
);
|
2018-01-23 22:56:46 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return
|
|
|
|
{
|
2019-09-06 12:18:56 +00:00
|
|
|
{ColumnInt8::create(), std::move(event_type_datatype), "event_type"},
|
2018-11-26 00:56:50 +00:00
|
|
|
{ColumnUInt16::create(), std::make_shared<DataTypeDate>(), "event_date"},
|
|
|
|
{ColumnUInt32::create(), std::make_shared<DataTypeDateTime>(), "event_time"},
|
|
|
|
{ColumnUInt64::create(), std::make_shared<DataTypeUInt64>(), "duration_ms"},
|
2018-01-23 22:56:46 +00:00
|
|
|
|
2018-11-26 00:56:50 +00:00
|
|
|
{ColumnString::create(), std::make_shared<DataTypeString>(), "database"},
|
|
|
|
{ColumnString::create(), std::make_shared<DataTypeString>(), "table"},
|
|
|
|
{ColumnString::create(), std::make_shared<DataTypeString>(), "part_name"},
|
|
|
|
{ColumnString::create(), std::make_shared<DataTypeString>(), "partition_id"},
|
2019-09-03 11:32:25 +00:00
|
|
|
{ColumnString::create(), std::make_shared<DataTypeString>(), "path_on_disk"},
|
2018-01-23 22:56:46 +00:00
|
|
|
|
2018-11-26 00:56:50 +00:00
|
|
|
{ColumnUInt64::create(), std::make_shared<DataTypeUInt64>(), "rows"},
|
|
|
|
{ColumnUInt64::create(), std::make_shared<DataTypeUInt64>(), "size_in_bytes"}, // On disk
|
2018-01-23 22:56:46 +00:00
|
|
|
|
|
|
|
/// Merge-specific info
|
|
|
|
{ColumnArray::create(ColumnString::create()), std::make_shared<DataTypeArray>(std::make_shared<DataTypeString>()), "merged_from"},
|
2018-11-26 00:56:50 +00:00
|
|
|
{ColumnUInt64::create(), std::make_shared<DataTypeUInt64>(), "bytes_uncompressed"}, // Result bytes
|
|
|
|
{ColumnUInt64::create(), std::make_shared<DataTypeUInt64>(), "read_rows"},
|
|
|
|
{ColumnUInt64::create(), std::make_shared<DataTypeUInt64>(), "read_bytes"},
|
2020-03-19 11:31:21 +00:00
|
|
|
{ColumnUInt64::create(), std::make_shared<DataTypeUInt64>(), "peak_memory_usage"},
|
2018-01-23 22:56:46 +00:00
|
|
|
|
|
|
|
/// Is there an error during the execution or commit
|
2018-11-26 00:56:50 +00:00
|
|
|
{ColumnUInt16::create(), std::make_shared<DataTypeUInt16>(), "error"},
|
|
|
|
{ColumnString::create(), std::make_shared<DataTypeString>(), "exception"},
|
2018-05-07 02:01:11 +00:00
|
|
|
};
|
2017-03-07 17:13:54 +00:00
|
|
|
}
|
|
|
|
|
2020-05-21 20:15:18 +00:00
|
|
|
void PartLogElement::appendToBlock(MutableColumns & columns) const
|
2017-03-07 17:13:54 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t i = 0;
|
2017-03-07 17:13:54 +00:00
|
|
|
|
2018-10-22 08:54:54 +00:00
|
|
|
columns[i++]->insert(event_type);
|
|
|
|
columns[i++]->insert(DateLUT::instance().toDayNum(event_time));
|
|
|
|
columns[i++]->insert(event_time);
|
|
|
|
columns[i++]->insert(duration_ms);
|
2017-03-07 17:13:54 +00:00
|
|
|
|
2017-12-15 18:23:05 +00:00
|
|
|
columns[i++]->insert(database_name);
|
|
|
|
columns[i++]->insert(table_name);
|
|
|
|
columns[i++]->insert(part_name);
|
2018-09-13 12:48:46 +00:00
|
|
|
columns[i++]->insert(partition_id);
|
2019-09-03 11:32:25 +00:00
|
|
|
columns[i++]->insert(path_on_disk);
|
2017-03-07 17:13:54 +00:00
|
|
|
|
2018-10-22 08:54:54 +00:00
|
|
|
columns[i++]->insert(rows);
|
|
|
|
columns[i++]->insert(bytes_compressed_on_disk);
|
2018-01-23 22:56:46 +00:00
|
|
|
|
|
|
|
Array source_part_names_array;
|
|
|
|
source_part_names_array.reserve(source_part_names.size());
|
|
|
|
for (const auto & name : source_part_names)
|
|
|
|
source_part_names_array.push_back(name);
|
|
|
|
|
|
|
|
columns[i++]->insert(source_part_names_array);
|
|
|
|
|
2018-10-22 08:54:54 +00:00
|
|
|
columns[i++]->insert(bytes_uncompressed);
|
|
|
|
columns[i++]->insert(rows_read);
|
|
|
|
columns[i++]->insert(bytes_read_uncompressed);
|
2020-03-19 11:31:21 +00:00
|
|
|
columns[i++]->insert(peak_memory_usage);
|
2017-12-15 18:23:05 +00:00
|
|
|
|
2018-10-22 08:54:54 +00:00
|
|
|
columns[i++]->insert(error);
|
2018-01-23 22:56:46 +00:00
|
|
|
columns[i++]->insert(exception);
|
2017-03-07 17:13:54 +00:00
|
|
|
}
|
|
|
|
|
2018-01-23 22:56:46 +00:00
|
|
|
|
2019-01-07 10:40:58 +00:00
|
|
|
bool PartLog::addNewPart(Context & current_context, const MutableDataPartPtr & part, UInt64 elapsed_ns, const ExecutionStatus & execution_status)
|
2017-06-25 00:01:10 +00:00
|
|
|
{
|
2019-01-07 10:40:58 +00:00
|
|
|
return addNewParts(current_context, {part}, elapsed_ns, execution_status);
|
2018-05-21 13:49:54 +00:00
|
|
|
}
|
|
|
|
|
2019-01-07 10:40:58 +00:00
|
|
|
bool PartLog::addNewParts(Context & current_context, const PartLog::MutableDataPartsVector & parts, UInt64 elapsed_ns,
|
2018-05-21 13:49:54 +00:00
|
|
|
const ExecutionStatus & execution_status)
|
|
|
|
{
|
|
|
|
if (parts.empty())
|
|
|
|
return true;
|
|
|
|
|
2019-03-21 19:22:38 +00:00
|
|
|
std::shared_ptr<PartLog> part_log;
|
2018-01-23 22:56:46 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2019-12-10 20:47:05 +00:00
|
|
|
auto table_id = parts.front()->storage.getStorageID();
|
|
|
|
part_log = current_context.getPartLog(table_id.database_name); // assume parts belong to the same table
|
2018-01-23 22:56:46 +00:00
|
|
|
if (!part_log)
|
|
|
|
return false;
|
|
|
|
|
2018-05-21 13:49:54 +00:00
|
|
|
for (const auto & part : parts)
|
|
|
|
{
|
|
|
|
PartLogElement elem;
|
2017-06-25 00:01:10 +00:00
|
|
|
|
2018-05-21 13:49:54 +00:00
|
|
|
elem.event_type = PartLogElement::NEW_PART;
|
|
|
|
elem.event_time = time(nullptr);
|
|
|
|
elem.duration_ms = elapsed_ns / 1000000;
|
2017-06-25 00:01:10 +00:00
|
|
|
|
2019-12-10 20:47:05 +00:00
|
|
|
elem.database_name = table_id.database_name;
|
|
|
|
elem.table_name = table_id.table_name;
|
2018-09-13 12:48:46 +00:00
|
|
|
elem.partition_id = part->info.partition_id;
|
2019-01-31 17:30:56 +00:00
|
|
|
elem.part_name = part->name;
|
2019-09-03 11:32:25 +00:00
|
|
|
elem.path_on_disk = part->getFullPath();
|
2018-01-23 22:56:46 +00:00
|
|
|
|
2020-03-23 13:32:02 +00:00
|
|
|
elem.bytes_compressed_on_disk = part->getBytesOnDisk();
|
2018-05-21 13:49:54 +00:00
|
|
|
elem.rows = part->rows_count;
|
2018-01-23 22:56:46 +00:00
|
|
|
|
2018-05-21 13:49:54 +00:00
|
|
|
elem.error = static_cast<UInt16>(execution_status.code);
|
|
|
|
elem.exception = execution_status.message;
|
2018-01-23 22:56:46 +00:00
|
|
|
|
2018-05-21 13:49:54 +00:00
|
|
|
part_log->add(elem);
|
|
|
|
}
|
2018-01-23 22:56:46 +00:00
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
2020-05-30 21:57:37 +00:00
|
|
|
tryLogCurrentException(part_log ? part_log->log : &Poco::Logger::get("PartLog"), __PRETTY_FUNCTION__);
|
2018-01-23 22:56:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-03-07 17:13:54 +00:00
|
|
|
|
2018-01-23 22:56:46 +00:00
|
|
|
return true;
|
2017-06-25 00:01:10 +00:00
|
|
|
}
|
2017-03-07 17:13:54 +00:00
|
|
|
|
|
|
|
}
|