Skip to content

Commit dbef714

Browse files
committed
Migrate from mysql-concpp to boost::mysql
Get rid of mysql-connector-c++ and use Boost::Mysql It's time to move on.
1 parent 57fb035 commit dbef714

22 files changed

Lines changed: 1037 additions & 672 deletions

File tree

CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,11 @@ endif(WIN32)
7777
##############################
7878
add_definitions(-DBOOST_ALL_NO_LIB)
7979
add_definitions(-DBOOST_UUID_FORCE_AUTO_LINK)
80+
add_definitions(-DBOOST_MYSQL_USE_SSL)
8081
set(Boost_USE_STATIC_LIBS ON)
8182
set(Boost_USE_MULTITHREADED ON)
8283
set(Boost_USE_STATIC_RUNTIME OFF)
83-
find_package(Boost 1.87.0 REQUIRED COMPONENTS program_options system)
84+
find_package(Boost 1.88.0 REQUIRED COMPONENTS program_options system charconv)
8485

8586
##############################
8687
# Git #
@@ -99,10 +100,9 @@ find_package(Botan 2.14.0 REQUIRED)
99100
include_directories(${BOTAN_INCLUDE_DIRS})
100101

101102
##############################
102-
# MySQL Connector C++ #
103+
# OpenSSL #
103104
##############################
104-
find_package(MySQLConnectorCPP REQUIRED)
105-
include_directories(${MYSQLCCPP_INCLUDE_DIRS})
105+
find_package(OpenSSL REQUIRED)
106106

107107
##############################
108108
# FlatBuffers #
@@ -152,4 +152,4 @@ add_subdirectory(configs)
152152
add_subdirectory(deps)
153153

154154
# Enables folder view in Visual Studio solutions
155-
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
155+
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

Dockerfile

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ RUN apt-get -y update && apt-get -y upgrade \
2323
&& apt-get -y install git \
2424
# Install required library packages
2525
&& apt-get install -y libbotan-2-dev \
26-
&& apt-get install -y libmysqlcppconn-dev \
26+
&& apt-get install -y libssl-dev \
2727
&& apt-get install -y zlib1g-dev \
2828
&& apt-get install -y libpcre3-dev \
2929
&& apt-get install -y libflatbuffers-dev \
3030
&& wget -q https://archives.boost.io/release/1.88.0/source/boost_1_88_0.tar.gz \
3131
&& tar -zxf boost_1_88_0.tar.gz \
3232
&& cd boost_1_88_0 \
33-
&& ./bootstrap.sh --with-libraries=system,program_options,headers \
33+
&& ./bootstrap.sh --with-libraries=system,program_options,headers,mysql,charconv \
3434
&& ./b2 link=static install -d0 -j $(nproc) cxxflags="-std=c++23"
3535

3636
# Copy source
@@ -42,7 +42,7 @@ WORKDIR ${working_dir}
4242
# These can be overriden by passing them through to `docker build`
4343
ARG build_optional_tools=1
4444
ARG disable_threads=0
45-
ARG build_type=Rel
45+
ARG build_type=Debug
4646
ARG install_dir=/usr/local/bin
4747

