2012-06-25 00:17:19 +00:00
|
|
|
#pragma once
|
|
|
|
|
2015-01-25 05:07:51 +00:00
|
|
|
#include <map>
|
2013-07-16 14:55:01 +00:00
|
|
|
|
2017-06-06 17:18:32 +00:00
|
|
|
#include <ext/shared_ptr_helper.h>
|
2016-08-26 21:25:05 +00:00
|
|
|
|
2019-12-12 08:57:25 +00:00
|
|
|
#include <Core/Defines.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Storages/IStorage.h>
|
|
|
|
#include <Common/FileChecker.h>
|
|
|
|
#include <Common/escapeForFileName.h>
|
2012-06-25 00:17:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2017-06-25 00:17:08 +00:00
|
|
|
/** Implements a table engine that is suitable for small chunks of the log.
|
2017-04-16 15:00:33 +00:00
|
|
|
* It differs from StorageLog in the absence of mark files.
|
2012-06-25 00:17:19 +00:00
|
|
|
*/
|
2020-03-19 23:48:53 +00:00
|
|
|
class StorageTinyLog final : public ext::shared_ptr_helper<StorageTinyLog>, public IStorage
|
2012-06-25 00:17:19 +00:00
|
|
|
{
|
2020-02-17 14:45:10 +00:00
|
|
|
friend class TinyLogSource;
|
2019-12-12 08:57:25 +00:00
|
|
|
friend class TinyLogBlockOutputStream;
|
|
|
|
friend struct ext::shared_ptr_helper<StorageTinyLog>;
|
2012-06-25 00:17:19 +00:00
|
|
|
|
|
|
|
public:
|
2019-12-12 08:57:25 +00:00
|
|
|
String getName() const override { return "TinyLog"; }
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-08-03 13:54:14 +00:00
|
|
|
Pipe read(
|
2017-04-01 07:20:54 +00:00
|
|
|
const Names & column_names,
|
2020-06-15 19:08:58 +00:00
|
|
|
const StorageMetadataPtr & /*metadata_snapshot*/,
|
2020-09-20 17:52:17 +00:00
|
|
|
SelectQueryInfo & query_info,
|
2017-04-01 07:20:54 +00:00
|
|
|
const Context & context,
|
2018-04-19 14:47:09 +00:00
|
|
|
QueryProcessingStage::Enum processed_stage,
|
2019-02-18 23:38:44 +00:00
|
|
|
size_t max_block_size,
|
2017-06-02 15:54:39 +00:00
|
|
|
unsigned num_streams) override;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-06-15 19:08:58 +00:00
|
|
|
BlockOutputStreamPtr write(const ASTPtr & query, const StorageMetadataPtr & /*metadata_snapshot*/, const Context & context) override;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-04-07 14:05:51 +00:00
|
|
|
void rename(const String & new_path_to_table_data, const StorageID & new_table_id) override;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2019-07-03 13:17:19 +00:00
|
|
|
CheckResults checkData(const ASTPtr & /* query */, const Context & /* context */) override;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-11-01 17:38:43 +00:00
|
|
|
bool storesDataOnDisk() const override { return true; }
|
2019-12-12 08:57:25 +00:00
|
|
|
Strings getDataPaths() const override { return {DB::fullPath(disk, table_path)}; }
|
2020-12-22 16:40:53 +00:00
|
|
|
bool supportsSubcolumns() const override { return true; }
|
2014-08-29 18:44:44 +00:00
|
|
|
|
2020-06-18 16:10:47 +00:00
|
|
|
void truncate(const ASTPtr &, const StorageMetadataPtr & metadata_snapshot, const Context &, TableExclusiveLockHolder &) override;
|
2018-04-21 00:35:20 +00:00
|
|
|
|
2019-12-12 08:57:25 +00:00
|
|
|
protected:
|
|
|
|
StorageTinyLog(
|
|
|
|
DiskPtr disk_,
|
2019-12-26 14:03:32 +00:00
|
|
|
const String & relative_path_,
|
2020-01-13 11:41:42 +00:00
|
|
|
const StorageID & table_id_,
|
2019-12-12 08:57:25 +00:00
|
|
|
const ColumnsDescription & columns_,
|
|
|
|
const ConstraintsDescription & constraints_,
|
|
|
|
bool attach,
|
|
|
|
size_t max_compress_block_size_);
|
|
|
|
|
2012-06-25 00:17:19 +00:00
|
|
|
private:
|
2019-12-12 08:57:25 +00:00
|
|
|
struct ColumnData
|
|
|
|
{
|
2019-12-25 08:24:13 +00:00
|
|
|
String data_file_path;
|
2019-12-12 08:57:25 +00:00
|
|
|
};
|
2019-12-25 08:24:13 +00:00
|
|
|
using Files = std::map<String, ColumnData>; /// file name -> column data
|
2019-12-12 08:57:25 +00:00
|
|
|
|
|
|
|
DiskPtr disk;
|
2019-12-26 14:03:32 +00:00
|
|
|
String table_path;
|
2012-06-25 00:17:19 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t max_compress_block_size;
|
2014-03-28 14:36:24 +00:00
|
|
|
|
2019-12-12 08:57:25 +00:00
|
|
|
Files files;
|
2012-08-29 18:49:54 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
FileChecker file_checker;
|
2020-09-24 23:29:16 +00:00
|
|
|
mutable std::shared_timed_mutex rwlock;
|
2014-07-31 13:39:23 +00:00
|
|
|
|
2020-05-30 21:57:37 +00:00
|
|
|
Poco::Logger * log;
|
2014-07-31 13:39:23 +00:00
|
|
|
|
2020-09-14 11:22:17 +00:00
|
|
|
void addFiles(const NameAndTypePair & column);
|
2012-06-25 00:17:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|