ClickHouse/src/Storages/StorageKeeperMap.h

74 lines
2.3 KiB
C++
Raw Normal View History

2022-07-26 09:08:55 +00:00
#pragma once
#include <Interpreters/Context.h>
#include <QueryPipeline/Pipe.h>
2022-07-27 13:20:45 +00:00
#include <Storages/IKVStorage.h>
2022-07-26 09:08:55 +00:00
#include <Storages/IStorage.h>
2022-07-27 13:20:45 +00:00
#include <Storages/StorageInMemoryMetadata.h>
#include "Common/PODArray_fwd.h"
#include <Common/ZooKeeper/ZooKeeper.h>
#include <span>
2022-07-26 09:08:55 +00:00
namespace DB
{
2022-07-27 13:20:45 +00:00
// KV store using (Zoo|CH)Keeper
class StorageKeeperMap final : public IKeyValueStorage
2022-07-26 09:08:55 +00:00
{
public:
// TODO(antonio2368): add setting to control creating if keeper_path doesn't exist
StorageKeeperMap(
2022-07-27 13:20:45 +00:00
ContextPtr context,
const StorageID & table_id,
const StorageInMemoryMetadata & metadata,
std::string_view primary_key_,
2022-08-03 13:34:14 +00:00
std::string_view keeper_path_,
const std::string & hosts,
2022-08-08 09:43:29 +00:00
bool create_missing_root_path,
size_t keys_limit);
2022-07-26 09:08:55 +00:00
Pipe read(
const Names & column_names,
const StorageSnapshotPtr & storage_snapshot,
SelectQueryInfo & query_info,
ContextPtr context,
QueryProcessingStage::Enum processed_stage,
size_t max_block_size,
unsigned num_streams) override;
2022-07-27 13:20:45 +00:00
SinkToStoragePtr write(const ASTPtr & query, const StorageMetadataPtr & metadata_snapshot, ContextPtr context) override;
2022-07-26 09:08:55 +00:00
2022-07-27 13:20:45 +00:00
std::string getName() const override { return "KeeperMap"; }
Names getPrimaryKey() const override { return {primary_key}; }
2022-07-26 09:08:55 +00:00
2022-07-27 13:20:45 +00:00
Chunk getByKeys(const ColumnsWithTypeAndName & keys, PaddedPODArray<UInt8> & null_map) const override;
Chunk getBySerializedKeys(std::span<const std::string> keys, PaddedPODArray<UInt8> * null_map) const;
2022-07-26 09:08:55 +00:00
2022-07-27 13:20:45 +00:00
bool supportsParallelInsert() const override { return true; }
bool supportsIndexForIn() const override { return true; }
bool mayBenefitFromIndexForIn(
const ASTPtr & node, ContextPtr /*query_context*/, const StorageMetadataPtr & /*metadata_snapshot*/) const override
{
return node->getColumnName() == primary_key;
}
zkutil::ZooKeeperPtr & getClient() const;
2022-07-26 09:08:55 +00:00
const std::string & rootKeeperPath() const;
2022-07-27 13:20:45 +00:00
std::string fullPathForKey(std::string_view key) const;
2022-07-26 09:08:55 +00:00
2022-08-08 09:43:29 +00:00
const std::string & lockPath() const;
UInt64 keysLimit() const;
2022-07-27 13:20:45 +00:00
private:
2022-07-26 09:08:55 +00:00
std::string keeper_path;
2022-07-27 13:20:45 +00:00
std::string primary_key;
2022-08-08 09:43:29 +00:00
std::string metadata_path;
std::string lock_path;
UInt64 keys_limit{0};
2022-07-27 13:20:45 +00:00
mutable zkutil::ZooKeeperPtr zookeeper_client;
2022-07-26 09:08:55 +00:00
};
}