Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【腾讯犀牛鸟开源课题实战】对接mysql sdk #188

Open
wants to merge 48 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
887e380
Basic Executor;
KosmosFult Sep 3, 2024
6f15be1
mysql: update MysqlResults and MysqlServiceProxy frame
KosmosFult Sep 8, 2024
58f7c5b
mysql: add annotation
KosmosFult Sep 9, 2024
64d8cbb
add connection pool
PoloDyBala Sep 9, 2024
02c4d79
add character_set
PoloDyBala Sep 9, 2024
744f1fd
fix error
PoloDyBala Sep 10, 2024
785e45e
add parse config file
PoloDyBala Sep 10, 2024
06c39e4
use trpc/util/time.h
PoloDyBala Sep 10, 2024
639acee
add parse config
PoloDyBala Sep 10, 2024
a885815
add parse config test
PoloDyBala Sep 11, 2024
51b1bef
fix varible define
PoloDyBala Sep 11, 2024
ba8251b
fix config parse test
PoloDyBala Sep 12, 2024
f9d96c3
add pool into serviceproxy
PoloDyBala Sep 12, 2024
f0aa64a
add executor manager
PoloDyBala Sep 16, 2024
baa85fe
fix error
PoloDyBala Sep 16, 2024
2540aeb
fix:config
PoloDyBala Sep 17, 2024
8b87544
add empty mysql codec
PoloDyBala Sep 17, 2024
4fe5018
add vec
PoloDyBala Sep 17, 2024
ee72e7c
Add MysqlExecutor error check
KosmosFult Sep 21, 2024
78545cf
Add MysqlExecutor Blob support
KosmosFult Sep 22, 2024
3cbd818
Add IterMode for MysqlResults.
KosmosFult Sep 23, 2024
7fdea4a
Refactor MysqlExecutorManager and MysqlServiceProxy
KosmosFult Sep 28, 2024
930e792
add thread_local
PoloDyBala Sep 28, 2024
e3ed65f
add valid
PoloDyBala Sep 29, 2024
8d5123c
add vaild
PoloDyBala Sep 29, 2024
6a099eb
fix:test
PoloDyBala Sep 30, 2024
9a2d419
add:test
PoloDyBala Sep 30, 2024
7b87fc5
Update ServiceProxy
KosmosFult Sep 30, 2024
a973d7b
Update MysqlResults
KosmosFult Oct 4, 2024
cf1adb5
Update MysqlResults. using string_view in MysqlResultsMode::NativeStr…
KosmosFult Oct 5, 2024
0eb8542
add test
PoloDyBala Oct 6, 2024
ac3f174
proxy:add tmp conn
PoloDyBala Oct 6, 2024
e4cb88d
fix:unique_ptr
PoloDyBala Oct 7, 2024
65ee445
Refactor MysqlExecutorPool with two implements. Add Simple Sync Trans…
KosmosFult Oct 8, 2024
2f00d59
Delete redundant code.
KosmosFult Oct 8, 2024
c7ead55
add examples
PoloDyBala Oct 8, 2024
4469b8e
import libmysqlclient dependency
KosmosFult Oct 10, 2024
db50c5d
Fix libprotobuf conflict in the libmysqlclient dependency.
KosmosFult Oct 10, 2024
af5c541
feature: MysqlServiceProxy supports async transaction
KosmosFult Oct 10, 2024
24dd9db
fixed mysqlresult IterMode error; deleted redundant code; added idle …
KosmosFult Oct 11, 2024
f6256d7
add cmake dependency for mysqlclient
KosmosFult Oct 12, 2024
a6c6f86
update example mysql
KosmosFult Oct 12, 2024
ece0672
Refactor mysql executor related code structure for improved organization
KosmosFult Oct 13, 2024
2592d90
Change the return type for MysqlFieldIterator::operator*() from strin…
KosmosFult Oct 14, 2024
c907db1
update msyql_client.md; add char_set to mysql_client_conf.h; remove I…
KosmosFult Oct 22, 2024
81e9d81
remove libmysqlclient unnecessary dependency; fixed MysqlServiceProxy…
KosmosFult Oct 22, 2024
9bfdae2
add TxConcurrency to mysql_service_proxy_test.cc;
KosmosFult Oct 25, 2024
ac7febf
add bind output type check;
KosmosFult Oct 25, 2024
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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ include(snappy)
include(lz4)
include(toml11)
include(flatbuffers)
include(mysqlclient)

#---------------------------------------------------------------------------------------
# Set complie options and include other libs if options are ON
Expand Down
4 changes: 3 additions & 1 deletion cmake/config/trpc_config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ set(INCLUDE_PATHS ${TRPC_ROOT_PATH}
${TRPC_ROOT_PATH}/cmake_third_party/nghttp2/lib/includes
${TRPC_ROOT_PATH}/cmake_third_party/picohttpparser
${TRPC_ROOT_PATH}/cmake_third_party/snappy
${TRPC_ROOT_PATH}/cmake_third_party/lz4)
${TRPC_ROOT_PATH}/cmake_third_party/lz4
${TRPC_ROOT_PATH}/cmake_third_party/mysqlclient/include)

