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