diff --git a/table_replication_consistency/cmake_install.cmake b/table_replication_consistency/cmake_install.cmake index 07d5b05df..19eb2623d 100644 --- a/table_replication_consistency/cmake_install.cmake +++ b/table_replication_consistency/cmake_install.cmake @@ -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) diff --git a/table_replication_consistency/table_replication_listener.cpp b/table_replication_consistency/table_replication_listener.cpp index 5546a9e6d..fa3d06c4d 100644 --- a/table_replication_consistency/table_replication_listener.cpp +++ b/table_replication_consistency/table_replication_listener.cpp @@ -48,10 +48,10 @@ namespace table_replication_listener { /* Table Consistency data structure */ typedef struct { - std::string database_dot_table; /* Fully qualified db.table name, + char* database_dot_table; /* Fully qualified db.table name, primary key. */ boost::uint32_t server_id; /* Server id */ - std::string gtid; /* Global transaction id */ + char* gtid; /* Global transaction id */ boost::uint64_t binlog_pos; /* Binlog position */ bool gtid_known; /* Is gtid known ? */ } table_listener_consistency_t; @@ -75,7 +75,8 @@ boost::mutex table_replication_mutex; /* This mutex is used protect /***********************************************************************//** This is the function that is executed by replication listeners. At startup it will try to connect the server and start listening -the actual replication stream. +the actual replication stream. Stream is listened and events +are handled until a shutdown message is send from the user. @return Pointer to error message. */ void* tb_replication_listener_reader( /*=================================*/ @@ -109,9 +110,11 @@ void* tb_replication_listener_reader( Binary_log_event *event; + // While we have events while (true) { Log_event_header *lheader; + // Wait for the next event int result = binlog.wait_for_next_event(&event); if (result == ERR_EOF) @@ -132,10 +135,15 @@ void* tb_replication_listener_reader( << event->get_event_type() << " txt " << get_event_type_str(event->get_event_type()) << " query " << qevent->query << " db " << qevent->db_name + << " gtid " << gtid.get_string() << std::endl; break; } + /* + Event is global transaction identifier. We need to store + value of this and handle actual state later. + */ case GTID_EVENT_MARIADB: case GTID_EVENT_MYSQL: { @@ -145,15 +153,17 @@ void* tb_replication_listener_reader( gtid_known = true; gtid = Gtid(gevent->domain_id, gevent->server_id, gevent->sequence_number); } else { - - 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->domain_id << "-" << gevent->server_id << "-" << gevent->sequence_number - << std::endl; + // TODO MYSQL } + 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 " << gtid.get_string() + << std::endl; + + break; } @@ -209,11 +219,13 @@ void* tb_replication_listener_reader( if(not_found) { // Consistency for this table and server not found, insert a record table_listener_consistency_t* tb_c = (table_listener_consistency_t*) malloc(sizeof(table_listener_consistency_t)); - tb_c->database_dot_table = database_dot_table; + tb_c->database_dot_table = (char *)malloc(database_dot_table.size()+1); + strcpy(tb_c->database_dot_table, database_dot_table.c_str()); tb_c->server_id = lheader->server_id; tb_c->binlog_pos = lheader->next_position; tb_c->gtid_known = gtid_known; - tb_c->gtid = gtid.get_string(); + tb_c->gtid = (char *)malloc(gtid.get_string().size()+1); + strcpy(tb_c->gtid, gtid.get_string().c_str()); table_consistency_map.insert(pair(database_dot_table,tb_c)); } else { @@ -221,7 +233,9 @@ void* tb_replication_listener_reader( // consistency values tc->binlog_pos = lheader->next_position; - tc->gtid = gtid.get_string(); + free(tc->gtid); + tc->gtid = (char *)malloc(gtid.get_string().size()+1); + strcpy(tc->gtid, gtid.get_string().c_str()); tc->gtid_known = gtid_known; } @@ -232,10 +246,12 @@ void* tb_replication_listener_reader( << " txt " << get_event_type_str(event->get_event_type()) << " table " << revent->table_id << " tb " << database_dot_table + << " gtid " << gtid.get_string() << std::endl; break; } + // Default event handler, do nothing default: break; } // switch diff --git a/table_replication_consistency/test/CMakeCache.txt b/table_replication_consistency/test/CMakeCache.txt index 1c3318e21..22a87f8f6 100644 --- a/table_replication_consistency/test/CMakeCache.txt +++ b/table_replication_consistency/test/CMakeCache.txt @@ -23,7 +23,7 @@ CMAKE_BACKWARDS_COMPATIBILITY:STRING=2.4 //Choose the type of build, options are: None(CMAKE_CXX_FLAGS or // CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel. -CMAKE_BUILD_TYPE:STRING= +CMAKE_BUILD_TYPE:STRING=Debug //Enable/Disable color output during build. CMAKE_COLOR_MAKEFILE:BOOL=ON diff --git a/table_replication_consistency/test/CMakeFiles/Example.dir/flags.make b/table_replication_consistency/test/CMakeFiles/Example.dir/flags.make index 7c3a60dad..5813decfc 100644 --- a/table_replication_consistency/test/CMakeFiles/Example.dir/flags.make +++ b/table_replication_consistency/test/CMakeFiles/Example.dir/flags.make @@ -2,7 +2,7 @@ # Generated by "Unix Makefiles" Generator, CMake Version 2.8 # compile C with /usr/bin/gcc -C_FLAGS = -I/usr/local/include -I/home/jan/skysql/skygateway/skygateway/utils +C_FLAGS = -g -I/usr/local/include -I/home/jan/skysql/skygateway/skygateway/utils C_DEFINES = diff --git a/table_replication_consistency/test/CMakeFiles/Example.dir/link.txt b/table_replication_consistency/test/CMakeFiles/Example.dir/link.txt index adc6326e4..4b092da7e 100644 --- a/table_replication_consistency/test/CMakeFiles/Example.dir/link.txt +++ b/table_replication_consistency/test/CMakeFiles/Example.dir/link.txt @@ -1 +1 @@ -/usr/bin/gcc CMakeFiles/Example.dir/Example.c.o -o Example -rdynamic -Wl,-Bstatic -ltable_replication_consistency -Wl,-Bdynamic -lreplication -lboost_system -lpthread +/usr/bin/gcc -g CMakeFiles/Example.dir/Example.c.o -o Example -rdynamic -Wl,-Bstatic -ltable_replication_consistency -Wl,-Bdynamic -lreplication -lboost_system -lpthread diff --git a/table_replication_consistency/test/Example b/table_replication_consistency/test/Example index 076271805..ab7f98194 100755 Binary files a/table_replication_consistency/test/Example and b/table_replication_consistency/test/Example differ diff --git a/table_replication_consistency/test/Example.c b/table_replication_consistency/test/Example.c index 718658ad9..dbd9425da 100644 --- a/table_replication_consistency/test/Example.c +++ b/table_replication_consistency/test/Example.c @@ -3,6 +3,7 @@ #include #include #include +#include int main(int argc, char** argv) { @@ -24,7 +25,8 @@ int main(int argc, char** argv) if ( strncmp("mysql://", uri, 8) == 0) { - mrl[i].server_url = uri; + mrl[k].server_url = malloc(strlen(uri)+1); + strcpy(mrl[k].server_url, uri); k++; if (argc == 1) { diff --git a/table_replication_consistency/test/cmake_install.cmake b/table_replication_consistency/test/cmake_install.cmake index 54c6cc19f..f6b1d3578 100644 --- a/table_replication_consistency/test/cmake_install.cmake +++ b/table_replication_consistency/test/cmake_install.cmake @@ -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)