Merge pull request #63656 from woodlzm/master

Add a build_id ALIAS column to trace_log to facilitate auto renaming upon detecting binary changes.
This commit is contained in:
Alexey Milovidov 2024-05-17 04:32:26 +00:00 committed by GitHub
commit 0c84c5658c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 124 additions and 1 deletions

View File

@ -8,6 +8,7 @@
#include <DataTypes/DataTypeDateTime64.h>
#include <DataTypes/DataTypeLowCardinality.h>
#include <Common/ClickHouseRevision.h>
#include <Common/SymbolIndex.h>
namespace DB
@ -53,6 +54,18 @@ ColumnsDescription TraceLogElement::getColumnsDescription()
};
}
NamesAndAliases TraceLogElement::getNamesAndAliases()
{
String build_id_hex;
#if defined(__ELF__) && !defined(OS_FREEBSD)
build_id_hex = SymbolIndex::instance().getBuildIDHex();
#endif
return
{
{"build_id", std::make_shared<DataTypeString>(), "\'" + build_id_hex + "\'"},
};
}
void TraceLogElement::appendToBlock(MutableColumns & columns) const
{
size_t i = 0;

View File

@ -39,7 +39,7 @@ struct TraceLogElement
static std::string name() { return "TraceLog"; }
static ColumnsDescription getColumnsDescription();
static NamesAndAliases getNamesAndAliases() { return {}; }
static NamesAndAliases getNamesAndAliases();
void appendToBlock(MutableColumns & columns) const;
};

View File

@ -0,0 +1,98 @@
import pytest
from helpers.cluster import ClickHouseCluster, CLICKHOUSE_CI_MIN_TESTED_VERSION
TEST_QUERY_ID = "test_trace_log_build_id_query_{}"
OLD_TEST_QUERY_ID = TEST_QUERY_ID.format("0")
NEW_TEST_QUERY_ID = TEST_QUERY_ID.format("1")
ACTIVE_TRACE_LOG_TABLE = "trace_log"
RENAMED_TRACE_LOG_TABLE = "trace_log_0"
cluster = ClickHouseCluster(__file__)
node = cluster.add_instance(
"node",
with_zookeeper=True,
image="clickhouse/clickhouse-server",
tag=CLICKHOUSE_CI_MIN_TESTED_VERSION,
stay_alive=True,
with_installed_binary=True,
)
sanitizer_check_node = cluster.add_instance("sanitizer_check_node")
@pytest.fixture(scope="module")
def started_cluster():
try:
cluster.start()
yield cluster
except Exception as ex:
print(ex)
finally:
cluster.shutdown()
def test_trace_log_build_id(started_cluster):
# This test checks that build_id column of system_log.trace_log is non-empty, and gets renamed when binary version changes.
# We make queries to create entries in trace_log, then restart with new version and verify if the old
# trace_log table is renamed and a new trace_log table is created.
if sanitizer_check_node.is_built_with_sanitizer():
pytest.skip(
"Sanitizers are skipped, because trace_log is disabled with sanitizers."
)
query_for_table_name = "EXISTS TABLE system.{table}"
node.query(
"SELECT sleep(2)",
query_id=OLD_TEST_QUERY_ID,
)
node.query("SYSTEM FLUSH LOGS")
assert (
node.query(query_for_table_name.format(table=ACTIVE_TRACE_LOG_TABLE)) == "1\n"
)
assert (
node.query(query_for_table_name.format(table=RENAMED_TRACE_LOG_TABLE)) == "0\n"
)
node.restart_with_latest_version()
query_for_test_query_id = """
SELECT EXISTS
(
SELECT *
FROM system.{table}
WHERE query_id = \'{query_id}\'
)
"""
node.query(
"SELECT sleep(2)",
query_id=NEW_TEST_QUERY_ID,
)
node.query("SYSTEM FLUSH LOGS")
assert (
node.query(
query_for_test_query_id.format(
table=ACTIVE_TRACE_LOG_TABLE, query_id=OLD_TEST_QUERY_ID
)
)
== "0\n"
)
assert (
node.query(
query_for_test_query_id.format(
table=ACTIVE_TRACE_LOG_TABLE, query_id=NEW_TEST_QUERY_ID
)
)
== "1\n"
)
assert (
node.query(
query_for_test_query_id.format(
table=RENAMED_TRACE_LOG_TABLE, query_id=OLD_TEST_QUERY_ID
)
)
== "1\n"
)

View File

@ -0,0 +1,2 @@
0
1

View File

@ -0,0 +1,10 @@
-- Tags: no-asan, no-tsan, no-msan, no-ubsan, no-sanitize-coverage
SET log_queries = 1;
SET log_query_threads = 1;
SET query_profiler_real_time_period_ns = 100000000;
SELECT sleep(1);
SYSTEM FLUSH LOGS;
SELECT COUNT(*) > 1 FROM system.trace_log WHERE build_id IS NOT NULL;