| 1 | #pragma once |
| 2 | |
| 3 | #include <map> |
| 4 | #include <shared_mutex> |
| 5 | |
| 6 | #include <ext/shared_ptr_helper.h> |
| 7 | |
| 8 | #include <Poco/File.h> |
| 9 | |
| 10 | #include <Storages/IStorage.h> |
| 11 | #include <Common/FileChecker.h> |
| 12 | #include <Common/escapeForFileName.h> |
| 13 | #include <Core/Defines.h> |
| 14 | |
| 15 | |
| 16 | namespace DB |
| 17 | { |
| 18 | |
| 19 | /** Implements a table engine that is suitable for small chunks of the log. |
| 20 | * In doing so, stores all the columns in a single Native file, with a nearby index. |
| 21 | */ |
| 22 | class StorageStripeLog : public ext::shared_ptr_helper<StorageStripeLog>, public IStorage |
| 23 | { |
| 24 | friend class StripeLogBlockInputStream; |
| 25 | friend class StripeLogBlockOutputStream; |
| 26 | friend struct ext::shared_ptr_helper<StorageStripeLog>; |
| 27 | |
| 28 | public: |
| 29 | std::string getName() const override { return "StripeLog" ; } |
| 30 | std::string getTableName() const override { return table_name; } |
| 31 | std::string getDatabaseName() const override { return database_name; } |
| 32 | |
| 33 | BlockInputStreams read( |
| 34 | const Names & column_names, |
| 35 | const SelectQueryInfo & query_info, |
| 36 | const Context & context, |
| 37 | QueryProcessingStage::Enum processed_stage, |
| 38 | size_t max_block_size, |
| 39 | unsigned num_streams) override; |
| 40 | |
| 41 | BlockOutputStreamPtr write(const ASTPtr & query, const Context & context) override; |
| 42 | |
| 43 | void rename(const String & new_path_to_table_data, const String & new_database_name, const String & new_table_name, TableStructureWriteLockHolder &) override; |
| 44 | |
| 45 | CheckResults checkData(const ASTPtr & /* query */, const Context & /* context */) override; |
| 46 | |
| 47 | /// Data of the file. |
| 48 | struct ColumnData |
| 49 | { |
| 50 | Poco::File data_file; |
| 51 | }; |
| 52 | using Files_t = std::map<String, ColumnData>; |
| 53 | |
| 54 | std::string fullPath() const { return path; } |
| 55 | |
| 56 | Strings getDataPaths() const override { return {fullPath()}; } |
| 57 | |
| 58 | void truncate(const ASTPtr &, const Context &, TableStructureWriteLockHolder &) override; |
| 59 | |
| 60 | private: |
| 61 | String base_path; |
| 62 | String path; |
| 63 | String table_name; |
| 64 | String database_name; |
| 65 | |
| 66 | size_t max_compress_block_size; |
| 67 | |
| 68 | FileChecker file_checker; |
| 69 | mutable std::shared_mutex rwlock; |
| 70 | |
| 71 | Logger * log; |
| 72 | |
| 73 | protected: |
| 74 | StorageStripeLog( |
| 75 | const std::string & relative_path_, |
| 76 | const std::string & database_name_, |
| 77 | const std::string & table_name_, |
| 78 | const ColumnsDescription & columns_, |
| 79 | const ConstraintsDescription & constraints_, |
| 80 | bool attach, |
| 81 | size_t max_compress_block_size_, |
| 82 | const Context & context_); |
| 83 | }; |
| 84 | |
| 85 | } |
| 86 | |