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
|
|
|
|
2012-06-25 00:17:19 +00:00
|
|
|
#include <map>
|
2015-01-25 05:07:51 +00:00
|
|
|
|
2013-02-26 11:28:00 +00:00
|
|
|
#include <Poco/Path.h>
|
2015-01-25 05:07:51 +00:00
|
|
|
#include <Poco/Util/XMLConfiguration.h>
|
2012-06-25 00:17:19 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Common/escapeForFileName.h>
|
2012-06-25 00:17:19 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Common/Exception.h>
|
2012-06-25 00:17:19 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <IO/ReadBufferFromFile.h>
|
|
|
|
#include <IO/WriteBufferFromFile.h>
|
2018-12-28 18:15:26 +00:00
|
|
|
#include <Compression/CompressedReadBuffer.h>
|
|
|
|
#include <Compression/CompressedWriteBuffer.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <IO/ReadHelpers.h>
|
|
|
|
#include <IO/WriteHelpers.h>
|
2012-06-25 00:17:19 +00:00
|
|
|
|
2017-12-25 18:58:39 +00:00
|
|
|
#include <DataTypes/NestedUtils.h>
|
2012-08-29 18:49:54 +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>
|
2015-01-18 08:25:56 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Columns/ColumnArray.h>
|
2012-08-29 18:49:54 +00:00
|
|
|
|
2017-07-13 20:58:19 +00:00
|
|
|
#include <Common/typeid_cast.h>
|
2018-12-21 12:17:30 +00:00
|
|
|
#include <Compression/CompressionFactory.h>
|
2017-07-13 20:58:19 +00:00
|
|
|
|
2017-05-24 21:06:29 +00:00
|
|
|
#include <Interpreters/Context.h>
|
2017-01-21 04:24:28 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Storages/StorageTinyLog.h>
|
2017-12-30 00:36:06 +00:00
|
|
|
#include <Storages/StorageFactory.h>
|
|
|
|
|
2014-08-29 18:44:44 +00:00
|
|
|
#include <Poco/DirectoryIterator.h>
|
2012-06-25 00:17:19 +00:00
|
|
|
|
2017-07-27 23:23:13 +00:00
|
|
|
#define DBMS_STORAGE_LOG_DATA_FILE_EXTENSION ".bin"
|
2012-06-25 00:17:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2016-01-11 21:46:36 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
extern const int EMPTY_LIST_OF_COLUMNS_PASSED;
|
|
|
|
extern const int CANNOT_CREATE_DIRECTORY;
|
|
|
|
extern const int CANNOT_READ_ALL_DATA;
|
|
|
|
extern const int DUPLICATE_COLUMN;
|
2017-07-27 23:23:13 +00:00
|
|
|
extern const int LOGICAL_ERROR;
|
2017-11-03 19:53:10 +00:00
|
|
|
extern const int INCORRECT_FILE_NAME;
|
2017-12-30 00:36:06 +00:00
|
|
|
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
|
2016-01-11 21:46:36 +00:00
|
|
|
}
|
|
|
|
|
2012-06-25 00:17:19 +00:00
|
|
|
|
2019-01-23 14:48:50 +00:00
|
|
|
class TinyLogBlockInputStream final : public IBlockInputStream
|
2012-06-25 00:17:19 +00:00
|
|
|
{
|
2015-01-18 08:25:56 +00:00
|
|
|
public:
|
2018-01-02 06:13:22 +00:00
|
|
|
TinyLogBlockInputStream(size_t block_size_, const NamesAndTypesList & columns_, StorageTinyLog & storage_, size_t max_read_buffer_size_)
|
|
|
|
: block_size(block_size_), columns(columns_),
|
2017-04-01 07:20:54 +00:00
|
|
|
storage(storage_), max_read_buffer_size(max_read_buffer_size_) {}
|
2015-01-18 08:25:56 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
String getName() const override { return "TinyLog"; }
|
2015-01-18 08:25:56 +00:00
|
|
|
|
2018-02-18 03:23:48 +00:00
|
|
|
Block getHeader() const override
|
2018-01-09 01:51:08 +00:00
|
|
|
{
|
|
|
|
Block res;
|
|
|
|
|
|
|
|
for (const auto & name_type : columns)
|
|
|
|
res.insert({ name_type.type->createColumn(), name_type.type, name_type.name });
|
|
|
|
|
2018-02-17 03:49:34 +00:00
|
|
|
return Nested::flatten(res);
|
2018-08-10 04:02:56 +00:00
|
|
|
}
|
2018-01-06 18:10:44 +00:00
|
|
|
|
2015-01-18 08:25:56 +00:00
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
Block readImpl() override;
|
2015-01-18 08:25:56 +00:00
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t block_size;
|
2018-01-02 06:13:22 +00:00
|
|
|
NamesAndTypesList columns;
|
2017-04-01 07:20:54 +00:00
|
|
|
StorageTinyLog & storage;
|
|
|
|
bool finished = false;
|
|
|
|
size_t max_read_buffer_size;
|
|
|
|
|
|
|
|
struct Stream
|
|
|
|
{
|
|
|
|
Stream(const std::string & data_path, size_t max_read_buffer_size)
|
2017-09-01 17:21:03 +00:00
|
|
|
: plain(data_path, std::min(static_cast<Poco::File::FileSize>(max_read_buffer_size), Poco::File(data_path).getSize())),
|
2017-04-01 07:20:54 +00:00
|
|
|
compressed(plain)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ReadBufferFromFile plain;
|
|
|
|
CompressedReadBuffer compressed;
|
|
|
|
};
|
|
|
|
|
|
|
|
using FileStreams = std::map<std::string, std::unique_ptr<Stream>>;
|
|
|
|
FileStreams streams;
|
|
|
|
|
2018-06-07 18:14:37 +00:00
|
|
|
using DeserializeState = IDataType::DeserializeBinaryBulkStatePtr;
|
|
|
|
using DeserializeStates = std::map<String, DeserializeState>;
|
|
|
|
DeserializeStates deserialize_states;
|
|
|
|
|
2018-01-02 09:11:13 +00:00
|
|
|
void readData(const String & name, const IDataType & type, IColumn & column, size_t limit);
|
2015-01-18 08:25:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-09-08 04:58:57 +00:00
|
|
|
class TinyLogBlockOutputStream final : public IBlockOutputStream
|
2015-01-18 08:25:56 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-09-07 21:04:48 +00:00
|
|
|
explicit TinyLogBlockOutputStream(StorageTinyLog & storage_)
|
2017-04-01 07:20:54 +00:00
|
|
|
: storage(storage_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~TinyLogBlockOutputStream() override
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
writeSuffix();
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
tryLogCurrentException(__PRETTY_FUNCTION__);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-19 00:45:32 +00:00
|
|
|
Block getHeader() const override { return storage.getSampleBlock(); }
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void write(const Block & block) override;
|
|
|
|
void writeSuffix() override;
|
2015-04-02 23:58:26 +00:00
|
|
|
|
2015-01-18 08:25:56 +00:00
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
StorageTinyLog & storage;
|
|
|
|
bool done = false;
|
|
|
|
|
|
|
|
struct Stream
|
|
|
|
{
|
2019-01-21 14:00:06 +00:00
|
|
|
Stream(const std::string & data_path, CompressionCodecPtr codec, size_t max_compress_block_size) :
|
2017-04-01 07:20:54 +00:00
|
|
|
plain(data_path, max_compress_block_size, O_APPEND | O_CREAT | O_WRONLY),
|
2019-01-21 18:04:08 +00:00
|
|
|
compressed(plain, std::move(codec), max_compress_block_size)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
WriteBufferFromFile plain;
|
|
|
|
CompressedWriteBuffer compressed;
|
|
|
|
|
|
|
|
void finalize()
|
|
|
|
{
|
|
|
|
compressed.next();
|
|
|
|
plain.next();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
using FileStreams = std::map<std::string, std::unique_ptr<Stream>>;
|
|
|
|
FileStreams streams;
|
|
|
|
|
2018-06-07 18:14:37 +00:00
|
|
|
using SerializeState = IDataType::SerializeBinaryBulkStatePtr;
|
|
|
|
using SerializeStates = std::map<String, SerializeState>;
|
|
|
|
SerializeStates serialize_states;
|
|
|
|
|
2017-08-07 07:31:16 +00:00
|
|
|
using WrittenStreams = std::set<std::string>;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2018-06-07 18:14:37 +00:00
|
|
|
IDataType::OutputStreamGetter createStreamGetter(const String & name, WrittenStreams & written_streams);
|
2017-08-07 07:31:16 +00:00
|
|
|
void writeData(const String & name, const IDataType & type, const IColumn & column, WrittenStreams & written_streams);
|
2015-01-18 08:25:56 +00:00
|
|
|
};
|
2012-06-25 00:17:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
Block TinyLogBlockInputStream::readImpl()
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
Block res;
|
|
|
|
|
|
|
|
if (finished || (!streams.empty() && streams.begin()->second->compressed.eof()))
|
|
|
|
{
|
|
|
|
/** Close the files (before destroying the object).
|
|
|
|
* When many sources are created, but simultaneously reading only a few of them,
|
|
|
|
* buffers don't waste memory.
|
|
|
|
*/
|
|
|
|
finished = true;
|
|
|
|
streams.clear();
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
/// if there are no files in the folder, it means that the table is empty
|
|
|
|
if (Poco::DirectoryIterator(storage.full_path()) == Poco::DirectoryIterator())
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2018-01-02 06:13:22 +00:00
|
|
|
for (const auto & name_type : columns)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2018-01-02 09:11:13 +00:00
|
|
|
MutableColumnPtr column = name_type.type->createColumn();
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2018-01-02 09:11:13 +00:00
|
|
|
readData(name_type.name, *name_type.type, *column, block_size);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
catch (Exception & e)
|
|
|
|
{
|
2018-01-02 06:13:22 +00:00
|
|
|
e.addMessage("while reading column " + name_type.name + " at " + storage.full_path());
|
2017-04-01 07:20:54 +00:00
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
2017-12-15 19:53:11 +00:00
|
|
|
if (column->size())
|
2018-01-02 06:13:22 +00:00
|
|
|
res.insert(ColumnWithTypeAndName(std::move(column), name_type.type, name_type.name));
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!res || streams.begin()->second->compressed.eof())
|
|
|
|
{
|
|
|
|
finished = true;
|
|
|
|
streams.clear();
|
|
|
|
}
|
|
|
|
|
2018-01-02 09:11:13 +00:00
|
|
|
return Nested::flatten(res);
|
2012-06-25 00:17:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-02 09:11:13 +00:00
|
|
|
void TinyLogBlockInputStream::readData(const String & name, const IDataType & type, IColumn & column, size_t limit)
|
2012-08-29 18:49:54 +00:00
|
|
|
{
|
2018-06-07 18:14:37 +00:00
|
|
|
IDataType::DeserializeBinaryBulkSettings settings; /// TODO Use avg_value_size_hint.
|
|
|
|
settings.getter = [&] (const IDataType::SubstreamPath & path) -> ReadBuffer *
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2017-08-07 07:31:16 +00:00
|
|
|
String stream_name = IDataType::getFileNameForStream(name, path);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-08-07 07:31:16 +00:00
|
|
|
if (!streams.count(stream_name))
|
|
|
|
streams[stream_name] = std::make_unique<Stream>(storage.files[stream_name].data_file.path(), max_read_buffer_size);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-08-07 07:31:16 +00:00
|
|
|
return &streams[stream_name]->compressed;
|
|
|
|
};
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2018-06-07 18:14:37 +00:00
|
|
|
if (deserialize_states.count(name) == 0)
|
|
|
|
type.deserializeBinaryBulkStatePrefix(settings, deserialize_states[name]);
|
|
|
|
|
|
|
|
type.deserializeBinaryBulkWithMultipleStreams(column, limit, settings, deserialize_states[name]);
|
2012-08-29 18:49:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-07 18:14:37 +00:00
|
|
|
IDataType::OutputStreamGetter TinyLogBlockOutputStream::createStreamGetter(const String & name,
|
|
|
|
WrittenStreams & written_streams)
|
2012-08-29 18:49:54 +00:00
|
|
|
{
|
2018-06-07 18:14:37 +00:00
|
|
|
return [&] (const IDataType::SubstreamPath & path) -> WriteBuffer *
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2017-08-07 07:31:16 +00:00
|
|
|
String stream_name = IDataType::getFileNameForStream(name, path);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2018-01-02 09:11:13 +00:00
|
|
|
if (!written_streams.insert(stream_name).second)
|
|
|
|
return nullptr;
|
|
|
|
|
2019-01-21 14:00:06 +00:00
|
|
|
const auto & columns = storage.getColumns();
|
2017-08-07 07:31:16 +00:00
|
|
|
if (!streams.count(stream_name))
|
2018-06-07 18:14:37 +00:00
|
|
|
streams[stream_name] = std::make_unique<Stream>(storage.files[stream_name].data_file.path(),
|
2019-01-21 14:00:06 +00:00
|
|
|
columns.getCodecOrDefault(name),
|
2018-06-07 18:14:37 +00:00
|
|
|
storage.max_compress_block_size);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-08-07 07:31:16 +00:00
|
|
|
return &streams[stream_name]->compressed;
|
|
|
|
};
|
2018-06-07 18:14:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TinyLogBlockOutputStream::writeData(const String & name, const IDataType & type, const IColumn & column, WrittenStreams & written_streams)
|
|
|
|
{
|
|
|
|
IDataType::SerializeBinaryBulkSettings settings;
|
|
|
|
settings.getter = createStreamGetter(name, written_streams);
|
|
|
|
|
|
|
|
if (serialize_states.count(name) == 0)
|
|
|
|
type.serializeBinaryBulkStatePrefix(settings, serialize_states[name]);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2018-06-07 18:14:37 +00:00
|
|
|
type.serializeBinaryBulkWithMultipleStreams(column, 0, 0, settings, serialize_states[name]);
|
2012-06-25 00:17:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-15 01:40:29 +00:00
|
|
|
void TinyLogBlockOutputStream::writeSuffix()
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
if (done)
|
|
|
|
return;
|
|
|
|
done = true;
|
2015-04-02 23:58:26 +00:00
|
|
|
|
2018-07-07 19:02:10 +00:00
|
|
|
/// If nothing was written - leave the table in initial state.
|
|
|
|
if (streams.empty())
|
|
|
|
return;
|
|
|
|
|
2018-06-07 18:14:37 +00:00
|
|
|
WrittenStreams written_streams;
|
|
|
|
IDataType::SerializeBinaryBulkSettings settings;
|
|
|
|
for (const auto & column : getHeader())
|
|
|
|
{
|
|
|
|
auto it = serialize_states.find(column.name);
|
|
|
|
if (it != serialize_states.end())
|
|
|
|
{
|
|
|
|
settings.getter = createStreamGetter(column.name, written_streams);
|
|
|
|
column.type->serializeBinaryBulkStateSuffix(settings, it->second);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Finish write.
|
2017-12-11 18:19:35 +00:00
|
|
|
for (auto & stream : streams)
|
|
|
|
stream.second->finalize();
|
2014-07-31 19:19:56 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
std::vector<Poco::File> column_files;
|
|
|
|
for (auto & pair : streams)
|
|
|
|
column_files.push_back(storage.files[pair.first].data_file);
|
2014-08-01 13:19:27 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
storage.file_checker.update(column_files.begin(), column_files.end());
|
2013-09-15 01:40:29 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
streams.clear();
|
2013-09-15 01:40:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-25 00:17:19 +00:00
|
|
|
void TinyLogBlockOutputStream::write(const Block & block)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
storage.check(block, true);
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2017-08-07 07:31:16 +00:00
|
|
|
/// The set of written offset columns so that you do not write shared columns for nested structures multiple times
|
|
|
|
WrittenStreams written_streams;
|
2012-06-25 00:17:19 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
for (size_t i = 0; i < block.columns(); ++i)
|
|
|
|
{
|
|
|
|
const ColumnWithTypeAndName & column = block.safeGetByPosition(i);
|
2017-08-07 07:31:16 +00:00
|
|
|
writeData(column.name, *column.type, *column.column, written_streams);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2012-06-25 00:17:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-30 03:08:47 +00:00
|
|
|
StorageTinyLog::StorageTinyLog(
|
2017-04-01 07:20:54 +00:00
|
|
|
const std::string & path_,
|
|
|
|
const std::string & name_,
|
2018-03-06 20:18:34 +00:00
|
|
|
const ColumnsDescription & columns_,
|
2017-04-01 07:20:54 +00:00
|
|
|
bool attach,
|
|
|
|
size_t max_compress_block_size_)
|
2018-03-06 20:18:34 +00:00
|
|
|
: IStorage{columns_},
|
2018-01-25 14:42:39 +00:00
|
|
|
path(path_), name(name_),
|
2017-04-01 07:20:54 +00:00
|
|
|
max_compress_block_size(max_compress_block_size_),
|
|
|
|
file_checker(path + escapeForFileName(name) + '/' + "sizes.json"),
|
|
|
|
log(&Logger::get("StorageTinyLog"))
|
2012-06-25 00:17:19 +00:00
|
|
|
{
|
2017-11-03 19:53:10 +00:00
|
|
|
if (path.empty())
|
|
|
|
throw Exception("Storage " + getName() + " requires data path", ErrorCodes::INCORRECT_FILE_NAME);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
String full_path = path + escapeForFileName(name) + '/';
|
|
|
|
if (!attach)
|
|
|
|
{
|
|
|
|
/// create files if they do not exist
|
|
|
|
if (0 != mkdir(full_path.c_str(), S_IRWXU | S_IRWXG | S_IRWXO) && errno != EEXIST)
|
|
|
|
throwFromErrno("Cannot create directory " + full_path, ErrorCodes::CANNOT_CREATE_DIRECTORY);
|
|
|
|
}
|
|
|
|
|
2018-03-13 15:00:28 +00:00
|
|
|
for (const auto & col : getColumns().getAllPhysical())
|
2017-08-07 07:31:16 +00:00
|
|
|
addFiles(col.name, *col.type);
|
2012-08-29 18:49:54 +00:00
|
|
|
}
|
|
|
|
|
2016-08-10 19:12:29 +00:00
|
|
|
|
2017-08-07 07:31:16 +00:00
|
|
|
void StorageTinyLog::addFiles(const String & column_name, const IDataType & type)
|
2012-08-29 18:49:54 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
if (files.end() != files.find(column_name))
|
|
|
|
throw Exception("Duplicate column with name " + column_name + " in constructor of StorageTinyLog.",
|
|
|
|
ErrorCodes::DUPLICATE_COLUMN);
|
|
|
|
|
2017-08-07 07:31:16 +00:00
|
|
|
IDataType::StreamCallback stream_callback = [&] (const IDataType::SubstreamPath & substream_path)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2017-08-07 07:31:16 +00:00
|
|
|
String stream_name = IDataType::getFileNameForStream(column_name, substream_path);
|
|
|
|
if (!files.count(stream_name))
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
ColumnData column_data;
|
2017-08-07 07:31:16 +00:00
|
|
|
files.insert(std::make_pair(stream_name, column_data));
|
|
|
|
files[stream_name].data_file = Poco::File(
|
|
|
|
path + escapeForFileName(name) + '/' + stream_name + DBMS_STORAGE_LOG_DATA_FILE_EXTENSION);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2017-08-07 07:31:16 +00:00
|
|
|
};
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2019-01-04 12:10:00 +00:00
|
|
|
IDataType::SubstreamPath substream_path;
|
|
|
|
type.enumerateStreams(stream_callback, substream_path);
|
2012-06-25 00:17:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-01 21:13:25 +00:00
|
|
|
void StorageTinyLog::rename(const String & new_path_to_db, const String & /*new_database_name*/, const String & new_table_name)
|
2012-06-25 00:17:19 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Rename directory with data.
|
|
|
|
Poco::File(path + escapeForFileName(name)).renameTo(new_path_to_db + escapeForFileName(new_table_name));
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
path = new_path_to_db;
|
|
|
|
name = new_table_name;
|
|
|
|
file_checker.setPath(path + escapeForFileName(name) + "/" + "sizes.json");
|
2012-06-25 00:17:19 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
for (Files_t::iterator it = files.begin(); it != files.end(); ++it)
|
|
|
|
it->second.data_file = Poco::File(path + escapeForFileName(name) + '/' + Poco::Path(it->second.data_file.path()).getFileName());
|
2012-06-25 00:17:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BlockInputStreams StorageTinyLog::read(
|
2017-04-01 07:20:54 +00:00
|
|
|
const Names & column_names,
|
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-04-01 07:20:54 +00:00
|
|
|
const size_t max_block_size,
|
2017-12-01 21:13:25 +00:00
|
|
|
const unsigned /*num_streams*/)
|
2012-06-25 00:17:19 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
check(column_names);
|
2017-05-24 21:06:29 +00:00
|
|
|
return BlockInputStreams(1, std::make_shared<TinyLogBlockInputStream>(
|
2018-03-13 15:00:28 +00:00
|
|
|
max_block_size, Nested::collect(getColumns().getAllPhysical().addTypes(column_names)), *this, context.getSettingsRef().max_read_buffer_size));
|
2012-06-25 00:17:19 +00:00
|
|
|
}
|
|
|
|
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2012-06-25 00:17:19 +00:00
|
|
|
BlockOutputStreamPtr StorageTinyLog::write(
|
2017-12-01 21:13:25 +00:00
|
|
|
const ASTPtr & /*query*/, const Settings & /*settings*/)
|
2012-06-25 00:17:19 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
return std::make_shared<TinyLogBlockOutputStream>(*this);
|
2012-06-25 00:17:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-31 13:39:23 +00:00
|
|
|
bool StorageTinyLog::checkData() const
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
return file_checker.check();
|
2014-07-31 13:39:23 +00:00
|
|
|
}
|
|
|
|
|
2018-12-28 13:39:44 +00:00
|
|
|
void StorageTinyLog::truncate(const ASTPtr &, const Context &)
|
2018-04-21 00:35:20 +00:00
|
|
|
{
|
2018-06-09 15:48:22 +00:00
|
|
|
if (name.empty())
|
|
|
|
throw Exception("Logical error: table name is empty", ErrorCodes::LOGICAL_ERROR);
|
2018-04-21 00:35:20 +00:00
|
|
|
|
2018-06-09 16:09:37 +00:00
|
|
|
auto file = Poco::File(path + escapeForFileName(name));
|
|
|
|
file.remove(true);
|
|
|
|
file.createDirectories();
|
2018-04-21 00:35:20 +00:00
|
|
|
|
2018-06-09 15:48:22 +00:00
|
|
|
files.clear();
|
|
|
|
file_checker = FileChecker{path + escapeForFileName(name) + '/' + "sizes.json"};
|
2018-04-21 00:35:20 +00:00
|
|
|
|
|
|
|
for (const auto &column : getColumns().getAllPhysical())
|
|
|
|
addFiles(column.name, *column.type);
|
|
|
|
}
|
|
|
|
|
2017-12-30 00:36:06 +00:00
|
|
|
|
2017-12-30 03:49:02 +00:00
|
|
|
void registerStorageTinyLog(StorageFactory & factory)
|
2017-12-30 00:36:06 +00:00
|
|
|
{
|
|
|
|
factory.registerStorage("TinyLog", [](const StorageFactory::Arguments & args)
|
|
|
|
{
|
|
|
|
if (!args.engine_args.empty())
|
|
|
|
throw Exception(
|
|
|
|
"Engine " + args.engine_name + " doesn't support any arguments (" + toString(args.engine_args.size()) + " given)",
|
|
|
|
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
|
|
|
|
|
|
|
return StorageTinyLog::create(
|
|
|
|
args.data_path, args.table_name, args.columns,
|
2017-12-30 03:49:02 +00:00
|
|
|
args.attach, args.context.getSettings().max_compress_block_size);
|
2017-12-30 00:36:06 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-06-25 00:17:19 +00:00
|
|
|
}
|