ClickHouse/src/Storages/PostgreSQL/PostgreSQLReplicaConsumer.h

53 lines
1.5 KiB
C++
Raw Normal View History

#pragma once
2021-01-19 15:29:22 +00:00
#include "PostgreSQLConnection.h"
#include "PostgreSQLReplicationHandler.h"
2021-01-27 15:29:28 +00:00
#include <Core/BackgroundSchedulePool.h>
#include "pqxx/pqxx"
namespace DB
{
class PostgreSQLReplicaConsumer
{
public:
PostgreSQLReplicaConsumer(
2021-01-27 15:29:28 +00:00
Context & context_,
const std::string & table_name_,
const std::string & conn_str_,
const std::string & replication_slot_name_,
const std::string & publication_name_,
const LSNPosition & start_lsn);
void run();
2021-01-19 15:29:22 +00:00
void createSubscription();
private:
2021-01-19 15:29:22 +00:00
void readString(const char * message, size_t & pos, size_t size, String & result);
Int64 readInt64(const char * message, size_t & pos);
Int32 readInt32(const char * message, size_t & pos);
Int16 readInt16(const char * message, size_t & pos);
Int8 readInt8(const char * message, size_t & pos);
void readTupleData(const char * message, size_t & pos, size_t size);
void startReplication(
const std::string & slot_name, const std::string start_lsn, const int64_t timeline, const std::string & plugin_args);
2021-01-19 15:29:22 +00:00
void decodeReplicationMessage(const char * replication_message, size_t size);
2021-01-27 15:29:28 +00:00
void WALReaderFunc();
Poco::Logger * log;
2021-01-27 15:29:28 +00:00
Context & context;
const std::string replication_slot_name;
const std::string publication_name;
const std::string table_name;
PostgreSQLConnectionPtr connection, replication_connection;
LSNPosition current_lsn;
2021-01-27 15:29:28 +00:00
BackgroundSchedulePool::TaskHolder wal_reader_task;
};
}