From 0d3cab3e10550144a27ec86ee06c3309e3261659 Mon Sep 17 00:00:00 2001 From: BohuTANG Date: Sat, 25 Apr 2020 22:04:36 +0800 Subject: [PATCH] fix openssl build --- src/Core/MySQLClient.h | 2 + src/Core/MySQLProtocol.h | 70 +++++++++++++++++++++++++++---- src/Core/tests/CMakeLists.txt | 3 ++ src/Core/tests/mysql_protocol.cpp | 2 +- 4 files changed, 68 insertions(+), 9 deletions(-) diff --git a/src/Core/MySQLClient.h b/src/Core/MySQLClient.h index 12ebbca45f4..96eb12cccba 100644 --- a/src/Core/MySQLClient.h +++ b/src/Core/MySQLClient.h @@ -15,6 +15,7 @@ namespace DB { using namespace MySQLProtocol; +using namespace ReplicationProtocol; class MySQLClient { @@ -25,6 +26,7 @@ public: bool ping(); bool registerSlave(UInt32 slave_id); bool binlogDump(UInt32 slave_id, String binlog_file_name, UInt64 binlog_pos); + BinlogEvent readBinlogEvent(); String error(); private: diff --git a/src/Core/MySQLProtocol.h b/src/Core/MySQLProtocol.h index 3f2c490e6c6..8789c43b2fd 100644 --- a/src/Core/MySQLProtocol.h +++ b/src/Core/MySQLProtocol.h @@ -1451,13 +1451,7 @@ namespace ReplicationProtocol UInt32 replication_rank; UInt32 master_id; - RegisterSlave(UInt32 server_id_) - : server_id(server_id_) - , slaves_mysql_port(0x00) - , replication_rank(0x00) - , master_id(0x00) - { - } + RegisterSlave(UInt32 server_id_) : server_id(server_id_), slaves_mysql_port(0x00), replication_rank(0x00), master_id(0x00) { } void writePayloadImpl(WriteBuffer & buffer) const override { @@ -1507,6 +1501,66 @@ namespace ReplicationProtocol protected: size_t getPayloadSize() const override { return 1 + 4 + 2 + 4 + binlog_file_name.size() + 1; } }; -} + + class BinlogEvent + { + public: + BinlogEvent() = default; + + virtual bool isValid(); + + virtual void parseEvents(ReadBuffer & payload); + + virtual ~BinlogEvent(); + }; + + class MySQLBinlogEvent : public BinlogEvent + { + public: + MySQLBinlogEvent() = default; + + void parseEvents(ReadBuffer & payload) override + { + UInt16 header = 0; + payload.readStrict(reinterpret_cast(&header), 1); + } + }; + + class IFlavor + { + public: + virtual String getName() = 0; + + virtual BinlogEvent readBinlogEvent(ReadBuffer & payload); + + virtual ~IFlavor() = default; + }; + + class MySQLFlavor : public IFlavor + { + public: + MySQLFlavor() = default; + + BinlogEvent readBinlogEvent(ReadBuffer & payload) override + { + UInt16 header = 0; + payload.readStrict(reinterpret_cast(&header), 1); + switch (header) + { + case PACKET_EOF: + throw Exception("Master maybe lost", ErrorCodes::UNKNOWN_EXCEPTION); + case PACKET_ERR: + ERR_Packet err; + err.readPayloadImpl(payload); + throw Exception(err.error_message, ErrorCodes::UNKNOWN_EXCEPTION); + } + + MySQLBinlogEvent binlog_event; + binlog_event.parseEvents(payload); + return binlog_event; + } + }; +} + } } diff --git a/src/Core/tests/CMakeLists.txt b/src/Core/tests/CMakeLists.txt index a5d694b7358..f77163a7109 100644 --- a/src/Core/tests/CMakeLists.txt +++ b/src/Core/tests/CMakeLists.txt @@ -21,3 +21,6 @@ target_link_libraries (mysql_client PRIVATE dbms) add_executable (mysql_protocol mysql_protocol.cpp) target_link_libraries (mysql_protocol PRIVATE dbms) +if(USE_SSL) + target_include_directories (mysql_protocol SYSTEM PRIVATE ${OPENSSL_INCLUDE_DIR}) +endif() diff --git a/src/Core/tests/mysql_protocol.cpp b/src/Core/tests/mysql_protocol.cpp index 46cee9709f5..a6aeb4d16ea 100644 --- a/src/Core/tests/mysql_protocol.cpp +++ b/src/Core/tests/mysql_protocol.cpp @@ -176,7 +176,7 @@ int main(int, char **) return 1; } - if (!client1.binlogDump(slave_id, "", 0)) + if (!client1.binlogDump(slave_id, "", 315)) { std::cerr << "Connect Error: " << client1.error() << std::endl; assert(0);