Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip unknown settings with warnings. #7653

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions dbms/programs/server/TCPHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,9 @@ void TCPHandler::receiveQuery()

/// Per query settings.
Settings & settings = query_context->getSettingsRef();
settings.deserialize(*in);
auto settings_format = (client_revision >= DBMS_MIN_REVISION_WITH_SETTINGS_SERIALIZED_AS_STRINGS) ? SettingsBinaryFormat::STRINGS
: SettingsBinaryFormat::OLD;
settings.deserialize(*in, settings_format);

/// Sync timeouts on client and server during current query to avoid dangling queries on server
/// NOTE: We use settings.send_timeout for the receive timeout and vice versa (change arguments ordering in TimeoutSetter),
Expand Down Expand Up @@ -953,7 +955,9 @@ void TCPHandler::receiveUnexpectedQuery()
skip_client_info.read(*in, client_revision);

Settings & skip_settings = query_context->getSettingsRef();
skip_settings.deserialize(*in);
auto settings_format = (client_revision >= DBMS_MIN_REVISION_WITH_SETTINGS_SERIALIZED_AS_STRINGS) ? SettingsBinaryFormat::STRINGS
: SettingsBinaryFormat::OLD;
skip_settings.deserialize(*in, settings_format);

readVarUInt(skip_uint_64, *in);
readVarUInt(skip_uint_64, *in);
Expand Down
6 changes: 5 additions & 1 deletion dbms/src/Client/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,11 @@ void Connection::sendQuery(

/// Per query settings.
if (settings)
settings->serialize(*out);
{
auto settings_format = (server_revision >= DBMS_MIN_REVISION_WITH_SETTINGS_SERIALIZED_AS_STRINGS) ? SettingsBinaryFormat::STRINGS
: SettingsBinaryFormat::OLD;
settings->serialize(*out, settings_format);
}
else
writeStringBinary("" /* empty string is a marker of the end of settings */, *out);

Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Common/ThreadStatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <Common/ProfileEvents.h>
#include <Common/MemoryTracker.h>

#include <Core/SettingsCommon.h>
#include <Core/SettingsCollection.h>

#include <IO/Progress.h>

Expand Down
10 changes: 6 additions & 4 deletions dbms/src/Core/Defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@
#define DBMS_MIN_REVISION_WITH_COLUMN_DEFAULTS_METADATA 54410

#define DBMS_MIN_REVISION_WITH_LOW_CARDINALITY_TYPE 54405

#define DBMS_MIN_REVISION_WITH_CLIENT_WRITE_INFO 54420

/// Mininum revision supporting SettingsBinaryFormat::STRINGS.
#define DBMS_MIN_REVISION_WITH_SETTINGS_SERIALIZED_AS_STRINGS 54429

/// Version of ClickHouse TCP protocol. Set to git tag with latest protocol change.
#define DBMS_TCP_PROTOCOL_VERSION 54226

Expand Down Expand Up @@ -148,9 +150,9 @@
#define OPTIMIZE(x)
#endif

/// This number is only used for distributed version compatible.
/// It could be any magic number.
#define DBMS_DISTRIBUTED_SENDS_MAGIC_NUMBER 0xCAFECABE
/// Marks that extra information is sent to a shard. It could be any magic numbers.
#define DBMS_DISTRIBUTED_SIGNATURE_EXTRA_INFO 0xCAFEDACEull
#define DBMS_DISTRIBUTED_SIGNATURE_SETTINGS_OLD_FORMAT 0xCAFECABEull

#if !__has_include(<sanitizer/asan_interface.h>)
# define ASAN_UNPOISON_MEMORY_REGION(a, b)
Expand Down
553 changes: 278 additions & 275 deletions dbms/src/Core/Settings.h

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#include "SettingsCommon.h"
#include <Core/SettingsCollection.h>
#include <Core/SettingsCollectionImpl.h>

#include <Core/Field.h>
#include <Common/getNumberOfPhysicalCPUCores.h>
#include <Common/FieldVisitors.h>
#include <common/logger_useful.h>
#include <IO/ReadHelpers.h>
#include <IO/ReadBufferFromString.h>
#include <IO/WriteHelpers.h>



namespace DB
{

namespace ErrorCodes
{
extern const int TYPE_MISMATCH;
Expand Down Expand Up @@ -90,22 +90,36 @@ void SettingNumber<bool>::set(const String & x)
}

template <typename Type>
void SettingNumber<Type>::serialize(WriteBuffer & buf) const
void SettingNumber<Type>::serialize(WriteBuffer & buf, SettingsBinaryFormat format) const
{
if (format >= SettingsBinaryFormat::STRINGS)
{
writeStringBinary(toString(), buf);
return;
}

if constexpr (is_integral_v<Type> && is_unsigned_v<Type>)
writeVarUInt(static_cast<UInt64>(value), buf);
else if constexpr (is_integral_v<Type> && is_signed_v<Type>)
writeVarInt(static_cast<Int64>(value), buf);
else
{
static_assert(std::is_floating_point_v<Type>);
writeBinary(toString(), buf);
writeStringBinary(toString(), buf);
}
}

template <typename Type>
void SettingNumber<Type>::deserialize(ReadBuffer & buf)
void SettingNumber<Type>::deserialize(ReadBuffer & buf, SettingsBinaryFormat format)
{
if (format >= SettingsBinaryFormat::STRINGS)
{
String x;
readStringBinary(x, buf);
set(x);
return;
}

if constexpr (is_integral_v<Type> && is_unsigned_v<Type>)
{
UInt64 x;
Expand All @@ -122,7 +136,7 @@ void SettingNumber<Type>::deserialize(ReadBuffer & buf)
{
static_assert(std::is_floating_point_v<Type>);
String x;
readBinary(x, buf);
readStringBinary(x, buf);
set(x);
}
}
Expand Down Expand Up @@ -167,13 +181,27 @@ void SettingMaxThreads::set(const String & x)
set(parse<UInt64>(x));
}

void SettingMaxThreads::serialize(WriteBuffer & buf) const
void SettingMaxThreads::serialize(WriteBuffer & buf, SettingsBinaryFormat format) const
{
if (format >= SettingsBinaryFormat::STRINGS)
{
writeStringBinary(is_auto ? "auto" : DB::toString(value), buf);
return;
}

writeVarUInt(is_auto ? 0 : value, buf);
}

void SettingMaxThreads::deserialize(ReadBuffer & buf)
void SettingMaxThreads::deserialize(ReadBuffer & buf, SettingsBinaryFormat format)
{
if (format >= SettingsBinaryFormat::STRINGS)
{
String x;
readStringBinary(x, buf);
set(x);
return;
}

UInt64 x = 0;
readVarUInt(x, buf);
set(x);
Expand Down Expand Up @@ -233,14 +261,28 @@ void SettingTimespan<io_unit>::set(const String & x)
}

template <SettingTimespanIO io_unit>
void SettingTimespan<io_unit>::serialize(WriteBuffer & buf) const
void SettingTimespan<io_unit>::serialize(WriteBuffer & buf, SettingsBinaryFormat format) const
{
if (format >= SettingsBinaryFormat::STRINGS)
{
writeStringBinary(toString(), buf);
return;
}

writeVarUInt(value.totalMicroseconds() / microseconds_per_io_unit, buf);
}

template <SettingTimespanIO io_unit>
void SettingTimespan<io_unit>::deserialize(ReadBuffer & buf)
void SettingTimespan<io_unit>::deserialize(ReadBuffer & buf, SettingsBinaryFormat format)
{
if (format >= SettingsBinaryFormat::STRINGS)
{
String x;
readStringBinary(x, buf);
set(x);
return;
}

UInt64 x = 0;
readVarUInt(x, buf);
set(x);
Expand Down Expand Up @@ -271,15 +313,15 @@ void SettingString::set(const Field & x)
set(safeGet<const String &>(x));
}

void SettingString::serialize(WriteBuffer & buf) const
void SettingString::serialize(WriteBuffer & buf, SettingsBinaryFormat) const
{
writeBinary(value, buf);
writeStringBinary(value, buf);
}

void SettingString::deserialize(ReadBuffer & buf)
void SettingString::deserialize(ReadBuffer & buf, SettingsBinaryFormat)
{
String s;
readBinary(s, buf);
readStringBinary(s, buf);
set(s);
}

Expand Down Expand Up @@ -314,30 +356,30 @@ void SettingChar::set(const Field & x)
set(s);
}

void SettingChar::serialize(WriteBuffer & buf) const
void SettingChar::serialize(WriteBuffer & buf, SettingsBinaryFormat) const
{
writeBinary(toString(), buf);
writeStringBinary(toString(), buf);
}

void SettingChar::deserialize(ReadBuffer & buf)
void SettingChar::deserialize(ReadBuffer & buf, SettingsBinaryFormat)
{
String s;
readBinary(s, buf);
readStringBinary(s, buf);
set(s);
}


template <typename EnumType, typename Tag>
void SettingEnum<EnumType, Tag>::serialize(WriteBuffer & buf) const
void SettingEnum<EnumType, Tag>::serialize(WriteBuffer & buf, SettingsBinaryFormat) const
{
writeBinary(toString(), buf);
writeStringBinary(toString(), buf);
}

template <typename EnumType, typename Tag>
void SettingEnum<EnumType, Tag>::deserialize(ReadBuffer & buf)
void SettingEnum<EnumType, Tag>::deserialize(ReadBuffer & buf, SettingsBinaryFormat)
{
String s;
readBinary(s, buf);
readStringBinary(s, buf);
set(s);
}

Expand Down Expand Up @@ -462,14 +504,43 @@ IMPLEMENT_SETTING_ENUM(LogsLevel, LOGS_LEVEL_LIST_OF_NAMES, ErrorCodes::BAD_ARGU

namespace details
{
void SettingsCollectionUtils::serializeName(const StringRef & name, WriteBuffer & buf)
{
writeStringBinary(name, buf);
}

String SettingsCollectionUtils::deserializeName(ReadBuffer & buf)
{
String name;
readBinary(name, buf);
readStringBinary(name, buf);
return name;
}

void SettingsCollectionUtils::serializeName(const StringRef & name, WriteBuffer & buf) { writeBinary(name, buf); }
void SettingsCollectionUtils::serializeFlag(bool flag, WriteBuffer & buf)
{
buf.write(flag);
}

bool SettingsCollectionUtils::deserializeFlag(ReadBuffer & buf)
{
char c;
buf.readStrict(c);
return c;
}

void SettingsCollectionUtils::skipValue(ReadBuffer & buf)
{
/// Ignore a string written by the function writeStringBinary().
UInt64 size;
readVarUInt(size, buf);
buf.ignore(size);
}

void SettingsCollectionUtils::warningNameNotFound(const StringRef & name)
{
static auto * log = &Logger::get("Settings");
LOG_WARNING(log, "Unknown setting " << name << ", skipping");
}

void SettingsCollectionUtils::throwNameNotFound(const StringRef & name)
{
Expand Down