4848
# Generate Makefile & compile
@@ -62,11 +62,9 @@ ARG install_dir=/usr/local/bin
6262
ARG working_dir=/usr/src/ember
6363
WORKDIR ${install_dir}
6464
RUN apt-get -y update \
65-
&& apt-get install -y libbotan-2-19 \
66-
&& apt-get install -y libmysqlcppconn7v5 \
67-
&& apt-get install -y mysql-client
65+
&& apt-get install -y libbotan-2-19
6866
COPY --from=builder ${install_dir} ${install_dir}
6967
RUN cp configs/*.dist .
7068
COPY ./sql ${install_dir}/sql
7169
COPY ./scripts ${install_dir}
72-
COPY ./dbcs ${install_dir}/dbcs
70+
COPY ./dbcs ${install_dir}/dbcs

cmake/FindMySQLConnectorCPP.cmake

Lines changed: 0 additions & 63 deletions
This file was deleted.

src/account/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ set(LIBRARY_SRC
2525
include_directories(${SPARK_INCLUDES_DIR})
2626

2727
add_library(${LIBRARY_NAME} STATIC ${LIBRARY_HDR} ${LIBRARY_SRC})
28-
target_link_libraries(${LIBRARY_NAME} PRIVATE spark conpool logger shared ${MYSQLCCPP_LIBRARY}
29-
${BOTAN_LIBRARY} ${Boost_LIBRARIES} Threads::Threads FB_SCHEMA_COMPILE)
28+
target_link_libraries(${LIBRARY_NAME} spark conpool logger shared ${Boost_LIBRARIES}
29+
${BOTAN_LIBRARY} Threads::Threads)
3030
target_include_directories(${LIBRARY_NAME} PUBLIC ${CMAKE_BINARY_DIR})
3131

3232
add_executable(${EXECUTABLE_NAME} main.cpp)
3333
target_link_libraries(${EXECUTABLE_NAME} ${LIBRARY_NAME} logger shared ${Boost_LIBRARIES} Threads::Threads)
3434

3535
INSTALL(TARGETS ${EXECUTABLE_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
3636
set_target_properties(account PROPERTIES FOLDER "Services/Applications")
37-
set_target_properties(libaccount PROPERTIES FOLDER "Services/Libraries")
37+
set_target_properties(libaccount PROPERTIES FOLDER "Services/Libraries")

src/character/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ set(LIBRARY_SRC
2424
include_directories(${CMAKE_SOURCE_DIR}/deps/utf8cpp)
2525

2626
add_library(${LIBRARY_NAME} STATIC ${LIBRARY_HDR} ${LIBRARY_SRC})
27-
target_link_libraries(${LIBRARY_NAME} dbcreader spark logger protocol shared ${BOTAN_LIBRARY}
28-
${Boost_LIBRARIES} Threads::Threads FB_SCHEMA_COMPILE)
27+
target_link_libraries(${LIBRARY_NAME} dbcreader spark logger protocol shared
28+
${Boost_LIBRARIES} ${BOTAN_LIBRARY} Threads::Threads)
2929
target_include_directories(${LIBRARY_NAME} PUBLIC ${CMAKE_BINARY_DIR})
3030

3131
add_executable(${EXECUTABLE_NAME} main.cpp)
32-
target_link_libraries(${EXECUTABLE_NAME} ${LIBRARY_NAME} protocol dbcreader spark conpool logger shared
33-
${MYSQLCCPP_LIBRARY} ${Boost_LIBRARIES} Threads::Threads)
32+
target_link_libraries(${EXECUTABLE_NAME} ${LIBRARY_NAME} protocol dbcreader spark conpool logger shared
33+
${Boost_LIBRARIES} Threads::Threads)
3434

3535
INSTALL(TARGETS ${EXECUTABLE_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
3636
set_target_properties(character PROPERTIES FOLDER "Services/Applications")
37-
set_target_properties(libcharacter PROPERTIES FOLDER "Services/Libraries")
37+
set_target_properties(libcharacter PROPERTIES FOLDER "Services/Libraries")

src/gateway/CMakeLists.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,13 @@ set(LIBRARY_SRC
8484
)
8585

8686
add_library(${LIBRARY_NAME} STATIC ${LIBRARY_HDR} ${LIBRARY_SRC})
87-
add_dependencies(${LIBRARY_NAME} FB_SCHEMA_COMPILE)
88-
target_link_libraries(${LIBRARY_NAME} PRIVATE ${Boost_LIBRARIES} PRIVATE nsd conpool stun ports dbcreader protocol spark
89-
logger shared ${ZLIB_LIBRARY} ${BOTAN_LIBRARY} Threads::Threads)
87+
target_link_libraries(${LIBRARY_NAME} nsd conpool stun ports dbcreader protocol spark logger shared
88+
${Boost_LIBRARIES} ${BOTAN_LIBRARY} ${ZLIB_LIBRARY} Threads::Threads)
9089
target_include_directories(${LIBRARY_NAME} PUBLIC ${CMAKE_BINARY_DIR})
9190

9291
add_executable(${EXECUTABLE_NAME} main.cpp)
9392
target_link_libraries(${EXECUTABLE_NAME} ${LIBRARY_NAME} logger shared ${Boost_LIBRARIES} Threads::Threads)
9493

9594
INSTALL(TARGETS ${EXECUTABLE_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
9695
set_target_properties(gateway PROPERTIES FOLDER "Services/Applications")
97-
set_target_properties(libgateway PROPERTIES FOLDER "Services/Libraries")
96+
set_target_properties(libgateway PROPERTIES FOLDER "Services/Libraries")

src/libs/conpool/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ add_library(${LIBRARY_NAME}
2222
include/conpool/drivers/DummyDriver.h
2323
)
2424

25-
target_link_libraries(${LIBRARY_NAME} shared ${MYSQLCCPP_LIBRARY})
25+
target_link_libraries(${LIBRARY_NAME} shared ${Boost_LIBRARIES} OpenSSL::SSL OpenSSL::Crypto)
2626
target_include_directories(${LIBRARY_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
27-
set_target_properties(${LIBRARY_NAME} PROPERTIES FOLDER "Common Libraries")
27+
set_target_properties(${LIBRARY_NAME} PROPERTIES FOLDER "Common Libraries")

src/libs/conpool/include/conpool/Connection.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014 - 2024 Ember
2+
* Copyright (c) 2014 - 2025 Ember
33
*
44
* This Source Code Form is subject to the terms of the Mozilla Public
55
* License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -20,7 +20,7 @@ using namespace std::chrono_literals;
2020

2121
template<typename ConType>
2222
struct ConnDetail {
23-
ConType conn{};
23+
std::unique_ptr<ConType> conn;
2424
sc::seconds idle = 0s;
2525
unsigned int id = 0;
2626
bool empty_slot : 1 = true;
@@ -30,8 +30,8 @@ struct ConnDetail {
3030
bool sweep : 1 = false;
3131
bool refresh : 1 = false;
3232

33-
ConnDetail(const ConType& connection, unsigned int id)
34-
: conn(connection),
33+
ConnDetail(std::unique_ptr<ConType> connection, unsigned int id)
34+
: conn(std::move(connection)),
3535
id(id),
3636
empty_slot(false) {}
3737

@@ -84,11 +84,11 @@ class Connection final {
8484
Connection(const Connection<ConType>& src) = delete;
8585
Connection<ConType>& operator=(const Connection<ConType>& src) = delete;
8686

87-
ConType operator->() { return detail_.get().conn; }
88-
ConType operator*() { return detail_.get().conn; }
87+
ConType* operator->() const { return detail_.get().conn.get(); }
88+
ConType& operator*() const { return *detail_.get().conn; }
8989

9090
template<typename A, typename B, typename C, unsigned int> friend class Pool;
9191
};
9292

9393

94-
} // connection_pool, ember
94+
} // connection_pool, ember

src/libs/conpool/include/conpool/ConnectionPool.h

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ class Pool final : private ReusePolicy, private GrowthPolicy {
6868
}
6969
}
7070

71-
void open_connections(std::size_t num) {
72-
boost::container::small_vector<std::future<ConType>, size_hint> futures;
71+
void open_connections(std::size_t num) {
72+
boost::container::small_vector<std::future<std::unique_ptr<ConType>>, size_hint> futures;
7373
futures.reserve(num);
7474

7575
for(std::size_t i = 0; i < num; ++i) {
@@ -106,7 +106,7 @@ class Pool final : private ReusePolicy, private GrowthPolicy {
106106
if(!cd.error && !cd.sweep && !cd.empty_slot) {
107107
if(cd.dirty && !return_clean()) {
108108
try {
109-
if(driver_.clean(cd.conn)) {
109+
if(driver_.clean(*cd.conn)) {
110110
cd.dirty = false;
111111
} else {
112112
cd.sweep = true;
@@ -116,6 +116,7 @@ class Pool final : private ReusePolicy, private GrowthPolicy {
116116
if(log_cb_) {
117117
log_cb_(Severity::DEBUG, "On connection clean: "s + e.what());
118118
}
119+
119120
return false;
120121
}
121122
}
@@ -128,9 +129,8 @@ class Pool final : private ReusePolicy, private GrowthPolicy {
128129

129130
return false;
130131
}
131-
132+
132133
std::optional<Connection<ConType>> get_connection() {
133-
driver_.thread_enter();
134134

135135
#ifdef DEBUG_NO_THREADS
136136
manager_.run();
@@ -149,7 +149,7 @@ class Pool final : private ReusePolicy, private GrowthPolicy {
149149
res = std::ranges::find_if(pool_, [&](auto& arg) {
150150
return find_free_connection(arg);
151151
});
152-
152+
153153
if(res == pool_.end()) {
154154
return std::nullopt;
155155
}
@@ -161,19 +161,18 @@ class Pool final : private ReusePolicy, private GrowthPolicy {
161161
this->return_connection(arg);
162162
}, *res);
163163
}
164-
164+
165165
public:
166166
Pool(Driver& driver, std::size_t min_size, std::size_t max_size,
167167
sc::seconds max_idle, sc::seconds interval = 15s)
168168
: driver_(driver),
169169
min_(min_size),
170-
max_(max_size),
170+
max_(max_size),
171171
manager_(this, interval, max_idle),
172172
pool_(max_size),
173173
pool_guards_(max_size),
174174
size_(0),
175175
closed_(false) {
176-
driver_.thread_enter();
177176

178177
if(!max_size) {
179178
throw exception("Max. database connections cannot be zero");
@@ -203,15 +202,14 @@ class Pool final : private ReusePolicy, private GrowthPolicy {
203202
BOOST_ASSERT_MSG(!c.checked_out, "Closed connection pool without returning all connections.");
204203

205204
try {
206-
driver_.close(c.conn);
207-
} catch(const std::exception& e) {
205+
driver_.close(std::move(c.conn));
206+
} catch(const std::exception& e) {
208207
if(log_cb_) {
209208
log_cb_(Severity::ERROR, "Closing pool, driver threw: "s + e.what());
210209
}
211210
}
212211
}
213212

214-
driver_.thread_exit();
215213
}
216214

217215
void close() {
@@ -234,7 +232,7 @@ class Pool final : private ReusePolicy, private GrowthPolicy {
234232
continue;
235233
}
236234

237-
driver_.close(c.conn);
235+
driver_.close(std::move(c.conn));
238236
}
239237

240238
if(active) {
@@ -260,7 +258,7 @@ class Pool final : private ReusePolicy, private GrowthPolicy {
260258
*/
261259
Connection<ConType> acquire() {
262260
std::optional<Connection<ConType>> conn;
263-
261+
264262
while(!(conn = get_connection())) {
265263
semaphore_.acquire();
266264
}
@@ -283,7 +281,7 @@ class Pool final : private ReusePolicy, private GrowthPolicy {
283281
while(!(conn = get_connection())) {
284282
sc::milliseconds elapsed = sc::duration_cast<sc::milliseconds>
285283
(sc::high_resolution_clock::now() - start);
286-
284+
287285
if(elapsed >= duration) {
288286
throw no_free_connections();
289287
}
@@ -301,7 +299,7 @@ class Pool final : private ReusePolicy, private GrowthPolicy {
301299
auto& detail = connection.detail_.get();
302300

303301
if(return_clean()) {
304-
if(!driver_.clean(detail.conn)) {
302+
if(!driver_.clean(*detail.conn)) {
305303
detail.dirty = true;
306304
detail.sweep = true;
307305
}
@@ -314,7 +312,6 @@ class Pool final : private ReusePolicy, private GrowthPolicy {
314312
std::atomic_thread_fence(std::memory_order_release);
315313
pool_guards_[detail.id].store(false, std::memory_order_relaxed);
316314

317-
driver_.thread_exit();
318315
manager_.check_exceptions();
319316
semaphore_.release();
320317
}
@@ -340,4 +337,4 @@ class Pool final : private ReusePolicy, private GrowthPolicy {
340337
}
341338
};
342339

343-
} // connection_pool, ember
340+
} // connection_pool, ember

0 commit comments

Comments
 (0)