2021-01-01 14:43:11 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-01-19 15:29:22 +00:00
|
|
|
#include "PostgreSQLConnection.h"
|
2021-01-01 14:43:11 +00:00
|
|
|
#include "PostgreSQLReplicationHandler.h"
|
2021-01-27 15:29:28 +00:00
|
|
|
#include <Core/BackgroundSchedulePool.h>
|
2021-01-01 14:43:11 +00:00
|
|
|
#include "pqxx/pqxx"
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class PostgreSQLReplicaConsumer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PostgreSQLReplicaConsumer(
|
2021-01-27 15:29:28 +00:00
|
|
|
Context & context_,
|
2021-01-01 14:43:11 +00:00
|
|
|
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();
|
2021-01-01 14:43:11 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2021-01-01 14:43:11 +00:00
|
|
|
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-01 14:43:11 +00:00
|
|
|
|
2021-01-27 15:29:28 +00:00
|
|
|
void WALReaderFunc();
|
|
|
|
|
2021-01-01 14:43:11 +00:00
|
|
|
Poco::Logger * log;
|
2021-01-27 15:29:28 +00:00
|
|
|
Context & context;
|
2021-01-01 14:43:11 +00:00
|
|
|
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;
|
2021-01-01 14:43:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|