Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: wangmh/mysql-replication-listener
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: bullsoft/mysql-replication-listener
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Loading
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -4,3 +4,4 @@ CMakeFiles
cmake_install.cmake
lib
tags
install_manifest.txt
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
language: cpp
compiler:
- gcc
- clang

before_install:
- echo $LANG
- echo $LC_ALL
- cmake --version
- gcc -v
- sudo apt-get install -y libboost-dev

script:
- mkdir build && cd build && cmake .. && make

notifications:
email:
- guweigang@bullsoft.org
- shangyuanchun@bullsoft.org
19 changes: 12 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
project (mysql-replication-listener)
cmake_minimum_required (VERSION 2.6)
cmake_minimum_required (VERSION 2.8)

set(MySQL_BINLOG_VERSION_MAJOR "0")
set(MySQL_BINLOG_VERSION_MINOR "0.1")
set(MRL_VERSION "${MySQL_BINLOG_VERSION_MAJOR}.${MySQL_BINLOG_VERSION_MINOR}")
set(MySQL_BINLOG_VERSION_MINOR "2")
set(MySQL_BINLOG_VERSION_PATCH "0")
set(MySQL_BINLOG_VERSION "${MySQL_BINLOG_VERSION_MAJOR}.${MySQL_BINLOG_VERSION_MINOR}.${MySQL_BINLOG_VERSION_PATCH}")

set(CMAKE_VERSION_STRING "${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}")

@@ -14,9 +15,13 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
include_directories(include)
link_directories(${PROJECT_BINARY_DIR}/lib)

# TODO: order: find asio -> allow to define asio directory -> use include/asio
# For ASIO headers
INCLUDE_DIRECTORIES(include/asio)
find_package(Boost)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_BOOST")
else(Boost_FOUND)
message(INFO "No Boost found, will not use Boost")
endif(Boost_FOUND)

# --------- Find crypt ------------------------------------------
FIND_LIBRARY(LIB_CRYPTO crypto /opt/local/lib /opt/lib /usr/lib /usr/local/lib)
@@ -26,5 +31,5 @@ add_subdirectory(src)
include(InstallRequiredSystemLibraries)

