From 9bf62dd6220739e183208ee0152606bae7595efe Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Tue, 14 Nov 2023 07:43:11 +0100 Subject: [PATCH] Remove orphan header files --- src/Common/HashTable/FixedClearableHashMap.h | 75 ---------------- src/Common/SharedBlockRowRef.h | 89 ------------------- src/Common/SimpleActionBlocker.h | 79 ---------------- src/Common/SmallObjectPool.h | 52 ----------- src/Databases/DictionaryAttachInfo.h | 18 ---- .../ExternalLoaderDatabaseConfigRepository.h | 32 ------- .../Executors/IReadProgressCallback.h | 18 ---- src/Processors/Executors/traverse.h | 30 ------- src/Processors/QueueBuffer.h | 41 --------- utils/check-style/check-style | 4 + 10 files changed, 4 insertions(+), 434 deletions(-) delete mode 100644 src/Common/HashTable/FixedClearableHashMap.h delete mode 100644 src/Common/SharedBlockRowRef.h delete mode 100644 src/Common/SimpleActionBlocker.h delete mode 100644 src/Common/SmallObjectPool.h delete mode 100644 src/Databases/DictionaryAttachInfo.h delete mode 100644 src/Interpreters/ExternalLoaderDatabaseConfigRepository.h delete mode 100644 src/Processors/Executors/IReadProgressCallback.h delete mode 100644 src/Processors/Executors/traverse.h delete mode 100644 src/Processors/QueueBuffer.h diff --git a/src/Common/HashTable/FixedClearableHashMap.h b/src/Common/HashTable/FixedClearableHashMap.h deleted file mode 100644 index 6be7fde88b5..00000000000 --- a/src/Common/HashTable/FixedClearableHashMap.h +++ /dev/null @@ -1,75 +0,0 @@ -#pragma once - -#include -#include - - -template -struct FixedClearableHashMapCell -{ - using Mapped = TMapped; - using State = ClearableHashSetState; - - using value_type = PairNoInit; - using mapped_type = Mapped; - - UInt32 version; - Mapped mapped; - - FixedClearableHashMapCell() {} /// NOLINT - FixedClearableHashMapCell(const Key &, const State & state) : version(state.version) {} - FixedClearableHashMapCell(const value_type & value_, const State & state) : version(state.version), mapped(value_.second) {} - - const VoidKey getKey() const { return {}; } /// NOLINT - Mapped & getMapped() { return mapped; } - const Mapped & getMapped() const { return mapped; } - - bool isZero(const State & state) const { return version != state.version; } - void setZero() { version = 0; } - - struct CellExt - { - CellExt() {} /// NOLINT - CellExt(Key && key_, FixedClearableHashMapCell * ptr_) : key(key_), ptr(ptr_) {} - void update(Key && key_, FixedClearableHashMapCell * ptr_) - { - key = key_; - ptr = ptr_; - } - Key key; - FixedClearableHashMapCell * ptr; - const Key & getKey() const { return key; } - Mapped & getMapped() { return ptr->mapped; } - const Mapped & getMapped() const { return *ptr->mapped; } - const value_type getValue() const { return {key, *ptr->mapped}; } /// NOLINT - }; -}; - - -template -class FixedClearableHashMap : public FixedHashMap, Allocator> -{ -public: - using Base = FixedHashMap, Allocator>; - using Self = FixedClearableHashMap; - using LookupResult = typename Base::LookupResult; - - using Base::Base; - - Mapped & operator[](const Key & x) - { - LookupResult it; - bool inserted; - this->emplace(x, it, inserted); - if (inserted) - new (&it->getMapped()) Mapped(); - - return it->getMapped(); - } - - void clear() - { - ++this->version; - this->m_size = 0; - } -}; diff --git a/src/Common/SharedBlockRowRef.h b/src/Common/SharedBlockRowRef.h deleted file mode 100644 index 77dd0f1cc13..00000000000 --- a/src/Common/SharedBlockRowRef.h +++ /dev/null @@ -1,89 +0,0 @@ -#pragma once - -#include -#include -#include -#include - - -namespace DB -{ - -/// Allows you refer to the row in the block and hold the block ownership, -/// and thus avoid creating a temporary row object. -/// Do not use std::shared_ptr, since there is no need for a place for `weak_count` and `deleter`; -/// does not use Poco::SharedPtr, since you need to allocate a block and `refcount` in one piece; -/// does not use Poco::AutoPtr, since it does not have a `move` constructor and there are extra checks for nullptr; -/// The reference counter is not atomic, since it is used from one thread. -namespace detail -{ - struct SharedBlock : Block - { - int refcount = 0; - - ColumnRawPtrs all_columns; - ColumnRawPtrs sort_columns; - - explicit SharedBlock(Block && block) : Block(std::move(block)) {} - }; -} - -inline void intrusive_ptr_add_ref(detail::SharedBlock * ptr) -{ - ++ptr->refcount; -} - -inline void intrusive_ptr_release(detail::SharedBlock * ptr) -{ - if (0 == --ptr->refcount) - delete ptr; -} - -using SharedBlockPtr = boost::intrusive_ptr; - -struct SharedBlockRowRef -{ - ColumnRawPtrs * columns = nullptr; - size_t row_num = 0; - SharedBlockPtr shared_block; - - void swap(SharedBlockRowRef & other) - { - std::swap(columns, other.columns); - std::swap(row_num, other.row_num); - std::swap(shared_block, other.shared_block); - } - - /// The number and types of columns must match. - bool operator==(const SharedBlockRowRef & other) const - { - size_t size = columns->size(); - for (size_t i = 0; i < size; ++i) - if (0 != (*columns)[i]->compareAt(row_num, other.row_num, *(*other.columns)[i], 1)) - return false; - return true; - } - - bool operator!=(const SharedBlockRowRef & other) const - { - return !(*this == other); - } - - void reset() - { - SharedBlockRowRef empty; - swap(empty); - } - - bool empty() const { return columns == nullptr; } - size_t size() const { return empty() ? 0 : columns->size(); } - - void set(SharedBlockPtr & shared_block_, ColumnRawPtrs * columns_, size_t row_num_) - { - shared_block = shared_block_; - columns = columns_; - row_num = row_num_; - } -}; - -} diff --git a/src/Common/SimpleActionBlocker.h b/src/Common/SimpleActionBlocker.h deleted file mode 100644 index 4a96db0e09d..00000000000 --- a/src/Common/SimpleActionBlocker.h +++ /dev/null @@ -1,79 +0,0 @@ -#pragma once -#include - - -namespace DB -{ - -class SimpleActionLock; - - -/// Similar to ActionBlocker, but without weak_ptr magic -class SimpleActionBlocker -{ - using Counter = std::atomic; - Counter counter = 0; - -public: - - SimpleActionBlocker() = default; - - bool isCancelled() const { return counter > 0; } - - /// Temporarily blocks corresponding actions (while the returned object is alive) - friend class SimpleActionLock; - inline SimpleActionLock cancel(); - - /// Cancel the actions forever. - void cancelForever() { ++counter; } -}; - - -/// Blocks related action while a SimpleActionLock instance exists -class SimpleActionLock -{ - SimpleActionBlocker * block = nullptr; - -public: - - SimpleActionLock() = default; - - explicit SimpleActionLock(SimpleActionBlocker & block_) : block(&block_) - { - ++block->counter; - } - - SimpleActionLock(const SimpleActionLock &) = delete; - - SimpleActionLock(SimpleActionLock && rhs) noexcept - { - *this = std::move(rhs); - } - - SimpleActionLock & operator=(const SimpleActionLock &) = delete; - - SimpleActionLock & operator=(SimpleActionLock && rhs) noexcept - { - if (block) - --block->counter; - - block = rhs.block; - rhs.block = nullptr; - - return *this; - } - - ~SimpleActionLock() - { - if (block) - --block->counter; - } -}; - - -SimpleActionLock SimpleActionBlocker::cancel() -{ - return SimpleActionLock(*this); -} - -} diff --git a/src/Common/SmallObjectPool.h b/src/Common/SmallObjectPool.h deleted file mode 100644 index 4d56a92a419..00000000000 --- a/src/Common/SmallObjectPool.h +++ /dev/null @@ -1,52 +0,0 @@ -#pragma once - -#include -#include - - -namespace DB -{ - -/** Can allocate memory objects of fixed size with deletion support. - * For small `object_size`s allocated no less than pointer size. - */ -class SmallObjectPool -{ -private: - const size_t object_size; - Arena pool; - char * free_list = nullptr; - -public: - explicit SmallObjectPool(size_t object_size_) - : object_size{std::max(object_size_, sizeof(char *))} - { - } - - char * alloc() - { - if (free_list) - { - char * res = free_list; - free_list = unalignedLoad(free_list); - return res; - } - - return pool.alloc(object_size); - } - - void free(char * ptr) - { - unalignedStore(ptr, free_list); - free_list = ptr; - } - - /// The size of the allocated pool in bytes - size_t size() const - { - return pool.size(); - } - -}; - -} diff --git a/src/Databases/DictionaryAttachInfo.h b/src/Databases/DictionaryAttachInfo.h deleted file mode 100644 index b2214d26f3c..00000000000 --- a/src/Databases/DictionaryAttachInfo.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include -#include -#include - - -namespace DB -{ - -struct DictionaryAttachInfo -{ - ASTPtr create_query; - Poco::AutoPtr config; - time_t modification_time; -}; - -} diff --git a/src/Interpreters/ExternalLoaderDatabaseConfigRepository.h b/src/Interpreters/ExternalLoaderDatabaseConfigRepository.h deleted file mode 100644 index b8dd6e278ad..00000000000 --- a/src/Interpreters/ExternalLoaderDatabaseConfigRepository.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include -#include - - -namespace DB -{ - -/// Repository from database, which stores dictionary definitions on disk. -/// Tracks update time and existence of .sql files through IDatabase. -class ExternalLoaderDatabaseConfigRepository : public IExternalLoaderConfigRepository, WithContext -{ -public: - ExternalLoaderDatabaseConfigRepository(IDatabase & database_, ContextPtr global_context_); - - std::string getName() const override { return database_name; } - - std::set getAllLoadablesDefinitionNames() override; - - bool exists(const std::string & loadable_definition_name) override; - - Poco::Timestamp getUpdateTime(const std::string & loadable_definition_name) override; - - LoadablesConfigurationPtr load(const std::string & loadable_definition_name) override; - -private: - const String database_name; - IDatabase & database; -}; - -} diff --git a/src/Processors/Executors/IReadProgressCallback.h b/src/Processors/Executors/IReadProgressCallback.h deleted file mode 100644 index 75a75eeb61d..00000000000 --- a/src/Processors/Executors/IReadProgressCallback.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once -#include - -namespace DB -{ - -/// An interface for read progress callback. -class IReadProgressCallback -{ -public: - virtual ~IReadProgressCallback() = default; - virtual bool onProgress(uint64_t read_rows, uint64_t read_bytes) = 0; -}; - -using ReadProgressCallbackPtr = std::unique_ptr; - - -} diff --git a/src/Processors/Executors/traverse.h b/src/Processors/Executors/traverse.h deleted file mode 100644 index 2fd89adcb43..00000000000 --- a/src/Processors/Executors/traverse.h +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once - -#include - - -namespace DB -{ - -/// Look for first Ready or Async processor by depth-first search in needed input ports and full output ports. -/// NOTE: Pipeline must not have cycles. -//template -//void traverse(IProcessor & processor, Visit && visit) -//{ -// IProcessor::Status status = visit(processor); -// -// if (status == IProcessor::Status::Ready || status == IProcessor::Status::Async) -// return; -// -// if (status == IProcessor::Status::NeedData) -// for (auto & input : processor.getInputs()) -// if (input.isNeeded() && !input.hasData()) -// traverse(input.getOutputPort().getProcessor(), std::forward(visit)); -// -// if (status == IProcessor::Status::PortFull) -// for (auto & output : processor.getOutputs()) -// if (output.hasData()) -// traverse(output.getInputPort().getProcessor(), std::forward(visit)); -//} - -} diff --git a/src/Processors/QueueBuffer.h b/src/Processors/QueueBuffer.h deleted file mode 100644 index 0736d6fbf43..00000000000 --- a/src/Processors/QueueBuffer.h +++ /dev/null @@ -1,41 +0,0 @@ -#pragma once - -#include -#include - - -namespace DB -{ - -/** Reads all data into queue. - * After all data has been read - output it in the same order. - */ -class QueueBuffer final : public IAccumulatingTransform -{ -private: - std::queue chunks; -public: - String getName() const override { return "QueueBuffer"; } - - explicit QueueBuffer(Block header) - : IAccumulatingTransform(header, header) - { - } - - void consume(Chunk block) override - { - chunks.push(std::move(block)); - } - - Chunk generate() override - { - if (chunks.empty()) - return {}; - - auto res = std::move(chunks.front()); - chunks.pop(); - return res; - } -}; - -} diff --git a/utils/check-style/check-style b/utils/check-style/check-style index f87d2e292b5..5076c737cd9 100755 --- a/utils/check-style/check-style +++ b/utils/check-style/check-style @@ -422,3 +422,7 @@ find $ROOT_PATH/{src,programs,utils} -name '*.h' -or -name '*.cpp' | xargs grep # Cyrillic characters hiding inside Latin. find $ROOT_PATH/{src,programs,utils} -name '*.h' -or -name '*.cpp' | xargs grep -P --line-number '[a-zA-Z][а-яА-ЯёЁ]|[а-яА-ЯёЁ][a-zA-Z]' && echo "^ Cyrillic characters found in unexpected place." + +# Orphaned header files. +join -v1 <(find $ROOT_PATH/{src,programs,utils} -name '*.h' -printf '%f\n' | sort | uniq) <(find $ROOT_PATH/{src,programs,utils} -name '*.cpp' -or -name '*.c' -or -name '*.h' -or -name '*.S' | xargs grep --no-filename -o -P '[\w-]+\.h' | sort | uniq) | + grep . && echo '^ Found orphan header files.'