Useless changes

This commit is contained in:
Alexey Milovidov 2024-05-09 02:07:04 +02:00
parent 95f12ef274
commit 1d69518c4d
37 changed files with 99 additions and 84 deletions

View File

@ -123,6 +123,14 @@ Checks: [
'-readability-uppercase-literal-suffix',
'-readability-use-anyofallof',
# These are new in clang-18, and we have to sort them out:
'-readability-avoid-nested-conditional-operator',
'-modernize-use-designated-initializers',
'-performance-enum-size',
'-readability-redundant-inline-specifier',
'-readability-redundant-member-init',
'-bugprone-crtp-constructor-accessibility',
'-zircon-*'
]

View File

@ -77,8 +77,7 @@ uint64_t getMemoryAmountOrZero()
{
uint64_t limit_v1;
if (limit_file_v1 >> limit_v1)
if (limit_v1 < memory_amount)
memory_amount = limit_v1;
memory_amount = std::min(memory_amount, limit_v1);
}
}

View File

@ -146,7 +146,7 @@ namespace impl
TUInt res;
if constexpr (sizeof(TUInt) == 1)
{
res = static_cast<UInt8>(unhexDigit(data[0])) * 0x10 + static_cast<UInt8>(unhexDigit(data[1]));
res = unhexDigit(data[0]) * 0x10 + unhexDigit(data[1]);
}
else if constexpr (sizeof(TUInt) == 2)
{

View File

@ -86,7 +86,10 @@ std::vector<String> KeeperClient::getCompletions(const String & prefix) const
void KeeperClient::askConfirmation(const String & prompt, std::function<void()> && callback)
{
if (!ask_confirmation)
return callback();
{
callback();
return;
}
std::cout << prompt << " Continue?\n";
waiting_confirmation = true;

View File

@ -149,12 +149,12 @@ public:
void popFirst()
{
return popFirst(1);
popFirst(1);
}
void pop_front() /// NOLINT
{
return popFirst();
popFirst();
}
void popLast(size_t parts_to_remove_size)
@ -172,7 +172,7 @@ public:
void popLast()
{
return popLast(1);
popLast(1);
}
void pop_back() /// NOLINT

View File

@ -649,7 +649,7 @@ void Connection::sendQuery(
bool with_pending_data,
std::function<void(const Progress &)>)
{
OpenTelemetry::SpanHolder span("Connection::sendQuery()", OpenTelemetry::CLIENT);
OpenTelemetry::SpanHolder span("Connection::sendQuery()", OpenTelemetry::SpanKind::CLIENT);
span.addAttribute("clickhouse.query_id", query_id_);
span.addAttribute("clickhouse.query", query);
span.addAttribute("target", [this] () { return this->getHost() + ":" + std::to_string(this->getPort()); });

View File

@ -100,7 +100,7 @@ public:
void updateHashWithValue(size_t n, SipHash & hash) const override
{
return getDictionary().updateHashWithValue(getIndexes().getUInt(n), hash);
getDictionary().updateHashWithValue(getIndexes().getUInt(n), hash);
}
void updateWeakHash32(WeakHash32 & hash) const override;
@ -154,7 +154,7 @@ public:
void getExtremes(Field & min, Field & max) const override
{
return dictionary.getColumnUnique().getNestedColumn()->index(getIndexes(), 0)->getExtremes(min, max); /// TODO: optimize
dictionary.getColumnUnique().getNestedColumn()->index(getIndexes(), 0)->getExtremes(min, max); /// TODO: optimize
}
void reserve(size_t n) override { idx.reserve(n); }
@ -208,7 +208,7 @@ public:
void getIndicesOfNonDefaultRows(Offsets & indices, size_t from, size_t limit) const override
{
return getIndexes().getIndicesOfNonDefaultRows(indices, from, limit);
getIndexes().getIndicesOfNonDefaultRows(indices, from, limit);
}
bool valuesHaveFixedSize() const override { return getDictionary().valuesHaveFixedSize(); }

View File

@ -87,7 +87,10 @@ public:
void free(char * ptr, const size_t size)
{
if (size > max_fixed_block_size)
return Allocator<false>::free(ptr, size);
{
Allocator<false>::free(ptr, size);
return;
}
/// find list of required size
const auto list_idx = findFreeListIndex(size);

View File

@ -46,14 +46,14 @@ size_t encodeBase58(const UInt8 * src, size_t src_length, UInt8 * dst)
size_t c_idx = idx >> 1;
for (size_t i = 0; i < c_idx; ++i)
{
char s = base58_encoding_alphabet[static_cast<UInt8>(dst[i])];
dst[i] = base58_encoding_alphabet[static_cast<UInt8>(dst[idx - (i + 1)])];
char s = base58_encoding_alphabet[dst[i]];
dst[i] = base58_encoding_alphabet[dst[idx - (i + 1)]];
dst[idx - (i + 1)] = s;
}
if ((idx & 1))
{
dst[c_idx] = base58_encoding_alphabet[static_cast<UInt8>(dst[c_idx])];
dst[c_idx] = base58_encoding_alphabet[dst[c_idx]];
}
return zeros + idx;
@ -105,7 +105,7 @@ std::optional<size_t> decodeBase58(const UInt8 * src, size_t src_length, UInt8 *
}
for (size_t j = 0; j < idx; ++j)
{
carry += static_cast<UInt8>(dst[j]) * 58;
carry += static_cast<UInt8>(dst[j] * 58);
dst[j] = static_cast<UInt8>(carry & 0xFF);
carry >>= 8;
}

View File

@ -1104,8 +1104,7 @@ public:
time -= values.amount_of_offset_change();
/// With cutoff at the time of the shift. Otherwise we may end up with something like 23:00 previous day.
if (time < values.time_at_offset_change())
time = values.time_at_offset_change();
time = std::max<Time>(time, values.time_at_offset_change());
}
}
else
@ -1250,7 +1249,7 @@ public:
DateComponents toDateComponents(Time t) const
{
const Values & values = getValues(t);
return { values.year, values.month, values.day_of_month };
return { .year = values.year, .month = values.month, .day = values.day_of_month };
}
DateTimeComponents toDateTimeComponents(Time t) const
@ -1350,10 +1349,7 @@ public:
UInt8 days_in_month = daysInMonth(year, month);
if (day_of_month > days_in_month)
day_of_month = days_in_month;
return day_of_month;
return std::min(day_of_month, days_in_month);
}
template <typename DateOrTime>

View File

@ -238,7 +238,7 @@ public:
private:
int saved_errno;
std::optional<std::string> path{};
std::optional<std::string> path;
const char * name() const noexcept override { return "DB::ErrnoException"; }
const char * className() const noexcept override { return "DB::ErrnoException"; }

View File

@ -53,7 +53,7 @@ public:
const auto & creator_map = getMap();
const auto & case_insensitive_creator_map = getCaseInsensitiveMap();
auto real_name_lowercase = Poco::toLower(real_name);
String real_name_lowercase = Poco::toLower(real_name);
if (!creator_map.contains(real_name) && !case_insensitive_creator_map.contains(real_name_lowercase))
throw Exception(
ErrorCodes::LOGICAL_ERROR,
@ -69,7 +69,6 @@ public:
void registerAliasUnchecked(const String & alias_name, const String & real_name, CaseSensitiveness case_sensitiveness = CaseSensitive)
{
String alias_name_lowercase = Poco::toLower(alias_name);
String real_name_lowercase = Poco::toLower(real_name);
const String factory_name = getFactoryName();
if (case_sensitiveness == CaseInsensitive)

View File

@ -74,7 +74,7 @@ PreformattedMessage FormatStringHelperImpl<Args...>::format(Args && ...args) con
{
std::vector<std::string> out_format_string_args;
std::string msg_text = tryGetArgsAndFormat(out_format_string_args, fmt_str, std::forward<Args>(args)...);
return PreformattedMessage{msg_text, message_format_string, out_format_string_args};
return PreformattedMessage{.text = msg_text, .format_string = message_format_string, .format_string_args = out_format_string_args};
}
template <typename... Args>

View File

@ -15,7 +15,7 @@ namespace OpenTelemetry
{
/// See https://opentelemetry.io/docs/reference/specification/trace/api/#spankind
enum SpanKind
enum class SpanKind : uint8_t
{
/// Default value. Indicates that the span represents an internal operation within an application,
/// as opposed to an operations with remote parents or children.
@ -39,13 +39,13 @@ enum SpanKind
struct Span
{
UUID trace_id{};
UUID trace_id;
UInt64 span_id = 0;
UInt64 parent_span_id = 0;
String operation_name;
UInt64 start_time_us = 0;
UInt64 finish_time_us = 0;
SpanKind kind = INTERNAL;
SpanKind kind = SpanKind::INTERNAL;
Map attributes;
/// Following methods are declared as noexcept to make sure they're exception safe.
@ -79,7 +79,7 @@ enum TraceFlags : UInt8
/// The runtime info we need to create new OpenTelemetry spans.
struct TracingContext
{
UUID trace_id{};
UUID trace_id;
UInt64 span_id = 0;
// The incoming tracestate header and the trace flags, we just pass them
// downstream. See https://www.w3.org/TR/trace-context/
@ -181,7 +181,7 @@ using TracingContextHolderPtr = std::unique_ptr<TracingContextHolder>;
/// Once it's created or destructed, it automatically maitains the tracing context on the thread that it lives.
struct SpanHolder : public Span
{
explicit SpanHolder(std::string_view, SpanKind _kind = INTERNAL);
explicit SpanHolder(std::string_view, SpanKind _kind = SpanKind::INTERNAL);
~SpanHolder();
/// Finish a span explicitly if needed.

View File

@ -11,7 +11,7 @@
namespace DB
{
inline constexpr size_t integerRoundUp(size_t value, size_t dividend)
constexpr size_t integerRoundUp(size_t value, size_t dividend)
{
return ((value + dividend - 1) / dividend) * dividend;
}

View File

@ -30,7 +30,7 @@ namespace ProfileEvents
class Timer
{
public:
enum class Resolution : UInt64
enum class Resolution : UInt32
{
Nanoseconds = 1,
Microseconds = 1000,

View File

@ -51,7 +51,7 @@ public:
explicit StackTrace(const ucontext_t & signal_context);
/// Creates empty object for deferred initialization
explicit inline StackTrace(NoCapture) {}
explicit StackTrace(NoCapture) {}
constexpr size_t getSize() const { return size; }
constexpr size_t getOffset() const { return offset; }

View File

@ -7,6 +7,9 @@
#include <cassert>
#include <atomic>
#include <memory>
#include <system_error>
#include <cerrno>
/// From clock_getres(2):
///
@ -22,7 +25,8 @@ static constexpr clockid_t STOPWATCH_DEFAULT_CLOCK = CLOCK_MONOTONIC;
inline UInt64 clock_gettime_ns(clockid_t clock_type = STOPWATCH_DEFAULT_CLOCK)
{
struct timespec ts;
clock_gettime(clock_type, &ts);
if (0 != clock_gettime(clock_type, &ts))
throw std::system_error(std::error_code(errno, std::system_category()));
return UInt64(ts.tv_sec * 1000000000LL + ts.tv_nsec);
}

View File

@ -154,16 +154,6 @@ inline bool isPunctuationASCII(char c)
}
inline bool isValidIdentifier(std::string_view str)
{
return !str.empty()
&& isValidIdentifierBegin(str[0])
&& std::all_of(str.begin() + 1, str.end(), isWordCharASCII)
/// NULL is not a valid identifier in SQL, any case.
&& !(str.size() == strlen("null") && 0 == strncasecmp(str.data(), "null", strlen("null")));
}
inline bool isNumberSeparator(bool is_start_of_block, bool is_hex, const char * pos, const char * end)
{
if (*pos != '_')
@ -329,3 +319,16 @@ constexpr bool containsGlobs(const std::string & str)
{
return str.find_first_of("*?{") != std::string::npos;
}
inline bool isValidIdentifier(std::string_view str)
{
return !str.empty()
&& isValidIdentifierBegin(str[0])
&& std::all_of(str.begin() + 1, str.end(), isWordCharASCII)
/// NULL is not a valid identifier in SQL, any case.
&& !(str.size() == strlen("null")
&& toLowerIfAlphaASCII(str[0]) == 'n'
&& toLowerIfAlphaASCII(str[1]) == 'u'
&& toLowerIfAlphaASCII(str[2]) == 'l'
&& toLowerIfAlphaASCII(str[3]) == 'l');
}

View File

@ -40,12 +40,12 @@ inline void futexWakeAll(std::atomic<UInt32> & address)
futexWake(&address, INT_MAX);
}
inline constexpr UInt32 lowerHalf(UInt64 value)
constexpr UInt32 lowerHalf(UInt64 value)
{
return static_cast<UInt32>(value & 0xffffffffull);
}
inline constexpr UInt32 upperHalf(UInt64 value)
constexpr UInt32 upperHalf(UInt64 value)
{
return static_cast<UInt32>(value >> 32ull);
}

View File

@ -13,7 +13,7 @@ inline NO_SANITIZE_UNDEFINED uint64_t intExp2(int x)
return 1ULL << x;
}
constexpr inline uint64_t intExp10(int x)
constexpr uint64_t intExp10(int x)
{
if (x < 0)
return 0;
@ -37,7 +37,7 @@ constexpr inline uint64_t intExp10(int x)
namespace common
{
constexpr inline int exp10_i32(int x)
constexpr int exp10_i32(int x)
{
if (x < 0)
return 0;
@ -60,7 +60,7 @@ constexpr inline int exp10_i32(int x)
return values[x];
}
constexpr inline int64_t exp10_i64(int x)
constexpr int64_t exp10_i64(int x)
{
if (x < 0)
return 0;
@ -92,7 +92,7 @@ constexpr inline int64_t exp10_i64(int x)
return values[x];
}
constexpr inline Int128 exp10_i128(int x)
constexpr Int128 exp10_i128(int x)
{
if (x < 0)
return 0;
@ -241,7 +241,7 @@ inline Int256 exp10_i256(int x)
/// intExp10 returning the type T.
template <typename T>
constexpr inline T intExp10OfSize(int x)
constexpr T intExp10OfSize(int x)
{
if constexpr (sizeof(T) <= 4)
return static_cast<T>(common::exp10_i32(x));

View File

@ -232,7 +232,7 @@ inline bool checkStringCaseInsensitive(const String & s, ReadBuffer & buf)
void assertStringCaseInsensitive(const char * s, ReadBuffer & buf);
inline void assertStringCaseInsensitive(const String & s, ReadBuffer & buf)
{
return assertStringCaseInsensitive(s.c_str(), buf);
assertStringCaseInsensitive(s.c_str(), buf);
}
/** Check that next character in buf matches first character of s.
@ -910,7 +910,7 @@ inline ReturnType readUUIDTextImpl(UUID & uuid, ReadBuffer & buf)
inline void readUUIDText(UUID & uuid, ReadBuffer & buf)
{
return readUUIDTextImpl<void>(uuid, buf);
readUUIDTextImpl<void>(uuid, buf);
}
inline bool tryReadUUIDText(UUID & uuid, ReadBuffer & buf)
@ -932,7 +932,7 @@ inline ReturnType readIPv4TextImpl(IPv4 & ip, ReadBuffer & buf)
inline void readIPv4Text(IPv4 & ip, ReadBuffer & buf)
{
return readIPv4TextImpl<void>(ip, buf);
readIPv4TextImpl<void>(ip, buf);
}
inline bool tryReadIPv4Text(IPv4 & ip, ReadBuffer & buf)
@ -954,7 +954,7 @@ inline ReturnType readIPv6TextImpl(IPv6 & ip, ReadBuffer & buf)
inline void readIPv6Text(IPv6 & ip, ReadBuffer & buf)
{
return readIPv6TextImpl<void>(ip, buf);
readIPv6TextImpl<void>(ip, buf);
}
inline bool tryReadIPv6Text(IPv6 & ip, ReadBuffer & buf)

View File

@ -109,8 +109,9 @@ inline void readVarUInt(UInt64 & x, ReadBuffer & istr)
inline void readVarUInt(UInt64 & x, ReadBuffer & istr)
{
if (istr.buffer().end() - istr.position() >= 10)
return varint_impl::readVarUInt<false>(x, istr);
return varint_impl::readVarUInt<true>(x, istr);
varint_impl::readVarUInt<false>(x, istr);
else
varint_impl::readVarUInt<true>(x, istr);
}
inline void readVarUInt(UInt64 & x, std::istream & istr)

View File

@ -37,11 +37,11 @@ protected:
void socketSendBytes(const char * ptr, size_t size);
void socketSendStr(const std::string & str)
{
return socketSendBytes(str.data(), str.size());
socketSendBytes(str.data(), str.size());
}
void socketSendStr(const char * ptr)
{
return socketSendBytes(ptr, strlen(ptr));
socketSendBytes(ptr, strlen(ptr));
}
Poco::Net::Socket & socket;

View File

@ -71,7 +71,7 @@ private:
{
vector.resize(
((position() - reinterpret_cast<Position>(vector.data())) /// NOLINT
+ sizeof(ValueType) - 1) /// Align up.
+ sizeof(ValueType) - 1) /// Align up. /// NOLINT
/ sizeof(ValueType));
/// Prevent further writes.

View File

@ -10,7 +10,7 @@ enum class CancellationCode : uint8_t
QueryIsNotInitializedYet = 1,
CancelCannotBeSent = 2,
CancelSent = 3,
Unknown
Unknown = 255
};
}

View File

@ -36,7 +36,7 @@ struct WithContextImpl
WithContextImpl() = default;
explicit WithContextImpl(Weak context_) : context(context_) {}
inline Shared getContext() const
Shared getContext() const
{
auto ptr = context.lock();
if (!ptr) throw Exception(ErrorCodes::LOGICAL_ERROR, "Context has expired");

View File

@ -569,7 +569,7 @@ void DDLWorker::processTask(DDLTaskBase & task, const ZooKeeperPtr & zookeeper)
OpenTelemetry::TracingContextHolder tracing_ctx_holder(__PRETTY_FUNCTION__,
task.entry.tracing_context,
this->context->getOpenTelemetrySpanLog());
tracing_ctx_holder.root_span.kind = OpenTelemetry::CONSUMER;
tracing_ctx_holder.root_span.kind = OpenTelemetry::SpanKind::CONSUMER;
String active_node_path = task.getActiveNodePath();
String finished_node_path = task.getFinishedNodePath();

View File

@ -20,11 +20,11 @@ ColumnsDescription OpenTelemetrySpanLogElement::getColumnsDescription()
auto span_kind_type = std::make_shared<DataTypeEnum8>(
DataTypeEnum8::Values
{
{"INTERNAL", static_cast<Int8>(OpenTelemetry::INTERNAL)},
{"SERVER", static_cast<Int8>(OpenTelemetry::SERVER)},
{"CLIENT", static_cast<Int8>(OpenTelemetry::CLIENT)},
{"PRODUCER", static_cast<Int8>(OpenTelemetry::PRODUCER)},
{"CONSUMER", static_cast<Int8>(OpenTelemetry::CONSUMER)}
{"INTERNAL", static_cast<Int8>(OpenTelemetry::SpanKind::INTERNAL)},
{"SERVER", static_cast<Int8>(OpenTelemetry::SpanKind::SERVER)},
{"CLIENT", static_cast<Int8>(OpenTelemetry::SpanKind::CLIENT)},
{"PRODUCER", static_cast<Int8>(OpenTelemetry::SpanKind::PRODUCER)},
{"CONSUMER", static_cast<Int8>(OpenTelemetry::SpanKind::CONSUMER)}
}
);

View File

@ -143,14 +143,14 @@ protected:
/// Container of PipelineExecutors to be cancelled when a cancelQuery is received
std::unordered_map<PipelineExecutor *, ExecutorHolderPtr> executors;
enum QueryStreamsStatus
enum class QueryStreamsStatus : uint8_t
{
NotInitialized,
Initialized,
Released
};
QueryStreamsStatus query_streams_status{NotInitialized};
QueryStreamsStatus query_streams_status{QueryStreamsStatus::NotInitialized};
ProcessListForUser * user_process_list = nullptr;

View File

@ -65,7 +65,7 @@ bool isSupportedAlterTypeForOnClusterDDLQuery(int type)
BlockIO executeDDLQueryOnCluster(const ASTPtr & query_ptr_, ContextPtr context, const DDLQueryOnClusterParams & params)
{
OpenTelemetry::SpanHolder span(__FUNCTION__, OpenTelemetry::PRODUCER);
OpenTelemetry::SpanHolder span(__FUNCTION__, OpenTelemetry::SpanKind::PRODUCER);
if (context->getCurrentTransaction() && context->getSettingsRef().throw_on_unsupported_query_inside_transaction)
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "ON CLUSTER queries inside transactions are not supported");

View File

@ -39,7 +39,7 @@ public:
QueryKind getQueryKind() const override { return QueryKind::Set; }
void appendColumnName(WriteBuffer & ostr) const override;
void appendColumnNameWithoutAlias(WriteBuffer & ostr) const override { return appendColumnName(ostr); }
void appendColumnNameWithoutAlias(WriteBuffer & ostr) const override { appendColumnName(ostr); }
};
}

View File

@ -873,7 +873,7 @@ namespace
query_context->getClientInfo().client_trace_context,
query_context->getSettingsRef(),
query_context->getOpenTelemetrySpanLog());
thread_trace_context->root_span.kind = OpenTelemetry::SERVER;
thread_trace_context->root_span.kind = OpenTelemetry::SpanKind::SERVER;
/// Prepare for sending exceptions and logs.
const Settings & settings = query_context->getSettingsRef();

View File

@ -132,12 +132,11 @@ protected:
void nextImpl() override
{
if (chunked)
return nextImplChunked();
if (fixed_length)
return nextImplFixedLength();
WriteBufferFromPocoSocket::nextImpl();
nextImplChunked();
else if (fixed_length)
nextImplFixedLength();
else
WriteBufferFromPocoSocket::nextImpl();
}
void nextImplFixedLength()

View File

@ -1108,7 +1108,7 @@ void HTTPHandler::handleRequest(HTTPServerRequest & request, HTTPServerResponse
client_trace_context,
context->getSettingsRef(),
context->getOpenTelemetrySpanLog());
thread_trace_context->root_span.kind = OpenTelemetry::SERVER;
thread_trace_context->root_span.kind = OpenTelemetry::SpanKind::SERVER;
thread_trace_context->root_span.addAttribute("clickhouse.uri", request.getURI());
response.setContentType("text/plain; charset=UTF-8");

View File

@ -384,7 +384,7 @@ void TCPHandler::runImpl()
query_context->getClientInfo().client_trace_context,
query_context->getSettingsRef(),
query_context->getOpenTelemetrySpanLog());
thread_trace_context->root_span.kind = OpenTelemetry::SERVER;
thread_trace_context->root_span.kind = OpenTelemetry::SpanKind::SERVER;
query_scope.emplace(query_context, /* fatal_error_callback */ [this]
{

View File

@ -100,7 +100,7 @@ public:
{
std::vector<std::string> paths_to_archives;
std::string path_in_archive; // used when reading a single file from archive
IArchiveReader::NameFilter filter = {}; // used when files inside archive are defined with a glob
IArchiveReader::NameFilter filter; // used when files inside archive are defined with a glob
bool isSingleFileRead() const
{