2019-01-15 22:08:56 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-05-26 12:58:40 +00:00
|
|
|
#include <Core/Block.h>
|
2022-01-19 23:59:09 +00:00
|
|
|
#include <base/BorrowedObjectPool.h>
|
2019-05-28 20:06:06 +00:00
|
|
|
|
2020-05-08 14:11:19 +00:00
|
|
|
#include "DictionaryStructure.h"
|
|
|
|
#include "IDictionarySource.h"
|
2019-01-15 22:08:56 +00:00
|
|
|
|
|
|
|
namespace Poco
|
|
|
|
{
|
|
|
|
namespace Util
|
|
|
|
{
|
|
|
|
class AbstractConfiguration;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace Redis
|
|
|
|
{
|
|
|
|
class Client;
|
2019-09-16 16:17:56 +00:00
|
|
|
class Array;
|
|
|
|
class Command;
|
2019-01-15 22:08:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2022-01-19 23:59:09 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2019-09-16 16:17:56 +00:00
|
|
|
enum class RedisStorageType
|
2019-04-16 23:13:07 +00:00
|
|
|
{
|
|
|
|
SIMPLE,
|
|
|
|
HASH_MAP,
|
|
|
|
UNKNOWN
|
2019-09-16 16:17:56 +00:00
|
|
|
};
|
2019-04-16 23:13:07 +00:00
|
|
|
|
2019-01-15 22:08:56 +00:00
|
|
|
class RedisDictionarySource final : public IDictionarySource
|
|
|
|
{
|
|
|
|
public:
|
2019-09-16 16:17:56 +00:00
|
|
|
using RedisArray = Poco::Redis::Array;
|
|
|
|
using RedisCommand = Poco::Redis::Command;
|
|
|
|
|
2022-01-19 23:59:09 +00:00
|
|
|
using ClientPtr = std::unique_ptr<Poco::Redis::Client>;
|
|
|
|
using Pool = BorrowedObjectPool<ClientPtr>;
|
|
|
|
using PoolPtr = std::shared_ptr<Pool>;
|
|
|
|
|
2022-01-20 14:55:56 +00:00
|
|
|
struct Configuration
|
|
|
|
{
|
|
|
|
const std::string host;
|
|
|
|
const UInt16 port;
|
|
|
|
const UInt32 db_index;
|
|
|
|
const std::string password;
|
|
|
|
const RedisStorageType storage_type;
|
|
|
|
const size_t pool_size;
|
|
|
|
};
|
|
|
|
|
2022-01-19 23:59:09 +00:00
|
|
|
struct Connection
|
|
|
|
{
|
|
|
|
Connection(PoolPtr pool_, ClientPtr client_)
|
|
|
|
: pool(std::move(pool_)), client(std::move(client_))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~Connection()
|
|
|
|
{
|
|
|
|
pool->returnObject(std::move(client));
|
|
|
|
}
|
|
|
|
|
|
|
|
PoolPtr pool;
|
|
|
|
ClientPtr client;
|
|
|
|
};
|
|
|
|
|
|
|
|
using ConnectionPtr = std::unique_ptr<Connection>;
|
|
|
|
|
2019-01-15 22:08:56 +00:00
|
|
|
RedisDictionarySource(
|
2022-01-20 14:55:56 +00:00
|
|
|
const DictionaryStructure & dict_struct_,
|
|
|
|
const Configuration & configuration_,
|
|
|
|
const Block & sample_block_);
|
2019-01-15 22:08:56 +00:00
|
|
|
|
|
|
|
RedisDictionarySource(const RedisDictionarySource & other);
|
|
|
|
|
|
|
|
~RedisDictionarySource() override;
|
|
|
|
|
2021-08-05 18:08:52 +00:00
|
|
|
Pipe loadAll() override;
|
2019-01-15 22:08:56 +00:00
|
|
|
|
2021-08-05 18:08:52 +00:00
|
|
|
Pipe loadUpdatedAll() override
|
2019-01-15 22:08:56 +00:00
|
|
|
{
|
2021-04-10 18:48:36 +00:00
|
|
|
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Method loadUpdatedAll is unsupported for RedisDictionarySource");
|
2019-01-15 22:08:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool supportsSelectiveLoad() const override { return true; }
|
|
|
|
|
2021-08-05 18:08:52 +00:00
|
|
|
Pipe loadIds(const std::vector<UInt64> & ids) override;
|
2019-01-15 22:08:56 +00:00
|
|
|
|
2021-08-05 18:08:52 +00:00
|
|
|
Pipe loadKeys(const Columns & key_columns, const std::vector<size_t> & requested_rows) override;
|
2019-01-15 22:08:56 +00:00
|
|
|
|
|
|
|
bool isModified() const override { return true; }
|
|
|
|
|
|
|
|
bool hasUpdateField() const override { return false; }
|
|
|
|
|
2021-12-15 12:55:28 +00:00
|
|
|
DictionarySourcePtr clone() const override { return std::make_shared<RedisDictionarySource>(*this); }
|
2019-01-15 22:08:56 +00:00
|
|
|
|
|
|
|
std::string toString() const override;
|
|
|
|
|
2019-04-16 23:13:07 +00:00
|
|
|
private:
|
2022-01-19 23:59:09 +00:00
|
|
|
ConnectionPtr getConnection() const;
|
2019-04-16 23:13:07 +00:00
|
|
|
|
2019-01-15 22:08:56 +00:00
|
|
|
const DictionaryStructure dict_struct;
|
2022-01-20 14:55:56 +00:00
|
|
|
const Configuration configuration;
|
2019-01-15 22:08:56 +00:00
|
|
|
|
2022-01-19 23:59:09 +00:00
|
|
|
PoolPtr pool;
|
|
|
|
Block sample_block;
|
2019-01-15 22:08:56 +00:00
|
|
|
};
|
2021-08-06 08:41:45 +00:00
|
|
|
}
|