2016-10-25 06:49:24 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
2018-05-09 04:22:30 +00:00
|
|
|
#include <errno.h>
|
2016-10-25 06:49:24 +00:00
|
|
|
|
2015-08-16 07:01:41 +00:00
|
|
|
#include <map>
|
2017-11-20 04:15:43 +00:00
|
|
|
#include <optional>
|
2015-08-16 07:01:41 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Common/escapeForFileName.h>
|
|
|
|
#include <Common/Exception.h>
|
2015-08-16 07:01:41 +00:00
|
|
|
|
2020-02-20 16:39:32 +00:00
|
|
|
#include <IO/WriteBufferFromFileBase.h>
|
2018-12-28 18:15:26 +00:00
|
|
|
#include <Compression/CompressedReadBufferFromFile.h>
|
|
|
|
#include <Compression/CompressedWriteBuffer.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <IO/ReadHelpers.h>
|
|
|
|
#include <IO/WriteHelpers.h>
|
2015-08-16 07:01:41 +00:00
|
|
|
|
2019-01-23 14:48:50 +00:00
|
|
|
#include <DataStreams/IBlockInputStream.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <DataStreams/IBlockOutputStream.h>
|
|
|
|
#include <DataStreams/NativeBlockInputStream.h>
|
|
|
|
#include <DataStreams/NativeBlockOutputStream.h>
|
|
|
|
#include <DataStreams/NullBlockInputStream.h>
|
2015-08-16 07:01:41 +00:00
|
|
|
|
2018-02-18 03:23:48 +00:00
|
|
|
#include <DataTypes/DataTypeFactory.h>
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Columns/ColumnArray.h>
|
2015-08-16 07:01:41 +00:00
|
|
|
|
2017-05-24 21:06:29 +00:00
|
|
|
#include <Interpreters/Context.h>
|
2017-01-21 04:24:28 +00:00
|
|
|
|
2020-02-14 14:28:33 +00:00
|
|
|
#include <Interpreters/evaluateConstantExpression.h>
|
|
|
|
#include <Parsers/ASTLiteral.h>
|
2017-12-30 00:36:06 +00:00
|
|
|
#include <Storages/StorageFactory.h>
|
2020-02-14 14:28:33 +00:00
|
|
|
#include <Storages/StorageStripeLog.h>
|
2020-02-18 14:41:30 +00:00
|
|
|
#include "StorageLogSettings.h"
|
2020-02-14 10:57:09 +00:00
|
|
|
#include <Processors/Sources/SourceWithProgress.h>
|
|
|
|
#include <Processors/Sources/NullSource.h>
|
|
|
|
#include <Processors/Pipe.h>
|
2015-08-16 07:01:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
#define INDEX_BUFFER_SIZE 4096
|
|
|
|
|
2016-01-11 21:46:36 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
2017-12-30 00:36:06 +00:00
|
|
|
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
|
2017-11-03 19:53:10 +00:00
|
|
|
extern const int INCORRECT_FILE_NAME;
|
2016-01-11 21:46:36 +00:00
|
|
|
}
|
|
|
|
|
2015-08-16 07:01:41 +00:00
|
|
|
|
2020-02-14 10:57:09 +00:00
|
|
|
class StripeLogSource final : public SourceWithProgress
|
2015-08-16 07:01:41 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-02-14 10:57:09 +00:00
|
|
|
|
|
|
|
static Block getHeader(
|
|
|
|
StorageStripeLog & storage,
|
2020-06-16 14:25:08 +00:00
|
|
|
const StorageMetadataPtr & metadata_snapshot,
|
2020-02-14 10:57:09 +00:00
|
|
|
const Names & column_names,
|
|
|
|
IndexForNativeFormat::Blocks::const_iterator index_begin,
|
|
|
|
IndexForNativeFormat::Blocks::const_iterator index_end)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2020-02-14 10:57:09 +00:00
|
|
|
if (index_begin == index_end)
|
2020-06-19 17:17:13 +00:00
|
|
|
return metadata_snapshot->getSampleBlockForColumns(column_names, storage.getVirtuals(), storage.getStorageID());
|
2020-02-14 10:57:09 +00:00
|
|
|
|
|
|
|
/// TODO: check if possible to always return storage.getSampleBlock()
|
|
|
|
|
|
|
|
Block header;
|
|
|
|
|
|
|
|
for (const auto & column : index_begin->columns)
|
2018-02-21 04:38:26 +00:00
|
|
|
{
|
2020-02-14 10:57:09 +00:00
|
|
|
auto type = DataTypeFactory::instance().get(column.type);
|
|
|
|
header.insert(ColumnWithTypeAndName{ type, column.name });
|
2018-02-21 04:38:26 +00:00
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-02-14 10:57:09 +00:00
|
|
|
return header;
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-06-16 14:25:08 +00:00
|
|
|
StripeLogSource(
|
|
|
|
StorageStripeLog & storage_,
|
|
|
|
const StorageMetadataPtr & metadata_snapshot_,
|
|
|
|
const Names & column_names,
|
|
|
|
size_t max_read_buffer_size_,
|
2020-02-14 10:57:09 +00:00
|
|
|
std::shared_ptr<const IndexForNativeFormat> & index_,
|
|
|
|
IndexForNativeFormat::Blocks::const_iterator index_begin_,
|
|
|
|
IndexForNativeFormat::Blocks::const_iterator index_end_)
|
2020-06-16 14:25:08 +00:00
|
|
|
: SourceWithProgress(
|
|
|
|
getHeader(storage_, metadata_snapshot_, column_names, index_begin_, index_end_))
|
|
|
|
, storage(storage_)
|
|
|
|
, metadata_snapshot(metadata_snapshot_)
|
|
|
|
, max_read_buffer_size(max_read_buffer_size_)
|
|
|
|
, index(index_)
|
|
|
|
, index_begin(index_begin_)
|
|
|
|
, index_end(index_end_)
|
2018-01-09 01:51:08 +00:00
|
|
|
{
|
2018-08-10 04:02:56 +00:00
|
|
|
}
|
2018-01-06 18:10:44 +00:00
|
|
|
|
2020-02-14 10:57:09 +00:00
|
|
|
String getName() const override { return "StripeLog"; }
|
|
|
|
|
2015-08-16 07:01:41 +00:00
|
|
|
protected:
|
2020-02-14 10:57:09 +00:00
|
|
|
Chunk generate() override
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
Block res;
|
2018-01-09 01:51:08 +00:00
|
|
|
start();
|
2015-12-16 02:32:49 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (block_in)
|
|
|
|
{
|
|
|
|
res = block_in->read();
|
2015-10-01 03:30:50 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Freeing memory before destroying the object.
|
|
|
|
if (!res)
|
|
|
|
{
|
2017-11-20 04:41:56 +00:00
|
|
|
block_in.reset();
|
|
|
|
data_in.reset();
|
2017-04-01 07:20:54 +00:00
|
|
|
index.reset();
|
|
|
|
}
|
|
|
|
}
|
2015-10-01 03:30:50 +00:00
|
|
|
|
2020-02-14 10:57:09 +00:00
|
|
|
return Chunk(res.getColumns(), res.rows());
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2015-08-16 07:01:41 +00:00
|
|
|
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
StorageStripeLog & storage;
|
2020-06-16 14:25:08 +00:00
|
|
|
StorageMetadataPtr metadata_snapshot;
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t max_read_buffer_size;
|
|
|
|
|
|
|
|
std::shared_ptr<const IndexForNativeFormat> index;
|
|
|
|
IndexForNativeFormat::Blocks::const_iterator index_begin;
|
|
|
|
IndexForNativeFormat::Blocks::const_iterator index_end;
|
2018-02-21 04:38:26 +00:00
|
|
|
Block header;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
/** optional - to create objects only on first reading
|
|
|
|
* and delete objects (release buffers) after the source is exhausted
|
|
|
|
* - to save RAM when using a large number of sources.
|
|
|
|
*/
|
|
|
|
bool started = false;
|
2017-11-20 04:15:43 +00:00
|
|
|
std::optional<CompressedReadBufferFromFile> data_in;
|
|
|
|
std::optional<NativeBlockInputStream> block_in;
|
2018-01-09 01:51:08 +00:00
|
|
|
|
|
|
|
void start()
|
|
|
|
{
|
|
|
|
if (!started)
|
|
|
|
{
|
|
|
|
started = true;
|
|
|
|
|
2019-12-25 08:24:13 +00:00
|
|
|
String data_file_path = storage.table_path + "data.bin";
|
|
|
|
size_t buffer_size = std::min(max_read_buffer_size, storage.disk->getFileSize(data_file_path));
|
2018-01-09 01:51:08 +00:00
|
|
|
|
2020-02-14 14:28:33 +00:00
|
|
|
data_in.emplace(storage.disk->readFile(data_file_path, buffer_size));
|
2018-02-18 02:46:39 +00:00
|
|
|
block_in.emplace(*data_in, 0, index_begin, index_end);
|
2018-01-09 01:51:08 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-16 07:01:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-09-08 04:58:57 +00:00
|
|
|
class StripeLogBlockOutputStream final : public IBlockOutputStream
|
2015-08-16 07:01:41 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-06-16 15:51:29 +00:00
|
|
|
explicit StripeLogBlockOutputStream(StorageStripeLog & storage_, const StorageMetadataPtr & metadata_snapshot_)
|
|
|
|
: storage(storage_)
|
|
|
|
, metadata_snapshot(metadata_snapshot_)
|
|
|
|
, lock(storage.rwlock)
|
|
|
|
, data_out_file(storage.table_path + "data.bin")
|
|
|
|
, data_out_compressed(storage.disk->writeFile(data_out_file, DBMS_DEFAULT_BUFFER_SIZE, WriteMode::Append))
|
2020-07-12 02:31:58 +00:00
|
|
|
, data_out(std::make_unique<CompressedWriteBuffer>(
|
|
|
|
*data_out_compressed, CompressionCodecFactory::instance().getDefaultCodec(), storage.max_compress_block_size))
|
2020-06-16 15:51:29 +00:00
|
|
|
, index_out_file(storage.table_path + "index.mrk")
|
|
|
|
, index_out_compressed(storage.disk->writeFile(index_out_file, DBMS_DEFAULT_BUFFER_SIZE, WriteMode::Append))
|
2020-07-12 02:31:58 +00:00
|
|
|
, index_out(std::make_unique<CompressedWriteBuffer>(*index_out_compressed))
|
|
|
|
, block_out(*data_out, 0, metadata_snapshot->getSampleBlock(), false, index_out.get(), storage.disk->getFileSize(data_out_file))
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-08-10 04:02:56 +00:00
|
|
|
~StripeLogBlockOutputStream() override
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2020-07-12 02:31:58 +00:00
|
|
|
if (!done)
|
|
|
|
{
|
|
|
|
/// Rollback partial writes.
|
|
|
|
data_out.reset();
|
|
|
|
data_out_compressed.reset();
|
|
|
|
index_out.reset();
|
|
|
|
index_out_compressed.reset();
|
|
|
|
|
|
|
|
storage.file_checker.repair();
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
tryLogCurrentException(__PRETTY_FUNCTION__);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-16 15:51:29 +00:00
|
|
|
Block getHeader() const override { return metadata_snapshot->getSampleBlock(); }
|
2018-02-19 00:45:32 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void write(const Block & block) override
|
|
|
|
{
|
|
|
|
block_out.write(block);
|
|
|
|
}
|
|
|
|
|
|
|
|
void writeSuffix() override
|
|
|
|
{
|
|
|
|
if (done)
|
|
|
|
return;
|
|
|
|
|
|
|
|
block_out.writeSuffix();
|
2020-07-12 02:31:58 +00:00
|
|
|
data_out->next();
|
2019-12-12 08:57:25 +00:00
|
|
|
data_out_compressed->next();
|
2020-07-12 02:31:58 +00:00
|
|
|
index_out->next();
|
2019-12-12 08:57:25 +00:00
|
|
|
index_out_compressed->next();
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2019-12-12 08:57:25 +00:00
|
|
|
storage.file_checker.update(data_out_file);
|
|
|
|
storage.file_checker.update(index_out_file);
|
2020-07-12 02:31:58 +00:00
|
|
|
storage.file_checker.save();
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
done = true;
|
|
|
|
}
|
2015-08-16 07:01:41 +00:00
|
|
|
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
StorageStripeLog & storage;
|
2020-06-16 15:51:29 +00:00
|
|
|
StorageMetadataPtr metadata_snapshot;
|
2017-07-28 17:34:02 +00:00
|
|
|
std::unique_lock<std::shared_mutex> lock;
|
2015-08-16 07:01:41 +00:00
|
|
|
|
2019-12-12 08:57:25 +00:00
|
|
|
String data_out_file;
|
|
|
|
std::unique_ptr<WriteBuffer> data_out_compressed;
|
2020-07-12 02:31:58 +00:00
|
|
|
std::unique_ptr<CompressedWriteBuffer> data_out;
|
2019-12-12 08:57:25 +00:00
|
|
|
String index_out_file;
|
|
|
|
std::unique_ptr<WriteBuffer> index_out_compressed;
|
2020-07-12 02:31:58 +00:00
|
|
|
std::unique_ptr<CompressedWriteBuffer> index_out;
|
2017-04-01 07:20:54 +00:00
|
|
|
NativeBlockOutputStream block_out;
|
2015-08-16 07:01:41 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
bool done = false;
|
2015-08-16 07:01:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
StorageStripeLog::StorageStripeLog(
|
2019-12-12 08:57:25 +00:00
|
|
|
DiskPtr disk_,
|
2019-12-26 14:03:32 +00:00
|
|
|
const String & relative_path_,
|
2019-12-04 16:06:55 +00:00
|
|
|
const StorageID & table_id_,
|
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,
|
|
|
|
size_t max_compress_block_size_)
|
2019-12-04 16:06:55 +00:00
|
|
|
: IStorage(table_id_)
|
2020-01-13 11:41:42 +00:00
|
|
|
, disk(std::move(disk_))
|
|
|
|
, table_path(relative_path_)
|
2019-12-04 16:06:55 +00:00
|
|
|
, max_compress_block_size(max_compress_block_size_)
|
2020-01-13 11:41:42 +00:00
|
|
|
, file_checker(disk, table_path + "sizes.json")
|
2020-05-30 21:57:37 +00:00
|
|
|
, log(&Poco::Logger::get("StorageStripeLog"))
|
2015-08-16 07:01:41 +00:00
|
|
|
{
|
2020-06-19 15:39:41 +00:00
|
|
|
StorageInMemoryMetadata storage_metadata;
|
|
|
|
storage_metadata.setColumns(columns_);
|
|
|
|
storage_metadata.setConstraints(constraints_);
|
|
|
|
setInMemoryMetadata(storage_metadata);
|
2019-08-24 21:20:20 +00:00
|
|
|
|
2019-10-25 19:07:47 +00:00
|
|
|
if (relative_path_.empty())
|
2017-11-03 19:53:10 +00:00
|
|
|
throw Exception("Storage " + getName() + " requires data path", ErrorCodes::INCORRECT_FILE_NAME);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
if (!attach)
|
|
|
|
{
|
2019-12-12 08:57:25 +00:00
|
|
|
/// create directories if they do not exist
|
|
|
|
disk->createDirectories(table_path);
|
2020-07-12 02:31:58 +00:00
|
|
|
|
|
|
|
file_checker.setEmpty(table_path + "data.bin");
|
|
|
|
file_checker.setEmpty(table_path + "index.mrk");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
file_checker.repair();
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
tryLogCurrentException(__PRETTY_FUNCTION__);
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2015-08-16 07:01:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-07 14:05:51 +00:00
|
|
|
void StorageStripeLog::rename(const String & new_path_to_table_data, const StorageID & new_table_id)
|
2015-08-16 07:01:41 +00:00
|
|
|
{
|
2017-07-28 17:34:02 +00:00
|
|
|
std::unique_lock<std::shared_mutex> lock(rwlock);
|
2015-08-16 08:18:34 +00:00
|
|
|
|
2019-12-26 14:03:32 +00:00
|
|
|
disk->moveDirectory(table_path, new_path_to_table_data);
|
2015-08-16 07:01:41 +00:00
|
|
|
|
2019-12-26 14:03:32 +00:00
|
|
|
table_path = new_path_to_table_data;
|
2019-12-12 08:57:25 +00:00
|
|
|
file_checker.setPath(table_path + "sizes.json");
|
2020-04-07 14:05:51 +00:00
|
|
|
renameInMemory(new_table_id);
|
2015-08-16 07:01:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-19 16:07:28 +00:00
|
|
|
Pipes StorageStripeLog::read(
|
2017-04-01 07:20:54 +00:00
|
|
|
const Names & column_names,
|
2020-06-16 14:25:08 +00:00
|
|
|
const StorageMetadataPtr & metadata_snapshot,
|
2017-12-01 21:13:25 +00:00
|
|
|
const SelectQueryInfo & /*query_info*/,
|
2017-04-01 07:20:54 +00:00
|
|
|
const Context & context,
|
2018-09-08 11:29:23 +00:00
|
|
|
QueryProcessingStage::Enum /*processed_stage*/,
|
2017-12-01 21:13:25 +00:00
|
|
|
const size_t /*max_block_size*/,
|
2017-06-02 15:54:39 +00:00
|
|
|
unsigned num_streams)
|
2015-08-16 07:01:41 +00:00
|
|
|
{
|
2017-07-28 17:34:02 +00:00
|
|
|
std::shared_lock<std::shared_mutex> lock(rwlock);
|
2015-08-16 08:18:34 +00:00
|
|
|
|
2020-06-19 17:17:13 +00:00
|
|
|
metadata_snapshot->check(column_names, getVirtuals(), getStorageID());
|
2015-08-16 08:18:34 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
NameSet column_names_set(column_names.begin(), column_names.end());
|
2015-08-16 08:18:34 +00:00
|
|
|
|
2020-02-14 10:57:09 +00:00
|
|
|
Pipes pipes;
|
|
|
|
|
2019-12-12 08:57:25 +00:00
|
|
|
String index_file = table_path + "index.mrk";
|
|
|
|
if (!disk->exists(index_file))
|
2020-02-14 10:57:09 +00:00
|
|
|
{
|
2020-06-19 17:17:13 +00:00
|
|
|
pipes.emplace_back(std::make_shared<NullSource>(metadata_snapshot->getSampleBlockForColumns(column_names, getVirtuals(), getStorageID())));
|
2020-02-14 10:57:09 +00:00
|
|
|
return pipes;
|
|
|
|
}
|
2015-12-08 20:04:11 +00:00
|
|
|
|
2020-02-14 14:28:33 +00:00
|
|
|
CompressedReadBufferFromFile index_in(disk->readFile(index_file, INDEX_BUFFER_SIZE));
|
2017-04-01 07:20:54 +00:00
|
|
|
std::shared_ptr<const IndexForNativeFormat> index{std::make_shared<IndexForNativeFormat>(index_in, column_names_set)};
|
2015-08-16 08:18:34 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t size = index->blocks.size();
|
2017-06-02 15:54:39 +00:00
|
|
|
if (num_streams > size)
|
|
|
|
num_streams = size;
|
2015-08-16 08:18:34 +00:00
|
|
|
|
2017-06-02 15:54:39 +00:00
|
|
|
for (size_t stream = 0; stream < num_streams; ++stream)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
IndexForNativeFormat::Blocks::const_iterator begin = index->blocks.begin();
|
|
|
|
IndexForNativeFormat::Blocks::const_iterator end = index->blocks.begin();
|
2015-08-16 08:18:34 +00:00
|
|
|
|
2017-06-02 15:54:39 +00:00
|
|
|
std::advance(begin, stream * size / num_streams);
|
|
|
|
std::advance(end, (stream + 1) * size / num_streams);
|
2015-08-16 08:18:34 +00:00
|
|
|
|
2020-02-14 10:57:09 +00:00
|
|
|
pipes.emplace_back(std::make_shared<StripeLogSource>(
|
2020-06-16 14:25:08 +00:00
|
|
|
*this, metadata_snapshot, column_names, context.getSettingsRef().max_read_buffer_size, index, begin, end));
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2015-08-16 08:18:34 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// We do not keep read lock directly at the time of reading, because we read ranges of data that do not change.
|
2015-08-16 08:18:34 +00:00
|
|
|
|
2020-02-14 10:57:09 +00:00
|
|
|
return pipes;
|
2015-08-16 07:01:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-16 15:51:29 +00:00
|
|
|
BlockOutputStreamPtr StorageStripeLog::write(const ASTPtr & /*query*/, const StorageMetadataPtr & metadata_snapshot, const Context & /*context*/)
|
2015-08-16 07:01:41 +00:00
|
|
|
{
|
2020-06-16 15:51:29 +00:00
|
|
|
return std::make_shared<StripeLogBlockOutputStream>(*this, metadata_snapshot);
|
2015-08-16 07:01:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-03 13:17:19 +00:00
|
|
|
CheckResults StorageStripeLog::checkData(const ASTPtr & /* query */, const Context & /* context */)
|
2015-08-16 07:01:41 +00:00
|
|
|
{
|
2017-07-28 17:34:02 +00:00
|
|
|
std::shared_lock<std::shared_mutex> lock(rwlock);
|
2017-04-01 07:20:54 +00:00
|
|
|
return file_checker.check();
|
2015-08-16 07:01:41 +00:00
|
|
|
}
|
|
|
|
|
2020-06-18 16:10:47 +00:00
|
|
|
void StorageStripeLog::truncate(const ASTPtr &, const StorageMetadataPtr &, const Context &, TableExclusiveLockHolder &)
|
2018-04-21 00:35:20 +00:00
|
|
|
{
|
2018-06-09 15:48:22 +00:00
|
|
|
std::shared_lock<std::shared_mutex> lock(rwlock);
|
2018-04-21 00:35:20 +00:00
|
|
|
|
2019-12-12 08:57:25 +00:00
|
|
|
disk->clearDirectory(table_path);
|
2018-06-09 16:09:37 +00:00
|
|
|
|
2019-12-12 08:57:25 +00:00
|
|
|
file_checker = FileChecker{disk, table_path + "sizes.json"};
|
2018-04-21 00:35:20 +00:00
|
|
|
}
|
|
|
|
|
2017-12-30 00:36:06 +00:00
|
|
|
|
|
|
|
void registerStorageStripeLog(StorageFactory & factory)
|
|
|
|
{
|
2020-02-18 14:41:30 +00:00
|
|
|
StorageFactory::StorageFeatures features{
|
|
|
|
.supports_settings = true
|
|
|
|
};
|
|
|
|
|
2017-12-30 00:36:06 +00:00
|
|
|
factory.registerStorage("StripeLog", [](const StorageFactory::Arguments & args)
|
|
|
|
{
|
2020-02-18 14:41:30 +00:00
|
|
|
if (!args.engine_args.empty())
|
2017-12-30 00:36:06 +00:00
|
|
|
throw Exception(
|
2020-02-18 14:41:30 +00:00
|
|
|
"Engine " + args.engine_name + " doesn't support any arguments (" + toString(args.engine_args.size()) + " given)",
|
2017-12-30 00:36:06 +00:00
|
|
|
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
|
|
|
|
2020-02-18 14:41:30 +00:00
|
|
|
String disk_name = getDiskName(*args.storage_def);
|
|
|
|
DiskPtr disk = args.context.getDisk(disk_name);
|
2020-02-14 14:28:33 +00:00
|
|
|
|
2017-12-30 00:36:06 +00:00
|
|
|
return StorageStripeLog::create(
|
2020-02-14 14:28:33 +00:00
|
|
|
disk, args.relative_data_path, args.table_id, args.columns, args.constraints,
|
2017-12-30 03:49:02 +00:00
|
|
|
args.attach, args.context.getSettings().max_compress_block_size);
|
2020-02-18 14:41:30 +00:00
|
|
|
}, features);
|
2017-12-30 00:36:06 +00:00
|
|
|
}
|
|
|
|
|
2015-08-16 07:01:41 +00:00
|
|
|
}
|