# When use tRPC as a third-party library, selectively inject the header files at including any-lib.cmake.
set(TARGET_INCLUDE_PATHS ${TRPC_ROOT_PATH})
Expand Down Expand Up @@ -106,6 +107,7 @@ set(LIBS_BASIC
snappy
lz4
flatbuffers
mysqlclient
pthread
z
dl
Expand Down
52 changes: 52 additions & 0 deletions cmake/mysqlclient.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# mysqlclient.cmake

include(FetchContent)


if(NOT DEFINED MYSQLCLIENT_VERSION_TAG)
set(MYSQLCLIENT_VERSION_TAG 8.0.39)
endif()

string(REGEX REPLACE "^([0-9]+\\.[0-9]+)\\..*" "\\1" MYSQLCLIENT_MAJOR_VER "${MYSQLCLIENT_VERSION_TAG}")
set(MYSQLCLIENT_URL "https://dev.mysql.com/get/Downloads/MySQL-${MYSQLCLIENT_MAJOR_VER}/mysql-${MYSQLCLIENT_VERSION_TAG}-linux-glibc2.17-x86_64-minimal.tar.xz")


FetchContent_Declare(
mysqlclient
URL ${MYSQLCLIENT_URL}
SOURCE_DIR ${TRPC_ROOT_PATH}/cmake_third_party/mysqlclient
)

FetchContent_GetProperties(mysqlclient)
if(NOT mysqlclient_POPULATED)
FetchContent_Populate(mysqlclient)
endif()

set(MYSQLCLIENT_INCLUDE_DIR "${mysqlclient_SOURCE_DIR}/include")
set(MYSQLCLIENT_LIB_DIR "${mysqlclient_SOURCE_DIR}/lib")


file(MAKE_DIRECTORY "${MYSQLCLIENT_INCLUDE_DIR}/mysqlclient")
file(GLOB MYSQL_HEADERS "${mysqlclient_SOURCE_DIR}/include/*.h")

# for #include "mysqlclient/mysql.h", otherwise we will directly #include "mysql.h"
file(COPY ${MYSQL_HEADERS} DESTINATION "${MYSQLCLIENT_INCLUDE_DIR}/mysqlclient")


add_library(mysqlclient STATIC IMPORTED)
Copy link
Contributor

Choose a reason for hiding this comment

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

libmysqlclient支持so的编译吗?如果支持,可以也加上,可以参照框架其他三方so的cmake引入方式引入


set_target_properties(mysqlclient PROPERTIES
IMPORTED_LOCATION "${MYSQLCLIENT_LIB_DIR}/libmysqlclient.a"
INTERFACE_INCLUDE_DIRECTORIES "${MYSQLCLIENT_INCLUDE_DIR}"
)

target_link_libraries(mysqlclient INTERFACE
"${MYSQLCLIENT_LIB_DIR}/private/libcrypto.so"
Copy link
Contributor

Choose a reason for hiding this comment

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

动态链这些库的话,服务二进制程序,是不是也要带上这些动态库?

比如,我把服务二进制程序拷贝到另一个容器里,是不是就不能运行了?

Choose a reason for hiding this comment

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

原本的包里有libmysqlclient.a和libmysqlclient.so,但都不能单独用,都依赖一堆private目录里的一些动态库

Copy link
Contributor

Choose a reason for hiding this comment

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

ldd看下libmysqlclient.a,是否全依赖了这些so库?

Choose a reason for hiding this comment

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

已修改,只依赖ssl和crypto

Copy link
Contributor

Choose a reason for hiding this comment

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

这个libcrypto.so是编译产生的吗?还是mysqlclient代码仓库里带的?

能复用系统库路径里ssl和crypto动态库吗?这两个库不太好随程序二进制发布而发布

"${MYSQLCLIENT_LIB_DIR}/private/libssl.so"
)

add_library(trpc_mysqlclient ALIAS mysqlclient)


set(TARGET_INCLUDE_PATHS ${TARGET_INCLUDE_PATHS} ${TRPC_ROOT_PATH}/cmake_third_party/mysqlclient/include)
set(TARGET_LINK_LIBS ${TARGET_LINK_LIBS} trpc_mysqlclient)
505 changes: 505 additions & 0 deletions docs/zh/mysql_client.md

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions examples/features/mysql/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

cmake_minimum_required(VERSION 3.14)

include(../cmake/common.cmake)

#---------------------------------------------------------------------------------------
# Compile project
#---------------------------------------------------------------------------------------
project(features_mysql)

# compile client
file(GLOB SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/client/fiber/*.cc)
add_executable(fiber_client ${SRC_FILES})
target_link_libraries(fiber_client ${LIBRARY})

file(GLOB SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/client/future/*.cc)
add_executable(future_client ${SRC_FILES})
target_link_libraries(future_client ${LIBRARY})
20 changes: 20 additions & 0 deletions examples/features/mysql/client/create_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
CREATE DATABASE IF NOT EXISTS test;

USE test;

DROP TABLE IF EXISTS users;

CREATE TABLE `users` (
`id` int NOT NULL AUTO_INCREMENT,
`username` varchar(50) NOT NULL,
`email` varchar(100) DEFAULT NULL,
`created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`meta` blob,
PRIMARY KEY (`id`)
);

INSERT INTO users (username, email, created_at, meta) VALUES
('alice', 'alice@example.com', '2024-09-08 13:16:24', NULL),
('bob', 'bob@abc.com', '2024-09-08 13:16:24', NULL),
('carol', 'carol@example.com', '2024-09-08 13:16:24', NULL),
('rose', NULL, '2024-09-08 13:16:53', NULL);
15 changes: 15 additions & 0 deletions examples/features/mysql/client/fiber/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cc_binary(
name = "fiber_client",
srcs = ["fiber_client.cc"],
deps = [
"@com_github_gflags_gflags//:gflags",
"@trpc_cpp//trpc/client:client_context",
"@trpc_cpp//trpc/client:make_client_context",
"@trpc_cpp//trpc/client:trpc_client",
"@trpc_cpp//trpc/client/mysql:mysql_service_proxy",
"@trpc_cpp//trpc/common:runtime_manager",
"@trpc_cpp//trpc/common:trpc_plugin",
"@trpc_cpp//trpc/coroutine:fiber",
"@trpc_cpp//trpc/util:latch",
],
)
Loading
Loading