2020-07-31 14:15:04 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Interpreters/SystemLog.h>
|
2022-01-10 19:01:41 +00:00
|
|
|
#include <Core/NamesAndTypes.h>
|
|
|
|
#include <Core/NamesAndAliases.h>
|
2023-04-06 17:00:51 +00:00
|
|
|
#include <Core/Field.h>
|
2024-01-12 15:39:22 +00:00
|
|
|
#include <Storages/ColumnsDescription.h>
|
2020-07-31 14:15:04 +00:00
|
|
|
|
2020-08-01 15:54:44 +00:00
|
|
|
|
|
|
|
/// Call this function on crash.
|
|
|
|
void collectCrashLog(Int32 signal, UInt64 thread_id, const String & query_id, const StackTrace & stack_trace);
|
|
|
|
|
|
|
|
|
2020-07-31 14:15:04 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/** Information about fatal errors that lead to crash.
|
|
|
|
* Before crash we are writing info into system table for further analysis.
|
|
|
|
*/
|
|
|
|
struct CrashLogElement
|
|
|
|
{
|
|
|
|
time_t event_time{};
|
|
|
|
UInt64 timestamp_ns{};
|
|
|
|
Int32 signal{};
|
|
|
|
UInt64 thread_id{};
|
|
|
|
String query_id;
|
|
|
|
Array trace;
|
|
|
|
Array trace_full;
|
|
|
|
|
|
|
|
static std::string name() { return "CrashLog"; }
|
2024-01-12 15:39:22 +00:00
|
|
|
static ColumnsDescription getColumnsDescription();
|
2021-06-28 11:42:21 +00:00
|
|
|
static NamesAndAliases getNamesAndAliases() { return {}; }
|
2020-07-31 14:15:04 +00:00
|
|
|
void appendToBlock(MutableColumns & columns) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CrashLog : public SystemLog<CrashLogElement>
|
|
|
|
{
|
|
|
|
using SystemLog<CrashLogElement>::SystemLog;
|
2020-08-01 15:54:44 +00:00
|
|
|
friend void ::collectCrashLog(Int32, UInt64, const String &, const StackTrace &);
|
2020-07-31 14:15:04 +00:00
|
|
|
|
|
|
|
static std::weak_ptr<CrashLog> crash_log;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static void initialize(std::shared_ptr<CrashLog> crash_log_)
|
|
|
|
{
|
2022-03-13 11:59:20 +00:00
|
|
|
crash_log = crash_log_;
|
2020-07-31 14:15:04 +00:00
|
|
|
}
|
2023-07-28 07:23:34 +00:00
|
|
|
|
|
|
|
static consteval size_t getDefaultMaxSize() { return 1024; }
|
|
|
|
static consteval size_t getDefaultReservedSize() { return 1024; }
|
|
|
|
static consteval size_t getDefaultFlushIntervalMilliseconds() { return 1000; }
|
|
|
|
static consteval size_t shouldNotifyFlushOnCrash() { return true; }
|
2020-07-31 14:15:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|