2015-08-16 07:01:41 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <map>
|
2017-07-28 17:34:02 +00:00
|
|
|
#include <shared_mutex>
|
2016-08-26 21:25:05 +00:00
|
|
|
|
2017-06-06 17:18:32 +00:00
|
|
|
#include <ext/shared_ptr_helper.h>
|
2016-08-26 21:25:05 +00:00
|
|
|
|
2015-08-16 07:01:41 +00:00
|
|
|
#include <Poco/File.h>
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Storages/IStorage.h>
|
|
|
|
#include <Common/FileChecker.h>
|
|
|
|
#include <Common/escapeForFileName.h>
|
2017-07-24 12:58:01 +00:00
|
|
|
#include <Core/Defines.h>
|
2015-08-16 07:01:41 +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
|
|
|
* In doing so, stores all the columns in a single Native file, with a nearby index.
|
2015-08-16 07:01:41 +00:00
|
|
|
*/
|
2017-06-06 18:36:13 +00:00
|
|
|
class StorageStripeLog : public ext::shared_ptr_helper<StorageStripeLog>, public IStorage
|
2015-08-16 07:01:41 +00:00
|
|
|
{
|
|
|
|
friend class StripeLogBlockInputStream;
|
|
|
|
friend class StripeLogBlockOutputStream;
|
2019-08-26 19:07:29 +00:00
|
|
|
friend struct ext::shared_ptr_helper<StorageStripeLog>;
|
2015-08-16 07:01:41 +00:00
|
|
|
|
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
std::string getName() const override { return "StripeLog"; }
|
2019-07-09 15:40:21 +00:00
|
|
|
std::string getTableName() const override { return table_name; }
|
|
|
|
std::string getDatabaseName() const override { return database_name; }
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
BlockInputStreams read(
|
|
|
|
const Names & column_names,
|
2017-07-15 03:48:36 +00:00
|
|
|
const 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
|
|
|
|
2019-02-27 18:26:24 +00:00
|
|
|
BlockOutputStreamPtr write(const ASTPtr & query, const Context & context) override;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2019-08-27 20:43:08 +00:00
|
|
|
void rename(const String & new_path_to_db, const String & new_database_name, const String & new_table_name, TableStructureWriteLockHolder &) 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
|
|
|
|
2017-04-16 15:00:33 +00:00
|
|
|
/// Data of the file.
|
2017-04-01 07:20:54 +00:00
|
|
|
struct ColumnData
|
|
|
|
{
|
|
|
|
Poco::File data_file;
|
|
|
|
};
|
|
|
|
using Files_t = std::map<String, ColumnData>;
|
|
|
|
|
2019-07-09 15:40:21 +00:00
|
|
|
std::string full_path() const { return path + escapeForFileName(table_name) + '/';}
|
2018-02-21 19:26:59 +00:00
|
|
|
|
2019-04-04 13:13:59 +00:00
|
|
|
Strings getDataPaths() const override { return {full_path()}; }
|
2015-08-16 07:01:41 +00:00
|
|
|
|
2019-08-27 20:43:08 +00:00
|
|
|
void truncate(const ASTPtr &, const Context &, TableStructureWriteLockHolder &) override;
|
2018-04-21 00:35:20 +00:00
|
|
|
|
2015-08-16 07:01:41 +00:00
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
String path;
|
2019-07-09 15:40:21 +00:00
|
|
|
String table_name;
|
|
|
|
String database_name;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
size_t max_compress_block_size;
|
|
|
|
|
|
|
|
FileChecker file_checker;
|
2017-07-28 17:34:02 +00:00
|
|
|
mutable std::shared_mutex rwlock;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
Logger * log;
|
|
|
|
|
2017-11-04 03:20:18 +00:00
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
StorageStripeLog(
|
|
|
|
const std::string & path_,
|
2019-07-09 15:40:21 +00:00
|
|
|
const std::string & database_name_,
|
|
|
|
const std::string & table_name_,
|
2018-03-06 20:18:34 +00:00
|
|
|
const ColumnsDescription & columns_,
|
2019-08-24 21:20:20 +00:00
|
|
|
const ConstraintsDescription & constraints_,
|
2017-04-01 07:20:54 +00:00
|
|
|
bool attach,
|
2017-12-30 03:49:02 +00:00
|
|
|
size_t max_compress_block_size_);
|
2015-08-16 07:01:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|