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
|
|
|
|
2021-10-02 07:13:14 +00:00
|
|
|
#include <base/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>
|
2021-08-26 22:15:24 +00:00
|
|
|
#include <Formats/IndexForNativeFormat.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Common/FileChecker.h>
|
|
|
|
#include <Common/escapeForFileName.h>
|
2022-01-24 17:41:13 +00:00
|
|
|
#include <Disks/IDisk.h>
|
2015-08-16 07:01:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2021-08-26 22:15:24 +00:00
|
|
|
struct IndexForNativeFormat;
|
|
|
|
|
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
|
|
|
*/
|
2021-06-15 19:55:21 +00:00
|
|
|
class StorageStripeLog final : public shared_ptr_helper<StorageStripeLog>, public IStorage
|
2015-08-16 07:01:41 +00:00
|
|
|
{
|
2020-02-14 10:57:09 +00:00
|
|
|
friend class StripeLogSource;
|
2021-07-23 14:25:35 +00:00
|
|
|
friend class StripeLogSink;
|
2022-01-17 18:55:40 +00:00
|
|
|
friend class StripeLogRestoreTask;
|
2021-06-15 19:55:21 +00:00
|
|
|
friend struct shared_ptr_helper<StorageStripeLog>;
|
2015-08-16 07:01:41 +00:00
|
|
|
|
|
|
|
public:
|
2021-08-26 22:15:24 +00:00
|
|
|
~StorageStripeLog() override;
|
|
|
|
|
2019-12-12 08:57:25 +00:00
|
|
|
String getName() const override { return "StripeLog"; }
|
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,
|
2021-07-09 03:15:41 +00:00
|
|
|
const StorageSnapshotPtr & storage_snapshot,
|
2020-09-20 17:52:17 +00:00
|
|
|
SelectQueryInfo & query_info,
|
2021-04-10 23:33:54 +00:00
|
|
|
ContextPtr 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
|
|
|
|
2021-07-23 14:25:35 +00:00
|
|
|
SinkToStoragePtr write(const ASTPtr & query, const StorageMetadataPtr & /*metadata_snapshot*/, ContextPtr 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
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
CheckResults checkData(const ASTPtr & /* query */, ContextPtr /* 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)}; }
|
2015-08-16 07:01:41 +00:00
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
void truncate(const ASTPtr &, const StorageMetadataPtr &, ContextPtr, TableExclusiveLockHolder&) override;
|
2018-04-21 00:35:20 +00:00
|
|
|
|
2022-02-22 13:31:50 +00:00
|
|
|
bool hasDataToBackup() const override { return true; }
|
|
|
|
BackupEntries backupData(ContextPtr context, const ASTs & partitions) override;
|
2022-04-19 18:15:27 +00:00
|
|
|
RestoreTaskPtr restoreData(ContextMutablePtr context, const ASTs & partitions, const BackupPtr & backup, const String & data_path_in_backup, const StorageRestoreSettings & restore_settings, const std::shared_ptr<IRestoreCoordination> & restore_coordination) override;
|
2021-10-26 09:48:31 +00:00
|
|
|
|
2022-05-02 22:01:11 +00:00
|
|
|
std::optional<UInt64> totalRows(const Settings & settings) const override;
|
|
|
|
std::optional<UInt64> totalBytes(const Settings & settings) const override;
|
|
|
|
|
2019-12-12 08:57:25 +00:00
|
|
|
protected:
|
|
|
|
StorageStripeLog(
|
|
|
|
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_,
|
2021-04-23 12:18:23 +00:00
|
|
|
const String & comment,
|
2019-12-12 08:57:25 +00:00
|
|
|
bool attach,
|
|
|
|
size_t max_compress_block_size_);
|
|
|
|
|
2015-08-16 07:01:41 +00:00
|
|
|
private:
|
2021-08-26 22:15:24 +00:00
|
|
|
using ReadLock = std::shared_lock<std::shared_timed_mutex>;
|
|
|
|
using WriteLock = std::unique_lock<std::shared_timed_mutex>;
|
2019-12-12 08:57:25 +00:00
|
|
|
|
2021-08-26 22:15:24 +00:00
|
|
|
/// Reads the index file if it hasn't read yet.
|
|
|
|
/// It is done lazily, so that with a large number of tables, the server starts quickly.
|
2022-05-02 22:01:11 +00:00
|
|
|
void loadIndices(std::chrono::seconds lock_timeout) const;
|
|
|
|
void loadIndices(const WriteLock &) const;
|
2021-08-26 22:15:24 +00:00
|
|
|
|
|
|
|
/// Saves the index file.
|
|
|
|
void saveIndices(const WriteLock &);
|
|
|
|
|
|
|
|
/// Removes all unsaved indices.
|
|
|
|
void removeUnsavedIndices(const WriteLock &);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2021-08-26 22:15:24 +00:00
|
|
|
/// Saves the sizes of the data and index files.
|
|
|
|
void saveFileSizes(const WriteLock &);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2021-08-26 22:15:24 +00:00
|
|
|
const DiskPtr disk;
|
|
|
|
String table_path;
|
|
|
|
|
|
|
|
String data_file_path;
|
|
|
|
String index_file_path;
|
2017-04-01 07:20:54 +00:00
|
|
|
FileChecker file_checker;
|
2021-08-26 22:15:24 +00:00
|
|
|
|
2022-05-02 22:01:11 +00:00
|
|
|
mutable IndexForNativeFormat indices;
|
|
|
|
mutable std::atomic<bool> indices_loaded = false;
|
|
|
|
mutable size_t num_indices_saved = 0;
|
2021-08-26 22:15:24 +00:00
|
|
|
|
|
|
|
const size_t max_compress_block_size;
|
|
|
|
|
2021-10-26 09:48:31 +00:00
|
|
|
mutable std::shared_timed_mutex rwlock;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-05-30 21:57:37 +00:00
|
|
|
Poco::Logger * log;
|
2015-08-16 07:01:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|