# installation configuration
install(DIRECTORY include DESTINATION /usr FILES_MATCHING PATTERN "*.h")
install(DIRECTORY include DESTINATION . FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp" PATTERN "*.ipp")

38 changes: 35 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,40 @@
mysql-replication-listener
MySQL Replication Listener
=========================

[![Build Status](https://img.shields.io/travis/BullSoft/mysql-replication-listener/master.svg?style=flat)](http://travis-ci.org/BullSoft/mysql-replication-listener)

A listener to fetch binlog from mysql server.

Reference:
https://code.launchpad.net/mysql-replication-listener
https://github.com/wangmh/mysql-replication-listener
- Origin repo: https://code.launchpad.net/mysql-replication-listener
- We forked from: https://github.com/wangmh/mysql-replication-listener

Install
--------------------
mysql-replication-listener uses cmake, so you need cmake first.

We use asio for socket communication, and it involes some **boost** libraries, so maybe you need install boost(1.47 and newer).

And then:

$ cmake . -DCMAKE_INSTALL_PREFIX=/path/to/install

$ make

$ make install


Notice
--------------------
We need to make mysql server to dump binlog-stream to us, so we need **REPLICATION SLAVE** privilege.
And We need to get master status, so we need **REPLICATION CLIENT** privilege.

If you want to set_position to a specified binlog-file and the position, we need to ensure the binlog-file and it's position are legal, so we need to execute "SHOW BINARY LOGS" on the server. Unfortunately,
In MySQL 5.1.63 and earlier, the **SUPER** privilege was required to use this statement. Starting with MYSQL 5.1.64, a user with the **REPLICATION CLIENT** privilege may also execute this statement.

So If you use MySQL 5.1.63 and earlier, you need **SUPER** privilege too.

Also, We auth privilege before binlog_dump, so we will access database **mysql** for accout checking... That means you have to give at least **READ** privilege for database mysql ...

Also notice that besides `log-bin` and `binlog-format` set in mysqld section, you should also set a `server-id` for mysql master.

14 changes: 9 additions & 5 deletions include/asio/basic_socket_iostream.hpp
Original file line number Diff line number Diff line change
@@ -19,11 +19,15 @@

#if !defined(BOOST_NO_IOSTREAM)

#include <boost/preprocessor/arithmetic/inc.hpp>
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
#include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/preprocessor/repetition/repeat_from_to.hpp>
#include <boost/utility/base_from_member.hpp>
#ifdef HAVE_BOOST
# include <boost/preprocessor/arithmetic/inc.hpp>
# include <boost/preprocessor/repetition/enum_binary_params.hpp>
# include <boost/preprocessor/repetition/enum_params.hpp>
# include <boost/preprocessor/repetition/repeat_from_to.hpp>
# include <boost/utility/base_from_member.hpp>
#else
#endif

#include "asio/basic_socket_streambuf.hpp"
#include "asio/stream_socket_service.hpp"

30 changes: 25 additions & 5 deletions include/asio/basic_socket_streambuf.hpp
Original file line number Diff line number Diff line change
@@ -20,11 +20,31 @@
#if !defined(BOOST_NO_IOSTREAM)

#include <streambuf>
#include <boost/preprocessor/arithmetic/inc.hpp>
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
#include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/preprocessor/repetition/repeat_from_to.hpp>
#include <boost/utility/base_from_member.hpp>
#ifdef HAVE_BOOST
# include <boost/preprocessor/arithmetic/inc.hpp>
# include <boost/preprocessor/repetition/enum_binary_params.hpp>
# include <boost/preprocessor/repetition/enum_params.hpp>
# include <boost/preprocessor/repetition/repeat_from_to.hpp>
# include <boost/utility/base_from_member.hpp>
#else
namespace boost {
template <typename MemberType, int UniqueID = 0>
class base_from_member
{
protected:
MemberType member;

base_from_member(): member()
{
}
};
}
# ifndef BOOST_PP_CAT
# define BOOST_PP_CAT(a, b) a ## b
# endif
# define BOOST_PP_INC(x) (x)
#endif

#include "asio/basic_socket.hpp"
#include "asio/deadline_timer_service.hpp"
#include "asio/detail/array.hpp"
14 changes: 13 additions & 1 deletion include/asio/detail/config.hpp
Original file line number Diff line number Diff line change
@@ -11,7 +11,19 @@
#ifndef ASIO_DETAIL_CONFIG_HPP
#define ASIO_DETAIL_CONFIG_HPP

#include <boost/config.hpp>
#ifdef HAVE_BOOST
# include <boost/config.hpp>
#else
# if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
# define BOOST_WINDOWS
# if !defined(__GNUC__) && !defined(BOOST_HAS_DECLSPEC)
# define BOOST_HAS_DECLSPEC
# endif
# ifdef _MSC_VER
# define BOOST_MSVC _MSC_VER
# endif
# endif
#endif

// Default to a header-only implementation. The user must specifically request
// separate compilation by defining either ASIO_SEPARATE_COMPILATION or
36 changes: 25 additions & 11 deletions include/binlog_api.h
Original file line number Diff line number Diff line change
@@ -21,6 +21,11 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
#ifndef _REPEVENT_H
#define _REPEVENT_H

// temp fix
#ifndef HAVE_BOOST
#define HAVE_BOOST
#endif

#include <iosfwd>
#include <list>
#include <cassert>
@@ -49,12 +54,16 @@ enum Error_code {

class Dummy_driver : public system::Binary_log_driver
{
public:
public:
Dummy_driver() : Binary_log_driver("", 0) {}
virtual ~Dummy_driver() {}

virtual int connect() { return 1; }

virtual int disconnect() { return ERR_OK; }

virtual int set_server_id(int server_id) { return server_id; }

virtual int wait_for_next_event(mysql::Binary_log_event **event) {
return ERR_EOF;
}
@@ -66,31 +75,33 @@ class Dummy_driver : public system::Binary_log_driver
virtual int get_position(std::string *str, unsigned long *position) {
return ERR_OK;
}

};

class Content_handler;

typedef std::list<Content_handler *> Content_handler_pipeline;

class Binary_log {
private:
private:
system::Binary_log_driver *m_driver;
Dummy_driver m_dummy_driver;
Content_handler_pipeline m_content_handlers;
unsigned long m_binlog_position;
std::string m_binlog_file;
public:
public:
Binary_log(system::Binary_log_driver *drv);
~Binary_log() {}

int connect();

int disconnect();

/**
* Blocking attempt to get the next binlog event from the stream
*/
int wait_for_next_event(Binary_log_event **event);


/**
* Inserts/removes content handlers in and out of the chain
* The Content_handler_pipeline is a derived std::list
@@ -101,9 +112,9 @@ class Binary_log {
* Set the binlog position (filename, position)
*
* @return Error_code
* @retval ERR_OK The position is updated.
* @retval ERR_EOF The position is out-of-range
* @retval >= ERR_CODE_COUNT An unspecified error occurred
* @retval ERR_OK The position is updated.
* @retval ERR_EOF The position is out-of-range
* @retval >= ERR_CODE_COUNT An unspecified error occurred
*/
int set_position(const std::string &filename, unsigned long position);

@@ -112,12 +123,15 @@ class Binary_log {
* @param position Requested position
*
* @return Error_code
* @retval ERR_OK The position is updated.
* @retval ERR_EOF The position is out-of-range
* @retval >= ERR_CODE_COUNT An unspecified error occurred
* @retval ERR_OK The position is updated.
* @retval ERR_EOF The position is out-of-range
* @retval >= ERR_CODE_COUNT An unspecified error occurred
*/
int set_position(unsigned long position);


int set_server_id(int server_id);

/**
* Fetch the binlog position for the current file
*/
7 changes: 5 additions & 2 deletions include/binlog_driver.h
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ class Binary_log_driver
{
public:
template <class FilenameT>
Binary_log_driver(const FilenameT& filename = FilenameT(), unsigned int offset = 0)
Binary_log_driver(const FilenameT& filename = FilenameT(), unsigned int offset = 0)
: m_binlog_file_name(filename), m_binlog_offset(offset)
{
}
@@ -44,9 +44,12 @@ class Binary_log_driver
* @retval 0 Success
* @retval >0 Error code (to be specified)
*/
virtual int connect()= 0;
virtual int connect() = 0;

virtual int disconnect() = 0;

virtual int set_server_id(int server_id) = 0;

/**
* Blocking attempt to get the next binlog event from the stream
* @param event [out] Pointer to a binary log event to be fetched.
Loading