Fixes to MySQL GTID handling. Still can't execute COM_BINLOG_DUMP_GTID.
This commit is contained in:
parent
59b0eee999
commit
427fee618a
@ -79,16 +79,6 @@ install/local: preinstall
|
||||
install/local/fast: install/local
|
||||
.PHONY : install/local/fast
|
||||
|
||||
# Special rule for the target install/strip
|
||||
install/strip: preinstall
|
||||
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing the project stripped..."
|
||||
/usr/bin/cmake -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake
|
||||
.PHONY : install/strip
|
||||
|
||||
# Special rule for the target install/strip
|
||||
install/strip/fast: install/strip
|
||||
.PHONY : install/strip/fast
|
||||
|
||||
# Special rule for the target list_install_components
|
||||
list_install_components:
|
||||
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Available install components are: \"Unspecified\""
|
||||
@ -172,6 +162,11 @@ replication_shared/fast:
|
||||
$(MAKE) -f src/CMakeFiles/replication_shared.dir/build.make src/CMakeFiles/replication_shared.dir/build
|
||||
.PHONY : replication_shared/fast
|
||||
|
||||
# Manual pre-install relink rule for target.
|
||||
replication_shared/preinstall:
|
||||
$(MAKE) -f src/CMakeFiles/replication_shared.dir/build.make src/CMakeFiles/replication_shared.dir/preinstall
|
||||
.PHONY : replication_shared/preinstall
|
||||
|
||||
#=============================================================================
|
||||
# Target rules for targets named replication_static
|
||||
|
||||
@ -246,7 +241,6 @@ help:
|
||||
@echo "... edit_cache"
|
||||
@echo "... install"
|
||||
@echo "... install/local"
|
||||
@echo "... install/strip"
|
||||
@echo "... list_install_components"
|
||||
@echo "... package"
|
||||
@echo "... package_source"
|
||||
|
@ -12,7 +12,7 @@ IF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
|
||||
STRING(REGEX REPLACE "^[^A-Za-z0-9_]+" ""
|
||||
CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}")
|
||||
ELSE(BUILD_TYPE)
|
||||
SET(CMAKE_INSTALL_CONFIG_NAME "")
|
||||
SET(CMAKE_INSTALL_CONFIG_NAME "Debug")
|
||||
ENDIF(BUILD_TYPE)
|
||||
MESSAGE(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"")
|
||||
ENDIF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
|
||||
|
@ -39,181 +39,181 @@ static char* server_groups[] = {
|
||||
|
||||
void* binlog_reader(void * arg)
|
||||
{
|
||||
replication_listener_t *rlt = (replication_listener_t*)arg;
|
||||
char *uri = rlt->server_url;
|
||||
map<int, string> tid2tname;
|
||||
map<int, string>::iterator tb_it;
|
||||
pthread_t id = pthread_self();
|
||||
string database_dot_table;
|
||||
const char* server_type;
|
||||
Gtid gtid(std::string("62cda1d0e3a011e289d76ac0855a31e8:54"));
|
||||
try {
|
||||
Binary_log binlog(create_transport(uri));
|
||||
binlog.connect(gtid);
|
||||
replication_listener_t *rlt = (replication_listener_t*)arg;
|
||||
char *uri = rlt->server_url;
|
||||
map<int, string> tid2tname;
|
||||
map<int, string>::iterator tb_it;
|
||||
pthread_t id = pthread_self();
|
||||
string database_dot_table;
|
||||
const char* server_type;
|
||||
Gtid gtid("62cda1d0e3a011e289d76ac0855a31e8:10");
|
||||
|
||||
server_type = binlog.get_mysql_server_type_str();
|
||||
try {
|
||||
Binary_log binlog(create_transport(uri));
|
||||
binlog.connect(gtid);
|
||||
|
||||
cout << "Server " << uri << " type: " << server_type << endl;
|
||||
server_type = binlog.get_mysql_server_type_str();
|
||||
|
||||
Binary_log_event *event;
|
||||
cout << "Server " << uri << " type: " << server_type << endl;
|
||||
|
||||
while (true) {
|
||||
Log_event_header *lheader;
|
||||
Binary_log_event *event;
|
||||
|
||||
int result = binlog.wait_for_next_event(&event);
|
||||
while (true) {
|
||||
Log_event_header *lheader;
|
||||
|
||||
if (result == ERR_EOF)
|
||||
break;
|
||||
int result = binlog.wait_for_next_event(&event);
|
||||
|
||||
lheader = event->header();
|
||||
if (result == ERR_EOF)
|
||||
break;
|
||||
|
||||
switch(event->get_event_type()) {
|
||||
lheader = event->header();
|
||||
|
||||
case QUERY_EVENT: {
|
||||
Query_event *qevent = dynamic_cast<Query_event *>(event);
|
||||
switch(event->get_event_type()) {
|
||||
|
||||
std::cout << "Thread: " << id << " server_id " << lheader->server_id
|
||||
<< " position " << lheader->next_position << " : Found event of type "
|
||||
<< event->get_event_type()
|
||||
<< " txt " << get_event_type_str(event->get_event_type())
|
||||
<< " query " << qevent->query << " db " << qevent->db_name
|
||||
<< std::endl;
|
||||
break;
|
||||
}
|
||||
case QUERY_EVENT: {
|
||||
Query_event *qevent = dynamic_cast<Query_event *>(event);
|
||||
|
||||
case GTID_EVENT_MARIADB:
|
||||
case GTID_EVENT_MYSQL:
|
||||
{
|
||||
Gtid_event *gevent = dynamic_cast<Gtid_event *>(event);
|
||||
std::cout << "Thread: " << id << " server_id " << lheader->server_id
|
||||
<< " position " << lheader->next_position << " : Found event of type "
|
||||
<< event->get_event_type()
|
||||
<< " txt " << get_event_type_str(event->get_event_type())
|
||||
<< " query " << qevent->query << " db " << qevent->db_name
|
||||
<< std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
std::cout << "Thread: " << id << " server_id " << lheader->server_id
|
||||
<< " position " << lheader->next_position << " : Found event of type "
|
||||
<< event->get_event_type()
|
||||
<< " txt " << get_event_type_str(event->get_event_type())
|
||||
<< " GTID " << gevent->m_gtid.get_string()
|
||||
<< " GTID2" << gevent->m_gtid.get_mysql_gtid()
|
||||
<< std::endl;
|
||||
case GTID_EVENT_MARIADB:
|
||||
case GTID_EVENT_MYSQL: {
|
||||
Gtid_event *gevent = dynamic_cast<Gtid_event *>(event);
|
||||
|
||||
break;
|
||||
std::cout << "Thread: " << id << " server_id " << lheader->server_id
|
||||
<< " position " << lheader->next_position << " : Found event of type "
|
||||
<< event->get_event_type()
|
||||
<< " txt " << get_event_type_str(event->get_event_type())
|
||||
<< " GTID " << std::string(gevent->m_gtid.get_mysql_gtid())
|
||||
<< " GTID " << gevent->m_gtid.get_string()
|
||||
<< std::endl;
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case TABLE_MAP_EVENT: {
|
||||
Table_map_event *table_map_event= dynamic_cast<Table_map_event*>(event);
|
||||
database_dot_table= table_map_event->db_name;
|
||||
database_dot_table.append(".");
|
||||
database_dot_table.append(table_map_event->table_name);
|
||||
tid2tname[table_map_event->table_id]= database_dot_table;
|
||||
break;
|
||||
}
|
||||
case TABLE_MAP_EVENT: {
|
||||
Table_map_event *table_map_event= dynamic_cast<Table_map_event*>(event);
|
||||
database_dot_table= table_map_event->db_name;
|
||||
database_dot_table.append(".");
|
||||
database_dot_table.append(table_map_event->table_name);
|
||||
tid2tname[table_map_event->table_id]= database_dot_table;
|
||||
break;
|
||||
}
|
||||
|
||||
case WRITE_ROWS_EVENT:
|
||||
case UPDATE_ROWS_EVENT:
|
||||
case DELETE_ROWS_EVENT:
|
||||
{
|
||||
Row_event *revent = dynamic_cast<Row_event*>(event);
|
||||
tb_it= tid2tname.begin();
|
||||
tb_it= tid2tname.find(revent->table_id);
|
||||
if (tb_it != tid2tname.end())
|
||||
case WRITE_ROWS_EVENT:
|
||||
case UPDATE_ROWS_EVENT:
|
||||
case DELETE_ROWS_EVENT: {
|
||||
Row_event *revent = dynamic_cast<Row_event*>(event);
|
||||
tb_it= tid2tname.begin();
|
||||
tb_it= tid2tname.find(revent->table_id);
|
||||
if (tb_it != tid2tname.end())
|
||||
{
|
||||
database_dot_table= tb_it->second;
|
||||
}
|
||||
|
||||
std::cout << "Thread: " << id << " server_id " << lheader->server_id
|
||||
<< " position " << lheader->next_position << " : Found event of type "
|
||||
<< event->get_event_type()
|
||||
<< " txt " << get_event_type_str(event->get_event_type())
|
||||
<< " table " << revent->table_id
|
||||
<< " tb " << database_dot_table
|
||||
<< std::endl;
|
||||
break;
|
||||
|
||||
}
|
||||
default:
|
||||
break;
|
||||
} // switch
|
||||
} // while
|
||||
} // try
|
||||
catch(ListenerException e)
|
||||
{
|
||||
database_dot_table= tb_it->second;
|
||||
std::cerr << "Listener exception: " << e.what() << std::endl;
|
||||
}
|
||||
catch(boost::system::error_code e)
|
||||
{
|
||||
std::cerr << "Listener system error: " << e.message() << std::endl;
|
||||
}
|
||||
// Try and catch all exceptions
|
||||
catch(std::exception const& e)
|
||||
{
|
||||
std::cerr << "Listener other error: " << e.what() << std::endl;
|
||||
}
|
||||
// Rest of them
|
||||
catch(...)
|
||||
{
|
||||
std::cerr << "Unknown exception: " << std::endl;
|
||||
// Re-Throw this one.
|
||||
// It was not handled so you want to make sure it is handled correctly by
|
||||
// the OS. So just allow the exception to keep propagating.
|
||||
throw;
|
||||
}
|
||||
|
||||
std::cout << "Thread: " << id << " server_id " << lheader->server_id
|
||||
<< " position " << lheader->next_position << " : Found event of type "
|
||||
<< event->get_event_type()
|
||||
<< " txt " << get_event_type_str(event->get_event_type())
|
||||
<< " table " << revent->table_id
|
||||
<< " tb " << database_dot_table
|
||||
<< std::endl;
|
||||
break;
|
||||
|
||||
}
|
||||
default:
|
||||
break;
|
||||
} // switch
|
||||
} // while
|
||||
} // try
|
||||
catch(ListenerException e)
|
||||
{
|
||||
std::cerr << "Listener exception: " << e.what() << std::endl;
|
||||
}
|
||||
catch(boost::system::error_code e)
|
||||
{
|
||||
std::cerr << "Listener system error: " << e.message() << std::endl;
|
||||
}
|
||||
// Try and catch all exceptions
|
||||
catch(std::exception const& e)
|
||||
{
|
||||
std::cerr << "Listener other error: " << e.what() << std::endl;
|
||||
}
|
||||
// Rest of them
|
||||
catch(...)
|
||||
{
|
||||
std::cerr << "Unknown exception: " << std::endl;
|
||||
// Re-Throw this one.
|
||||
// It was not handled so you want to make sure it is handled correctly by
|
||||
// the OS. So just allow the exception to keep propagating.
|
||||
throw;
|
||||
}
|
||||
|
||||
pthread_exit(NULL);
|
||||
return NULL;
|
||||
pthread_exit(NULL);
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
int number_of_args = argc;
|
||||
int i=0,k=0;
|
||||
pthread_t *tid=NULL;
|
||||
char *uri;
|
||||
replication_listener_t *mrl;
|
||||
int err=0;
|
||||
int number_of_args = argc;
|
||||
int i=0,k=0;
|
||||
pthread_t *tid=NULL;
|
||||
char *uri;
|
||||
replication_listener_t *mrl;
|
||||
int err=0;
|
||||
|
||||
tid = (pthread_t*)malloc(sizeof(pthread_t) * argc);
|
||||
mrl = (replication_listener_t*)calloc(argc, sizeof(replication_listener_t));
|
||||
tid = (pthread_t*)malloc(sizeof(pthread_t) * argc);
|
||||
mrl = (replication_listener_t*)calloc(argc, sizeof(replication_listener_t));
|
||||
|
||||
if (argc < 2) {
|
||||
std::cerr << "Usage: basic-2 <uri>" << std::endl;
|
||||
exit(2);
|
||||
}
|
||||
if (argc < 2) {
|
||||
std::cerr << "Usage: basic-2 <uri>" << std::endl;
|
||||
exit(2);
|
||||
}
|
||||
|
||||
mysql_server_init(num_elements, server_options, server_groups);
|
||||
if (mysql_server_init(num_elements, server_options, server_groups)) {
|
||||
std::cerr << "Failed to init MySQL server" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
argc =0;
|
||||
while(argc != number_of_args)
|
||||
{
|
||||
uri= argv[argc++];
|
||||
argc =0;
|
||||
while(argc != number_of_args)
|
||||
{
|
||||
uri= argv[argc++];
|
||||
|
||||
if ( strncmp("mysql://", uri, 8) == 0)
|
||||
{
|
||||
if ( strncmp("mysql://", uri, 8) == 0) {
|
||||
|
||||
mrl[i].server_url = uri;
|
||||
mrl[i].server_url = uri;
|
||||
|
||||
if (argc == 1) {
|
||||
mrl[i].is_master = 1;
|
||||
}
|
||||
if (argc == 1) {
|
||||
mrl[i].is_master = 1;
|
||||
}
|
||||
|
||||
err = pthread_create(&(tid[i++]), NULL, &binlog_reader, (void *)&mrl[i]);
|
||||
err = pthread_create(&(tid[i++]), NULL, &binlog_reader, (void *)&mrl[i]);
|
||||
|
||||
if (err ) {
|
||||
perror(NULL);
|
||||
break;
|
||||
}
|
||||
if (err ) {
|
||||
perror(NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}//end of outer while loop
|
||||
}
|
||||
}//end of outer while loop
|
||||
|
||||
for(k=0; k < i; k++)
|
||||
{
|
||||
err = pthread_join(tid[k], (void **)&(mrl[k]));
|
||||
for(k=0; k < i; k++)
|
||||
{
|
||||
err = pthread_join(tid[k], (void **)&(mrl[k]));
|
||||
|
||||
if (err) {
|
||||
perror(NULL);
|
||||
}
|
||||
}
|
||||
if (err) {
|
||||
perror(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
exit(0);
|
||||
exit(0);
|
||||
|
||||
}
|
||||
|
@ -186,7 +186,7 @@ public:
|
||||
boost::uint32_t domain_id;
|
||||
boost::uint32_t server_id;
|
||||
boost::uint64_t sequence_number;
|
||||
std::string m_mysql_gtid;
|
||||
char m_mysql_gtid[MYSQL_GTID_ENCODED_SIZE];
|
||||
Gtid m_gtid;
|
||||
};
|
||||
|
||||
|
@ -44,28 +44,32 @@ enum mysql_server_types {
|
||||
MYSQL_SERVER_TYPE_MYSQL = 2
|
||||
};
|
||||
|
||||
#define MYSQL_GTID_ENCODED_SIZE 24
|
||||
|
||||
class Gtid
|
||||
{
|
||||
public:
|
||||
|
||||
Gtid()
|
||||
: m_real_gtid(false), m_domain_id(0), m_server_id(0), m_sequence_number(0), m_mysql_gtid(""), m_server_type(MYSQL_SERVER_TYPE_NA)
|
||||
{}
|
||||
: m_real_gtid(false), m_domain_id(0), m_server_id(0), m_sequence_number(0), m_server_type(MYSQL_SERVER_TYPE_NA)
|
||||
{
|
||||
memset(m_mysql_gtid, 0, MYSQL_GTID_ENCODED_SIZE);
|
||||
}
|
||||
|
||||
Gtid(const boost::uint32_t domain_id,
|
||||
const boost::uint32_t server_id,
|
||||
const boost::uint64_t sequence_number);
|
||||
|
||||
Gtid(const std::string &mysql_gtid,
|
||||
Gtid(const char *mysql_gtid,
|
||||
const boost::uint64_t gno);
|
||||
|
||||
Gtid(const std::string &mysql_gtid);
|
||||
Gtid(const char *mysql_gtid);
|
||||
|
||||
~Gtid() {}
|
||||
|
||||
bool is_real_gtid() const { return m_real_gtid;}
|
||||
|
||||
const std::string& get_mysql_gtid() const { return m_mysql_gtid; }
|
||||
const char* get_mysql_gtid() const { return m_mysql_gtid; }
|
||||
|
||||
std::string get_string() const;
|
||||
|
||||
@ -82,7 +86,7 @@ class Gtid
|
||||
boost::uint32_t m_server_id;
|
||||
boost::uint64_t m_sequence_number;
|
||||
|
||||
std::string m_mysql_gtid;
|
||||
char m_mysql_gtid[MYSQL_GTID_ENCODED_SIZE];
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -79,16 +79,6 @@ install/local: preinstall
|
||||
install/local/fast: install/local
|
||||
.PHONY : install/local/fast
|
||||
|
||||
# Special rule for the target install/strip
|
||||
install/strip: preinstall
|
||||
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing the project stripped..."
|
||||
/usr/bin/cmake -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake
|
||||
.PHONY : install/strip
|
||||
|
||||
# Special rule for the target install/strip
|
||||
install/strip/fast: install/strip
|
||||
.PHONY : install/strip/fast
|
||||
|
||||
# Special rule for the target list_install_components
|
||||
list_install_components:
|
||||
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Available install components are: \"Unspecified\""
|
||||
@ -173,6 +163,11 @@ replication_shared/fast:
|
||||
cd /home/jan/skysql/skygateway/skygateway/replication_listener && $(MAKE) -f src/CMakeFiles/replication_shared.dir/build.make src/CMakeFiles/replication_shared.dir/build
|
||||
.PHONY : replication_shared/fast
|
||||
|
||||
# Manual pre-install relink rule for target.
|
||||
replication_shared/preinstall:
|
||||
cd /home/jan/skysql/skygateway/skygateway/replication_listener && $(MAKE) -f CMakeFiles/Makefile2 src/CMakeFiles/replication_shared.dir/preinstall
|
||||
.PHONY : replication_shared/preinstall
|
||||
|
||||
# Convenience name for target.
|
||||
src/CMakeFiles/replication_static.dir/rule:
|
||||
cd /home/jan/skysql/skygateway/skygateway/replication_listener && $(MAKE) -f CMakeFiles/Makefile2 src/CMakeFiles/replication_static.dir/rule
|
||||
@ -601,7 +596,6 @@ help:
|
||||
@echo "... edit_cache"
|
||||
@echo "... install"
|
||||
@echo "... install/local"
|
||||
@echo "... install/strip"
|
||||
@echo "... list_install_components"
|
||||
@echo "... package"
|
||||
@echo "... package_source"
|
||||
|
@ -12,7 +12,7 @@ IF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
|
||||
STRING(REGEX REPLACE "^[^A-Za-z0-9_]+" ""
|
||||
CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}")
|
||||
ELSE(BUILD_TYPE)
|
||||
SET(CMAKE_INSTALL_CONFIG_NAME "")
|
||||
SET(CMAKE_INSTALL_CONFIG_NAME "Debug")
|
||||
ENDIF(BUILD_TYPE)
|
||||
MESSAGE(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"")
|
||||
ENDIF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
|
||||
@ -33,37 +33,11 @@ IF(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)
|
||||
ENDIF(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)
|
||||
|
||||
IF(NOT CMAKE_INSTALL_COMPONENT OR "${CMAKE_INSTALL_COMPONENT}" STREQUAL "Unspecified")
|
||||
FOREACH(file
|
||||
"$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/lib/libreplication.so.0.1"
|
||||
"$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/lib/libreplication.so.1"
|
||||
"$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/lib/libreplication.so"
|
||||
)
|
||||
IF(EXISTS "${file}" AND
|
||||
NOT IS_SYMLINK "${file}")
|
||||
FILE(RPATH_CHECK
|
||||
FILE "${file}"
|
||||
RPATH "")
|
||||
ENDIF()
|
||||
ENDFOREACH()
|
||||
FILE(INSTALL DESTINATION "${CMAKE_INSTALL_PREFIX}/lib" TYPE SHARED_LIBRARY FILES
|
||||
"/home/jan/skysql/skygateway/skygateway/replication_listener/lib/libreplication.so.0.1"
|
||||
"/home/jan/skysql/skygateway/skygateway/replication_listener/lib/libreplication.so.1"
|
||||
"/home/jan/skysql/skygateway/skygateway/replication_listener/lib/libreplication.so"
|
||||
"/home/jan/skysql/skygateway/skygateway/replication_listener/src/CMakeFiles/CMakeRelink.dir/libreplication.so.0.1"
|
||||
"/home/jan/skysql/skygateway/skygateway/replication_listener/src/CMakeFiles/CMakeRelink.dir/libreplication.so.1"
|
||||
"/home/jan/skysql/skygateway/skygateway/replication_listener/src/CMakeFiles/CMakeRelink.dir/libreplication.so"
|
||||
)
|
||||
FOREACH(file
|
||||
"$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/lib/libreplication.so.0.1"
|
||||
"$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/lib/libreplication.so.1"
|
||||
"$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/lib/libreplication.so"
|
||||
)
|
||||
IF(EXISTS "${file}" AND
|
||||
NOT IS_SYMLINK "${file}")
|
||||
FILE(RPATH_REMOVE
|
||||
FILE "${file}")
|
||||
IF(CMAKE_INSTALL_DO_STRIP)
|
||||
EXECUTE_PROCESS(COMMAND "/usr/bin/strip" "${file}")
|
||||
ENDIF(CMAKE_INSTALL_DO_STRIP)
|
||||
ENDIF()
|
||||
ENDFOREACH()
|
||||
ENDIF(NOT CMAKE_INSTALL_COMPONENT OR "${CMAKE_INSTALL_COMPONENT}" STREQUAL "Unspecified")
|
||||
|
||||
IF(NOT CMAKE_INSTALL_COMPONENT OR "${CMAKE_INSTALL_COMPONENT}" STREQUAL "Unspecified")
|
||||
|
@ -25,6 +25,9 @@ Author: Jan Lindström jan.lindstrom@skysql.com
|
||||
#include <boost/bind.hpp>
|
||||
#include "gtid.h"
|
||||
#include "listener_exception.h"
|
||||
#include <mysql.h>
|
||||
#include <my_global.h>
|
||||
#include <my_byteorder.h>
|
||||
|
||||
namespace mysql
|
||||
{
|
||||
@ -36,23 +39,23 @@ namespace mysql
|
||||
m_domain_id(domain_id),
|
||||
m_server_id(server_id),
|
||||
m_sequence_number(sequence_number),
|
||||
m_mysql_gtid(""),
|
||||
m_server_type(MYSQL_SERVER_TYPE_MARIADB)
|
||||
{
|
||||
memset(m_mysql_gtid, 0, MYSQL_GTID_ENCODED_SIZE);
|
||||
}
|
||||
|
||||
Gtid::Gtid(const std::string& mysql_gtid,
|
||||
Gtid::Gtid(const char *mysql_gtid,
|
||||
const boost::uint64_t gno)
|
||||
:m_real_gtid(true),
|
||||
m_domain_id(0),
|
||||
m_server_id(0),
|
||||
m_sequence_number(gno),
|
||||
m_mysql_gtid(mysql_gtid),
|
||||
m_server_type(MYSQL_SERVER_TYPE_MYSQL)
|
||||
{
|
||||
memcpy(m_mysql_gtid, mysql_gtid, MYSQL_GTID_ENCODED_SIZE);
|
||||
}
|
||||
|
||||
Gtid::Gtid(const std::string& mysql_gtid)
|
||||
Gtid::Gtid(const char* mysql_gtid)
|
||||
:m_real_gtid(true),
|
||||
m_domain_id(0),
|
||||
m_server_id(0),
|
||||
@ -60,21 +63,20 @@ namespace mysql
|
||||
m_server_type(MYSQL_SERVER_TYPE_MYSQL)
|
||||
{
|
||||
int i,k;
|
||||
unsigned char tmp[2];
|
||||
unsigned char *sid = (unsigned char *)mysql_gtid.c_str();
|
||||
char tmp[2];
|
||||
char *sid = (char *)mysql_gtid;
|
||||
|
||||
for(i=0; i < 16*2; i+=2) {
|
||||
for(i=0,k=0; i < 16*2; i+=2,k++) {
|
||||
unsigned int c;
|
||||
tmp[0] = sid[i];
|
||||
tmp[1] = sid[i+1];
|
||||
sscanf((const char *)tmp, "%02x", &c);
|
||||
tmp[0] = (unsigned char)c;
|
||||
tmp[1] = '\0';
|
||||
m_mysql_gtid.append(std::string((const char *)tmp));
|
||||
m_mysql_gtid[k]=(unsigned char)c;
|
||||
}
|
||||
i++;
|
||||
k++;
|
||||
sscanf((const char *)&(sid[i]), "%lu", &m_sequence_number);
|
||||
m_mysql_gtid.append(to_string(m_sequence_number));
|
||||
int8store(&(m_mysql_gtid[k]), m_sequence_number);
|
||||
|
||||
std::cout << "GTID:: " << m_mysql_gtid << " " << std::endl;
|
||||
}
|
||||
@ -85,8 +87,8 @@ namespace mysql
|
||||
return (to_string(m_domain_id) + std::string("-") + to_string(m_server_id) + std::string("-") + to_string(m_sequence_number));
|
||||
} else {
|
||||
std::string hexs;
|
||||
unsigned char *sid = (unsigned char *)m_mysql_gtid.c_str();
|
||||
unsigned char tmp[5];
|
||||
char *sid = (char *)m_mysql_gtid;
|
||||
char tmp[2];
|
||||
|
||||
// Dump the encoded SID using hexadesimal representation
|
||||
// Making it little bit more usefull
|
||||
|
@ -24,6 +24,10 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
#include "protocol.h"
|
||||
#include "listener_exception.h"
|
||||
#include <iostream>
|
||||
#include <mysql.h>
|
||||
#include <my_global.h>
|
||||
#include <my_byteorder.h>
|
||||
|
||||
using namespace mysql;
|
||||
using namespace mysql::system;
|
||||
|
||||
@ -405,53 +409,31 @@ Query_event *proto_query_event(std::istream &is, Log_event_header *header)
|
||||
return qev;
|
||||
}
|
||||
|
||||
// Don't know better way to do this
|
||||
#define uchar unsigned char
|
||||
#define uint32 boost::uint32_t
|
||||
#define ulonglong unsigned long long
|
||||
|
||||
#define uint8korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) +\
|
||||
(((uint32) ((uchar) (A)[1])) << 8) +\
|
||||
(((uint32) ((uchar) (A)[2])) << 16) +\
|
||||
(((uint32) ((uchar) (A)[3])) << 24)) +\
|
||||
(((ulonglong) (((uint32) ((uchar) (A)[4])) +\
|
||||
(((uint32) ((uchar) (A)[5])) << 8) +\
|
||||
(((uint32) ((uchar) (A)[6])) << 16) +\
|
||||
(((uint32) ((uchar) (A)[7])) << 24))) <<\
|
||||
32))
|
||||
|
||||
Gtid_event *proto_gtid_event(std::istream &is, Log_event_header *header)
|
||||
{
|
||||
Gtid_event *gev=new Gtid_event(header);
|
||||
boost::uint32_t gtid_length=0;
|
||||
|
||||
// For MariaDB
|
||||
Protocol_chunk<boost::uint32_t> proto_gtid_event_domain_id(gev->domain_id);
|
||||
gev->server_id = header->server_id;
|
||||
Protocol_chunk<boost::uint64_t> proto_gtid_event_sequence_number(gev->sequence_number);
|
||||
std::string tmp;
|
||||
|
||||
// For MySQL
|
||||
Protocol_chunk<boost::uint32_t> proto_gtid_length(gtid_length);
|
||||
|
||||
if (header->type_code == GTID_EVENT_MARIADB) {
|
||||
Protocol_chunk<boost::uint32_t> proto_gtid_event_domain_id(gev->domain_id);
|
||||
gev->server_id = header->server_id;
|
||||
Protocol_chunk<boost::uint64_t> proto_gtid_event_sequence_number(gev->sequence_number);
|
||||
|
||||
// In MariaDB GTIDs are just sequence number followed by domain id
|
||||
is >> proto_gtid_event_sequence_number
|
||||
>> proto_gtid_event_domain_id;
|
||||
gev->m_gtid= Gtid(gev->domain_id, gev->server_id, gev->sequence_number);
|
||||
} else {
|
||||
boost::uint8_t flags=0;
|
||||
Protocol_chunk<boost::uint8_t> proto_flags(flags); // commit flag
|
||||
Protocol_chunk_string proto_sid(gev->m_mysql_gtid, 24); // encoded
|
||||
// SID
|
||||
char *sid;
|
||||
|
||||
is /* >> proto_flags */
|
||||
>> proto_sid;
|
||||
|
||||
sid = (char *)gev->m_mysql_gtid.c_str();
|
||||
|
||||
gev->sequence_number = uint8korr(sid+16);
|
||||
// In MySQL GTIDs consists two parts SID and global sequence
|
||||
// number. SID is stored in encoded format, we will not try to
|
||||
// understand that. Global sequence number is more meaningfull.
|
||||
unsigned char gtid_data[MYSQL_GTID_ENCODED_SIZE+1];
|
||||
memset(gtid_data, 0, MYSQL_GTID_ENCODED_SIZE+1);
|
||||
is.read((char *)gtid_data, MYSQL_GTID_ENCODED_SIZE);
|
||||
unsigned char *buf = gtid_data;
|
||||
buf++; // commit flag, ignore
|
||||
memcpy(gev->m_mysql_gtid, (char *)buf, MYSQL_GTID_ENCODED_SIZE);
|
||||
gev->sequence_number = uint8korr(buf+16);
|
||||
|
||||
gev->m_gtid= Gtid(gev->m_mysql_gtid, gev->sequence_number);
|
||||
}
|
||||
|
@ -587,7 +587,7 @@ void Binlog_tcp_driver::start_binlog_dump(const Gtid gtid)
|
||||
// package
|
||||
Protocol_chunk<boost::uint64_t> prot_pos(pos);
|
||||
Protocol_chunk<boost::uint32_t> prot_binlog_name_size(binlog_name_size);
|
||||
gtid_size = gtid.get_mysql_gtid().size();
|
||||
gtid_size = MYSQL_GTID_ENCODED_SIZE;
|
||||
Protocol_chunk<boost::uint32_t> prot_gtid_size(gtid_size);
|
||||
|
||||
command_request_stream
|
||||
@ -597,8 +597,11 @@ void Binlog_tcp_driver::start_binlog_dump(const Gtid gtid)
|
||||
<< prot_binlog_name_size
|
||||
<< binlog_file_name
|
||||
<< prot_pos
|
||||
<< prot_gtid_size
|
||||
<< gtid.get_mysql_gtid();
|
||||
<< prot_gtid_size;
|
||||
|
||||
// Need to do special handling because GTTID is encoded and can
|
||||
// contain \0 characters.
|
||||
command_request_stream.write((const char *)gtid.get_mysql_gtid(), MYSQL_GTID_ENCODED_SIZE);
|
||||
|
||||
int size=server_messages.size();
|
||||
char command_packet_header[4];
|
||||
|
Loading…
x
Reference in New Issue
Block a user