Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ before_install:
before_script:
- mkdir build
- cd build
- cmake -DCMAKE_BUILD_TYPE=Release ..
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is not related to PR with Percona 8 support. Please remove it.

- cmake -DCMAKE_BUILD_TYPE=Release ..

script:
- make
72 changes: 35 additions & 37 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ PROJECT (libslave)
OPTION (BUILD_STATIC "Force building static library" ON)
OPTION (WITH_TESTING "Enable building the tests framework" OFF)

SET (THREADS_PREFER_PTHREAD_FLAG ON)
FIND_PACKAGE (Threads REQUIRED)

# Build flags
SET (CMAKE_CXX_STANDARD 14)
SET (CMAKE_CXX_STANDARD_REQUIRED TRUE)
Expand All @@ -21,66 +24,55 @@ IF (CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
ADD_DEFINITIONS (-Wall)
ENDIF ()

# Fixes a lot of annoying warnings about auto_ptr deprecation
ADD_DEFINITIONS (-DBOOST_NO_AUTO_PTR)

SET (BOOST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
SET (BOOST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/boost)
SET (MYSQL_SRC ${CMAKE_CURRENT_SOURCE_DIR}/mysql)
SET (MYSQL_BIN ${CMAKE_BINARY_DIR}/mysql)
FILE (MAKE_DIRECTORY ${MYSQL_BIN})

INCLUDE_DIRECTORIES (
BEFORE SYSTEM
${MYSQL_BIN}/include
${MYSQL_SRC}/include
${MYSQL_SRC}/libbinlogevents/export
${BOOST_DIR}/boost_1_69_0/boost
)
ADD_CUSTOM_TARGET (
fix_static_build
WORKING_DIRECTORY ${MYSQL_BIN}
COMMAND sed -i '/GET_TARGET_PROPERTY.*libmysql/s/libmysql/perconaserverclient/' ${MYSQL_SRC}/scripts/CMakeLists.txt
)
ADD_CUSTOM_TARGET (
mysql_configure
WORKING_DIRECTORY ${MYSQL_BIN}
DEPENDS fix_static_build
COMMAND "${CMAKE_COMMAND}"
mysql_configure
WORKING_DIRECTORY ${MYSQL_BIN}
COMMAND "${CMAKE_COMMAND}"
-DCMAKE_BUILD_TYPE=Release
-DDISABLE_SHARED=1
-DENABLED_PROFILING=0
-DWITHOUT_SERVER=1
-DWITH_CLIENT_PROTOCOL_TRACING=0
-DWITH_DEFAULT_FEATURE_SET=0
-DWITH_SSL=bundled
-DWITH_SSL=system
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the reasons to change it?

-DWITH_ZLIB=bundled
-DWITH_LIBEVENT=bundled
-DWITH_LZ4=bundled
-DWITH_PROTOBUF=bundled
-DWITH_EDITLINE=bundled
-DDOWNLOAD_BOOST=1 -DWITH_BOOST=${BOOST_DIR}
-DDOWNLOAD_BOOST=1
-DDOWNLOAD_BOOST_TIMEOUT=1200
-DWITH_BOOST=${BOOST_DIR}
${MYSQL_SRC}
)

ADD_CUSTOM_TARGET (
mysqlclient_build
WORKING_DIRECTORY ${MYSQL_BIN}
DEPENDS mysql_configure
COMMAND ${CMAKE_COMMAND} --build . --target perconaserverclient
binlogevents_build
WORKING_DIRECTORY ${MYSQL_BIN}
DEPENDS mysql_configure
COMMAND ${CMAKE_COMMAND} --build . --target binlogevents_static
)

ADD_CUSTOM_TARGET (
binlogevents_build
WORKING_DIRECTORY ${MYSQL_BIN}
DEPENDS mysql_configure
COMMAND ${CMAKE_COMMAND} --build . --target binlogevents_static
mysql_client_build
WORKING_DIRECTORY ${MYSQL_BIN}
DEPENDS binlogevents_build
COMMAND ${CMAKE_COMMAND} --build . --target perconaserverclient
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems it's a formatting change and it is not related to Percona 8 support. Please remove it.

)

ADD_LIBRARY (mysqlclient STATIC IMPORTED)
ADD_DEPENDENCIES (mysqlclient mysqlclient_build)
SET_PROPERTY (TARGET mysqlclient PROPERTY IMPORTED_LOCATION ${MYSQL_BIN}/archive_output_directory/libperconaserverclient.a)

ADD_LIBRARY (binlogevents STATIC IMPORTED)
ADD_DEPENDENCIES (binlogevents binlogevents_build)
SET_PROPERTY (TARGET binlogevents PROPERTY IMPORTED_LOCATION ${MYSQL_BIN}/libbinlogevents/lib/libbinlogevents.a)
SET_PROPERTY (TARGET binlogevents PROPERTY IMPORTED_LOCATION ${MYSQL_BIN}/libbinlogevents/lib/${CMAKE_STATIC_LIBRARY_PREFIX}binlogevents${CMAKE_STATIC_LIBRARY_SUFFIX})

ADD_LIBRARY (libmysql STATIC IMPORTED)
ADD_DEPENDENCIES (libmysql mysql_client_build)
SET_TARGET_PROPERTIES (libmysql PROPERTIES IMPORTED_LOCATION ${MYSQL_BIN}/archive_output_directory/${CMAKE_STATIC_LIBRARY_PREFIX}perconaserverclient${CMAKE_STATIC_LIBRARY_SUFFIX})
SET_TARGET_PROPERTIES (libmysql PROPERTIES INTERFACE_LINK_LIBRARIES binlogevents)

ADD_DEFINITIONS (-DDBUG_OFF)
SET (LINK_TYPE STATIC)
Expand All @@ -94,9 +86,15 @@ FILE (GLOB HDR "*.h")
INSTALL (FILES ${HDR} DESTINATION include)
AUX_SOURCE_DIRECTORY (${CMAKE_CURRENT_SOURCE_DIR} SRC)

# Most probably static mysql is built without fPIC, so, we can't build dynamic library with it
ADD_LIBRARY (slave ${LINK_TYPE} ${SRC})
TARGET_LINK_LIBRARIES (slave ${MYSQL_LIBS} -lpthread)
TARGET_LINK_LIBRARIES (slave PUBLIC libmysql ssl crypto Threads::Threads m rt dl)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the reasons to remove MYSQL_LIBS here?

TARGET_INCLUDE_DIRECTORIES (slave PUBLIC
${MYSQL_BIN}/include
${MYSQL_SRC}
${MYSQL_SRC}/include
${MYSQL_SRC}/libbinlogevents/export
${BOOST_DIR}/boost_1_70_0
)
INSTALL (TARGETS slave DESTINATION lib64)

IF (WITH_TESTING)
Expand Down
27 changes: 13 additions & 14 deletions collate.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#include "nanomysql.h"
#include "collate.h"

#include <map>
#include <mysql.h>
#include <stdexcept>
#include <stdio.h>
#include <string>
#include <vector>
#include "nanomysql.h"
#include "collate.h"

using namespace slave;

Expand All @@ -20,15 +19,15 @@ collate_map_t slave::readCollateMap(nanomysql::Connection& conn)
conn.query("SHOW CHARACTER SET");
conn.store(nanores);

for (nanomysql::Connection::result_t::const_iterator i = nanores.begin(); i != nanores.end(); ++i)
for (const auto& nanore : nanores)
{
std::map<std::string, nanomysql::field>::const_iterator z = i->find("Charset");
if (z == i->end())
auto z = nanore.find("Charset");
if (z == nanore.end())
throw std::runtime_error("Slave::readCollateMap(): SHOW CHARACTER SET query did not return 'Charset'");
const std::string name = z->second.data;

z = i->find("Maxlen");
if (z == i->end())
z = nanore.find("Maxlen");
if (z == nanore.end())
throw std::runtime_error("Slave::readCollateMap(): SHOW CHARACTER SET query did not return 'Maxlen'");

const int maxlen = atoi(z->second.data.c_str());
Expand All @@ -40,17 +39,17 @@ collate_map_t slave::readCollateMap(nanomysql::Connection& conn)
conn.query("SHOW COLLATION");
conn.store(nanores);

for (nanomysql::Connection::result_t::const_iterator i = nanores.begin(); i != nanores.end(); ++i)
for (const auto& nanore : nanores)
{
collate_info ci;

std::map<std::string, nanomysql::field>::const_iterator z = i->find("Collation");
if (z == i->end())
auto z = nanore.find("Collation");
if (z == nanore.end())
throw std::runtime_error("Slave::readCollateMap(): SHOW COLLATION query did not return 'Collation'");
ci.name = z->second.data;

z = i->find("Charset");
if (z == i->end())
z = nanore.find("Charset");
if (z == nanore.end())
throw std::runtime_error("Slave::readCollateMap(): SHOW COLLATION query did not return 'Charset'");
ci.charset = z->second.data;

Expand Down
2 changes: 1 addition & 1 deletion field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const char* Field_decimal::unpack(const char *from)
int value_length = decimal_string_size(&dec);
char buffer[ value_length ];

if (::decimal2string(&dec, (char*)&buffer, &value_length, zerofill ? precision : 0, scale, '0') != E_DEC_OK) {
if (::decimal2string(&dec, (char*)&buffer, &value_length, zerofill ? precision : 0, scale) != E_DEC_OK) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are at least two supported versions of MySQL: 5.7 and 8.0 [1] [2]. This change will add compatibility with 8.x and will broke compatibility with 5.7. Perhaps we need to introduce a compilation flag (for example MYSQL57, MYSQL80) and pass it to cmake before a build.

  1. https://www.mysql.com/support/supportedplatforms/database.html
  2. https://www.percona.com/services/policies/percona-software-support-lifecycle

throw std::runtime_error("Field_decimal::unpack(): decimal2string() failed");
}

Expand Down
2 changes: 1 addition & 1 deletion mysql
Submodule mysql updated 20633 files
6 changes: 3 additions & 3 deletions nanomysql.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "MysqlGuard.h"
#include "nanofield.h"
#include <stdexcept>
#include <stdio.h>
#include <cstdio>
#include <vector>

namespace nanomysql {
Expand Down Expand Up @@ -176,7 +176,7 @@ class Connection {
{
_mysql_res_wrap re(::mysql_use_result(m_conn));

if (re.s == NULL) {
if (re.s == nullptr) {
throw_error("mysql_use_result() failed");
}

Expand All @@ -197,7 +197,7 @@ class Connection {
while (1) {
MYSQL_ROW row = ::mysql_fetch_row(re.s);

if (row == NULL) {
if (row == nullptr) {
if (::mysql_errno(m_conn) != 0) {
throw_error("mysql_fetch_row() failed");
}
Expand Down
3 changes: 3 additions & 0 deletions slave_log_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,9 @@ bool read_log_event(const char* buf, uint event_len, Basic_event_info& bei, Even
case TRANSACTION_CONTEXT_EVENT:
case VIEW_CHANGE_EVENT:
case XA_PREPARE_LOG_EVENT:
case PARTIAL_UPDATE_ROWS_EVENT:
case START_5_7_ENCRYPTION_EVENT:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like event MYSQL_END_EVENT added to slave_log_event.h is missed here.

case MARIA_EVENTS_BEGIN:
if (event_stat)
event_stat->tickOther();
return false;
Expand Down
23 changes: 23 additions & 0 deletions slave_log_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,29 @@ enum Log_event_type

XA_PREPARE_LOG_EVENT= 38,

/*
* Extension of UPDATE_ROWS_EVENT, allowing partial values according
* to binlog_row_value_options.
*/
PARTIAL_UPDATE_ROWS_EVENT = 39,

/*
* Add new events here - right above this comment!
* Existing events (except ENUM_END_EVENT) should never change their numbers
*/

/* New MySQL events are to be added right above this comment */
MYSQL_END_EVENT,

/* Add new Percona Server events here - its ids should go downwards
* starting from MARIA_EVENTS_BEGIN, i.e. 159, 158 ..
* till MYSQL_END_EVENT
*/

START_5_7_ENCRYPTION_EVENT = 159,

MARIA_EVENTS_BEGIN = 160,

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

libslave has a unit test (test/unit_test.cpp) that covers different types of events. It would be good to add new testcases for a new event types.

ENUM_END_EVENT
};

Expand Down
2 changes: 1 addition & 1 deletion table.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
namespace slave
{

typedef std::unique_ptr<Field> PtrField;
typedef std::shared_ptr<Field> PtrField;
typedef std::function<void (RecordSet&)> callback;
typedef std::function<void (const std::string&, const std::string&, const std::vector<PtrField>&)> ddl_callback;
typedef EventKind filter;
Expand Down