Fixed bug on memory allocation for string types and fixed linker problem on example main program
This commit is contained in:
parent
b51232c518
commit
471b3cbaf2
@ -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)
|
||||
|
@ -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<std::string, table_listener_consistency_t*>(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
|
||||
|
@ -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
|
||||
|
@ -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 =
|
||||
|
||||
|
@ -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
|
||||
|
Binary file not shown.
@ -3,6 +3,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
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) {
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user