slightly better

This commit is contained in:
Anton Popov 2022-10-04 14:19:05 +00:00
parent 9a2cabd3a1
commit 121ef74b17
5 changed files with 21 additions and 14 deletions

View File

@ -56,17 +56,17 @@ private:
std::atomic<const DateLUTImpl *> default_impl;
};
static inline UInt64 timeInMilliseconds(std::chrono::time_point<std::chrono::system_clock> timepoint)
inline UInt64 timeInMilliseconds(std::chrono::time_point<std::chrono::system_clock> timepoint)
{
return std::chrono::duration_cast<std::chrono::milliseconds>(timepoint.time_since_epoch()).count();
}
static inline UInt64 timeInMicroseconds(std::chrono::time_point<std::chrono::system_clock> timepoint)
inline UInt64 timeInMicroseconds(std::chrono::time_point<std::chrono::system_clock> timepoint)
{
return std::chrono::duration_cast<std::chrono::microseconds>(timepoint.time_since_epoch()).count();
}
static inline UInt64 timeInSeconds(std::chrono::time_point<std::chrono::system_clock> timepoint)
inline UInt64 timeInSeconds(std::chrono::time_point<std::chrono::system_clock> timepoint)
{
return std::chrono::duration_cast<std::chrono::seconds>(timepoint.time_since_epoch()).count();
}

View File

@ -19,7 +19,7 @@ NamesAndTypesList AsynchronousInsertLogElement::getNamesAndTypes()
auto type_status = std::make_shared<DataTypeEnum8>(
DataTypeEnum8::Values
{
{"Ok", static_cast<Int8>(Status::Ok)},
{"Ok", static_cast<Int8>(Status::Ok)},
{"ParsingError", static_cast<Int8>(Status::ParsingError)},
{"FlushError", static_cast<Int8>(Status::FlushError)},
});
@ -64,8 +64,8 @@ void AsynchronousInsertLogElement::appendToBlock(MutableColumns & columns) const
}
else
{
columns[i++]->insert(insert_query.table_id.getDatabaseName());
columns[i++]->insert(insert_query.table_id.getTableName());
columns[i++]->insertDefault();
columns[i++]->insertDefault();
}
columns[i++]->insert(insert_query.format);

View File

@ -11,11 +11,11 @@ namespace DB
struct AsynchronousInsertLogElement
{
enum Status
enum Status : Int8
{
Ok,
ParsingError,
FlushError,
Ok = 0,
ParsingError = 1,
FlushError = 2,
};
time_t event_time{};
@ -23,15 +23,15 @@ struct AsynchronousInsertLogElement
ASTPtr query;
String query_id;
UInt64 bytes;
UInt64 bytes{};
String exception;
Status status;
Status status{};
time_t flush_time{};
Decimal64 flush_time_microseconds{};
String flush_query_id;
static std::string name() { return "AsynchronousInserts"; }
static std::string name() { return "AsynchronousInsertLog"; }
static NamesAndTypesList getNamesAndTypes();
static NamesAndAliases getNamesAndAliases() { return {}; }
void appendToBlock(MutableColumns & columns) const;

View File

@ -1,3 +1,5 @@
5
Values 21 1 Ok 1
t_async_inserts_logs JSONEachRow 39 1 Ok 1
t_async_inserts_logs Values 8 1 Ok 1
t_async_inserts_logs JSONEachRow 6 0 ParsingError 1

View File

@ -15,6 +15,8 @@ ${CLICKHOUSE_CURL} -sS "$url" -d "INSERT INTO t_async_inserts_logs VALUES (1, 'a
${CLICKHOUSE_CURL} -sS "$url" -d 'INSERT INTO t_async_inserts_logs FORMAT JSONEachRow qqqqqq' > /dev/null 2>&1 &
${CLICKHOUSE_CURL} -sS "$url" -d 'INSERT INTO t_async_inserts_logs VALUES qqqqqq' > /dev/null 2>&1 &
${CLICKHOUSE_CURL} -sS "$url" -d "INSERT INTO FUNCTION remote('127.0.0.1', currentDatabase(), t_async_inserts_logs) VALUES (1, 'aaa') (2, 'bbb')" &
wait
${CLICKHOUSE_CLIENT} -q "OPTIMIZE TABLE t_async_inserts_logs FINAL"
@ -24,11 +26,14 @@ ${CLICKHOUSE_CURL} -sS "$url" -d "INSERT INTO t_async_inserts_logs VALUES (1, 'a
wait
${CLICKHOUSE_CLIENT} -q "SELECT count() FROM t_async_inserts_logs"
${CLICKHOUSE_CLIENT} -q "SYSTEM FLUSH LOGS"
${CLICKHOUSE_CLIENT} -q "
SELECT table, format, bytes, empty(exception), status,
status = 'ParsingError' ? flush_time_microseconds = 0 : flush_time_microseconds > event_time_microseconds AS time_ok
FROM system.asynchronous_insert_log WHERE database = '$CLICKHOUSE_DATABASE'
FROM system.asynchronous_insert_log
WHERE database = '$CLICKHOUSE_DATABASE' OR query ILIKE 'INSERT INTO FUNCTION%$CLICKHOUSE_DATABASE%'
ORDER BY table, status, format"
${CLICKHOUSE_CLIENT} -q "DROP TABLE t_async_inserts_logs"