Skip to content

Commit cf57972

Browse files
authored
[feat](cloud) Support fdb multi version clients (#59360)
1 parent c28afa3 commit cf57972

File tree

6 files changed

+352
-67
lines changed

6 files changed

+352
-67
lines changed

cloud/CMakeLists.txt

Lines changed: 17 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -394,67 +394,12 @@ if (ENABLE_INJECTION_POINT)
394394
add_definitions(-DENABLE_INJECTION_POINT)
395395
endif()
396396

397-
# Add libs if needed, download to current dir -- ${BUILD_DIR}
398-
set(FDB_LIB "fdb_lib_7_1_23.tar.xz")
399-
if (ARCH_AARCH64)
400-
set(FDB_LIB "fdb_lib_7_1_57.aarch64.tar.xz")
401-
endif ()
402-
file(GLOB RELEASE_FILE_LIST LIST_DIRECTORIES false "/etc/*release*")
403-
execute_process(COMMAND "cat" ${RELEASE_FILE_LIST}
404-
RESULT_VARIABLE CAT_RET_CODE
405-
OUTPUT_VARIABLE CAT_RET_CONTENT)
406-
string(TOUPPER "${CAT_RET_CONTENT}" CAT_RET_CONTENT)
407-
408-
if (ARCH_AARCH64)
409-
message("Centos OS")
410-
SET(OS_RELEASE "Centos")
411-
set(FDB_LIB_URL "https://doris-build.oss-cn-beijing.aliyuncs.com/thirdparty/fdb/aarch64/")
412-
string(APPEND FDB_LIB_URL "${FDB_LIB}")
413-
set(FDB_LIB_MD5SUM "2d01a431b7a7465077e4ae5520f89693")
414-
else ()
415-
if ("${CAT_RET_CONTENT}" MATCHES "UBUNTU")
416-
message("Ubuntu OS")
417-
SET(OS_RELEASE "Ubuntu")
418-
set(FDB_LIB_URL "https://doris-build.oss-cn-beijing.aliyuncs.com/thirdparty/fdb/ubuntu/")
419-
string(APPEND FDB_LIB_URL "${FDB_LIB}")
420-
set(FDB_LIB_MD5SUM "a00fe45da95cfac4e0caffa274bb2b30")
421-
else()
422-
# If it is not ubuntu, it is regarded as centos by default
423-
message("Centos OS")
424-
SET(OS_RELEASE "Centos")
425-
set(FDB_LIB_URL "https://doris-build.oss-cn-beijing.aliyuncs.com/thirdparty/fdb/centos/")
426-
string(APPEND FDB_LIB_URL "${FDB_LIB}")
427-
set(FDB_LIB_MD5SUM "f9839a564849c0232a351143b4340de0")
428-
endif()
429-
endif()
430-
431-
if (NOT EXISTS "${THIRDPARTY_SRC}/${FDB_LIB}")
432-
file(MAKE_DIRECTORY ${THIRDPARTY_SRC})
433-
execute_process(COMMAND curl --retry 10 --retry-delay 2 --retry-max-time 30 ${FDB_LIB_URL}
434-
-o ${THIRDPARTY_SRC}/${FDB_LIB} -k
435-
RESULTS_VARIABLE DOWNLOAD_RET)
436-
if (NOT ${DOWNLOAD_RET} STREQUAL "0")
437-
execute_process(COMMAND "rm" "-rf" "${THIRDPARTY_SRC}/${FDB_LIB}")
438-
message(FATAL_ERROR "Failed to download dependency of fdb ${FDB_LIB_URL}, remove it")
439-
endif ()
440-
endif ()
441-
442-
# Add fdb dependencies
443-
add_definitions(-DFDB_API_VERSION=710)
444-
if (NOT EXISTS ${THIRDPARTY_DIR}/include/foundationdb)
445-
execute_process(COMMAND "md5sum" "${THIRDPARTY_SRC}/${FDB_LIB}"
446-
RESULT_VARIABLE MD5SUM_RET_CODE
447-
OUTPUT_VARIABLE MD5SUM_CONTENT)
448-
if (NOT "${MD5SUM_CONTENT}" MATCHES "${FDB_LIB_MD5SUM}")
449-
execute_process(COMMAND "rm" "-rf" "${THIRDPARTY_SRC}/${FDB_LIB}")
450-
message(FATAL_ERROR "${THIRDPARTY_SRC}/${FDB_LIB} md5sum check failed, remove it")
451-
endif ()
452-
execute_process(COMMAND tar xf ${THIRDPARTY_SRC}/${FDB_LIB} -C ${THIRDPARTY_DIR}/)
453-
endif ()
454-
455397
# enable glog custom prefix
456398
add_definitions(-DGLOG_CUSTOM_PREFIX_SUPPORT)
457399

400+
set(FDB_VERSIONS "7.1.57" "7.3.69")
401+
set(FDB_DEFAULT_VERSION "7.1.57")
402+
include(install_fdb)
458403
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lfdb_c -L${THIRDPARTY_DIR}/lib")
459404

460405
set(DORIS_CLOUD_LIBS
@@ -556,3 +501,17 @@ install(FILES
556501
GROUP_READ GROUP_WRITE GROUP_EXECUTE
557502
WORLD_READ WORLD_EXECUTE
558503
DESTINATION ${OUTPUT_DIR}/lib)
504+
505+
foreach(version ${FDB_VERSIONS})
506+
if (version STREQUAL ${FDB_DEFAULT_VERSION})
507+
continue()
508+
endif()
509+
510+
string(REPLACE "." "_" version_underscored ${version})
511+
install(FILES
512+
${FDB_INSTALL_DIR_${version_underscored}}/lib64/libfdb_c.so
513+
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
514+
GROUP_READ GROUP_WRITE GROUP_EXECUTE
515+
WORLD_READ WORLD_EXECUTE
516+
DESTINATION ${OUTPUT_DIR}/lib/fdb/${version}/libfdb_c.so)
517+
endforeach()

cloud/cmake/install_fdb.cmake

Lines changed: 280 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,280 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
# ============================================================================
19+
# FDB Library Configuration
20+
# ============================================================================
21+
# Configuration format:
22+
# FDB_CONFIG_${version}_${arch}_${os}_FILE - Tarball filename
23+
# FDB_CONFIG_${version}_${arch}_${os}_MD5 - MD5 checksum
24+
# FDB_CONFIG_${version}_${arch}_${os}_URL - Base download URL
25+
# FDB_CONFIG_${version}_API_VERSION - FDB API version (e.g., 710)
26+
#
27+
# Supported combinations:
28+
# - version: 7_1_23, 7_1_57
29+
# - arch: AMD64, AARCH64
30+
# - os: UBUNTU, CENTOS (all uppercase)
31+
# ============================================================================
32+
33+
# Version 7.1.23 Configuration
34+
set(FDB_CONFIG_7_1_23_API_VERSION "710")
35+
36+
# Version 7.1.23 - AMD64 - UBUNTU
37+
set(FDB_CONFIG_7_1_23_AMD64_UBUNTU_FILE "fdb_lib_7_1_23.tar.xz")
38+
set(FDB_CONFIG_7_1_23_AMD64_UBUNTU_MD5 "a00fe45da95cfac4e0caffa274bb2b30")
39+
set(FDB_CONFIG_7_1_23_AMD64_UBUNTU_URL "https://doris-build.oss-cn-beijing.aliyuncs.com/thirdparty/fdb/ubuntu/")
40+
41+
# Version 7.1.23 - AMD64 - CENTOS
42+
set(FDB_CONFIG_7_1_23_AMD64_CENTOS_FILE "fdb_lib_7_1_23.tar.xz")
43+
set(FDB_CONFIG_7_1_23_AMD64_CENTOS_MD5 "f9839a564849c0232a351143b4340de0")
44+
set(FDB_CONFIG_7_1_23_AMD64_CENTOS_URL "https://doris-build.oss-cn-beijing.aliyuncs.com/thirdparty/fdb/centos/")
45+
46+
# Version 7.1.57 Configuration
47+
set(FDB_CONFIG_7_1_57_API_VERSION "710")
48+
49+
# Version 7.1.57 - AARCH64 - CENTOS
50+
set(FDB_CONFIG_7_1_57_AARCH64_CENTOS_FILE "fdb_lib_7_1_57.aarch64.tar.xz")
51+
set(FDB_CONFIG_7_1_57_AARCH64_CENTOS_MD5 "2d01a431b7a7465077e4ae5520f89693")
52+
set(FDB_CONFIG_7_1_57_AARCH64_CENTOS_URL "https://doris-build.oss-cn-beijing.aliyuncs.com/thirdparty/fdb/aarch64/")
53+
54+
# Version 7.1.57 - AMD64 - UBUNTU
55+
set(FDB_CONFIG_7_1_57_AMD64_UBUNTU_FILE "fdb_lib_7_1_57.tar.xz")
56+
set(FDB_CONFIG_7_1_57_AMD64_UBUNTU_MD5 "5a4aec35de0e041b952a3e39078f327a")
57+
set(FDB_CONFIG_7_1_57_AMD64_UBUNTU_URL "https://doris-build.oss-cn-beijing.aliyuncs.com/thirdparty/fdb/amd64/")
58+
59+
# Version 7.1.57 - AMD64 - CENTOS
60+
set(FDB_CONFIG_7_1_57_AMD64_CENTOS_FILE "fdb_lib_7_1_57.tar.xz")
61+
set(FDB_CONFIG_7_1_57_AMD64_CENTOS_MD5 "5a4aec35de0e041b952a3e39078f327a")
62+
set(FDB_CONFIG_7_1_57_AMD64_CENTOS_URL "https://doris-build.oss-cn-beijing.aliyuncs.com/thirdparty/fdb/amd64/")
63+
64+
# Version 7.3.69 Configuration
65+
set(FDB_CONFIG_7_3_69_API_VERSION "730")
66+
67+
# Version 7.3.69 - AARCH64 - CENTOS
68+
set(FDB_CONFIG_7_3_69_AARCH64_CENTOS_FILE "fdb_lib_7_3_69.tar.xz")
69+
set(FDB_CONFIG_7_3_69_AARCH64_CENTOS_MD5 "7c6c676b41c70ef31eca617de7879364")
70+
set(FDB_CONFIG_7_3_69_AARCH64_CENTOS_URL "https://doris-build.oss-cn-beijing.aliyuncs.com/thirdparty/fdb/aarch64/")
71+
72+
# Version 7.3.69 - AMD64 - UBUNTU
73+
set(FDB_CONFIG_7_3_69_AMD64_UBUNTU_FILE "fdb_lib_7_3_69.tar.xz")
74+
set(FDB_CONFIG_7_3_69_AMD64_UBUNTU_MD5 "5454db8a8aaa4bcc580c1a40d1171f61")
75+
set(FDB_CONFIG_7_3_69_AMD64_UBUNTU_URL "https://doris-build.oss-cn-beijing.aliyuncs.com/thirdparty/fdb/amd64/")
76+
77+
# Version 7.3.69 - AMD64 - CENTOS
78+
set(FDB_CONFIG_7_3_69_AMD64_CENTOS_FILE "fdb_lib_7_3_69.tar.xz")
79+
set(FDB_CONFIG_7_3_69_AMD64_CENTOS_MD5 "5454db8a8aaa4bcc580c1a40d1171f61")
80+
set(FDB_CONFIG_7_3_69_AMD64_CENTOS_URL "https://doris-build.oss-cn-beijing.aliyuncs.com/thirdparty/fdb/amd64/")
81+
82+
# ============================================================================
83+
# Detect OS (run once)
84+
# ============================================================================
85+
86+
if (NOT DEFINED FDB_OS_DETECTED)
87+
file(GLOB RELEASE_FILE_LIST LIST_DIRECTORIES false "/etc/*release*")
88+
execute_process(COMMAND "cat" ${RELEASE_FILE_LIST}
89+
RESULT_VARIABLE CAT_RET_CODE
90+
OUTPUT_VARIABLE CAT_RET_CONTENT)
91+
string(TOUPPER "${CAT_RET_CONTENT}" CAT_RET_CONTENT)
92+
93+
if ("${CAT_RET_CONTENT}" MATCHES "UBUNTU")
94+
set(FDB_OS_RELEASE "UBUNTU" CACHE INTERNAL "Detected OS for FDB")
95+
else()
96+
# If it is not ubuntu, it is regarded as centos by default
97+
set(FDB_OS_RELEASE "CENTOS" CACHE INTERNAL "Detected OS for FDB")
98+
endif()
99+
100+
set(FDB_OS_DETECTED TRUE CACHE INTERNAL "OS detection flag")
101+
message(STATUS "Detected OS: ${FDB_OS_RELEASE}")
102+
endif()
103+
104+
# ============================================================================
105+
# Function: Download and Setup FDB Library
106+
# ============================================================================
107+
# Downloads, verifies, and extracts a specific version of FDB library
108+
#
109+
# Parameters:
110+
# version - FDB version in format like "7_1_23" or "7_1_57"
111+
#
112+
# Exports:
113+
# FDB_INSTALL_DIR_${version} - Installation directory for this version
114+
# FDB_LIB_SO_${version} - Path to libfdb_c.so for this version
115+
# ============================================================================
116+
117+
function(download_and_setup_fdb version)
118+
# Determine architecture
119+
if (ARCH_AARCH64)
120+
set(fdb_arch "AARCH64")
121+
else()
122+
set(fdb_arch "AMD64")
123+
endif()
124+
125+
# Construct configuration variable names
126+
set(config_prefix "FDB_CONFIG_${version}_${fdb_arch}_${FDB_OS_RELEASE}")
127+
set(fdb_file_var "${config_prefix}_FILE")
128+
set(fdb_md5_var "${config_prefix}_MD5")
129+
set(fdb_url_var "${config_prefix}_URL")
130+
set(fdb_api_version_var "FDB_CONFIG_${version}_API_VERSION")
131+
132+
# Check if all required configurations exist
133+
set(missing_configs "")
134+
if (NOT DEFINED ${fdb_file_var})
135+
list(APPEND missing_configs ${fdb_file_var})
136+
endif()
137+
if (NOT DEFINED ${fdb_md5_var})
138+
list(APPEND missing_configs ${fdb_md5_var})
139+
endif()
140+
if (NOT DEFINED ${fdb_url_var})
141+
list(APPEND missing_configs ${fdb_url_var})
142+
endif()
143+
if (NOT DEFINED ${fdb_api_version_var})
144+
list(APPEND missing_configs ${fdb_api_version_var})
145+
endif()
146+
147+
if (missing_configs)
148+
message(FATAL_ERROR "FDB version ${version} is missing required configurations for "
149+
"architecture ${fdb_arch} and OS ${FDB_OS_RELEASE}:\n"
150+
" Missing variables: ${missing_configs}\n"
151+
" Please add the following configurations:\n"
152+
" ${fdb_file_var}\n"
153+
" ${fdb_md5_var}\n"
154+
" ${fdb_url_var}\n"
155+
" ${fdb_api_version_var}")
156+
endif()
157+
158+
# Get configuration values
159+
set(fdb_lib ${${fdb_file_var}})
160+
set(fdb_md5 ${${fdb_md5_var}})
161+
set(fdb_url ${${fdb_url_var}})
162+
163+
string(APPEND fdb_url "${fdb_lib}")
164+
165+
# Set version-specific installation directory
166+
string(REPLACE "_" "." version_dotted ${version})
167+
set(install_dir "${THIRDPARTY_DIR}/lib/fdb/${version_dotted}")
168+
set(lib_so "${install_dir}/lib64/libfdb_c.so")
169+
170+
# Download FDB library if not exists
171+
if (NOT EXISTS "${THIRDPARTY_SRC}/${fdb_lib}")
172+
message(STATUS "Downloading FDB library from ${fdb_url}")
173+
file(MAKE_DIRECTORY ${THIRDPARTY_SRC})
174+
execute_process(COMMAND curl --retry 10 --retry-delay 2 --retry-max-time 30 ${fdb_url}
175+
-o ${THIRDPARTY_SRC}/${fdb_lib} -k
176+
RESULTS_VARIABLE download_ret)
177+
if (NOT ${download_ret} STREQUAL "0")
178+
execute_process(COMMAND "rm" "-rf" "${THIRDPARTY_SRC}/${fdb_lib}")
179+
message(FATAL_ERROR "Failed to download dependency of fdb ${fdb_url}, remove it")
180+
endif ()
181+
endif ()
182+
183+
if (NOT EXISTS ${install_dir}/include/foundationdb)
184+
execute_process(COMMAND "md5sum" "${THIRDPARTY_SRC}/${fdb_lib}"
185+
RESULT_VARIABLE md5sum_ret_code
186+
OUTPUT_VARIABLE md5sum_content)
187+
if (NOT "${md5sum_content}" MATCHES "${fdb_md5}")
188+
execute_process(COMMAND "rm" "-rf" "${THIRDPARTY_SRC}/${fdb_lib}")
189+
message(FATAL_ERROR "${THIRDPARTY_SRC}/${fdb_lib} md5sum check failed, remove it")
190+
endif ()
191+
192+
make_directory(${install_dir})
193+
execute_process(COMMAND tar xf ${THIRDPARTY_SRC}/${fdb_lib} -C ${install_dir})
194+
endif ()
195+
196+
# Export version-specific API version to parent scope
197+
set(api_version_var "FDB_CONFIG_${version}_API_VERSION")
198+
if (DEFINED ${api_version_var})
199+
set(FDB_API_VERSION_${version} "${${api_version_var}}" PARENT_SCOPE)
200+
endif()
201+
202+
# Export to parent scope
203+
set(FDB_INSTALL_DIR_${version} "${install_dir}" PARENT_SCOPE)
204+
set(FDB_LIB_SO_${version} "${lib_so}" PARENT_SCOPE)
205+
206+
message(STATUS "FDB ${version_dotted} installation directory: ${install_dir}")
207+
endfunction()
208+
209+
# ============================================================================
210+
# Function: Setup Default FDB Library
211+
# ============================================================================
212+
# Sets up the default FDB library for static linking
213+
#
214+
# Parameters:
215+
# version - FDB version to use as default (e.g., "7_1_23")
216+
#
217+
# Exports:
218+
# FDB_INSTALL_DIR - Installation directory for default version
219+
# FDB_LIB_SO - Path to libfdb_c.so for default version
220+
# ============================================================================
221+
222+
function(setup_default_fdb version)
223+
string(REPLACE "_" "." version_dotted ${version})
224+
225+
# Ensure the version has been downloaded and set up
226+
if (NOT DEFINED FDB_INSTALL_DIR_${version})
227+
message(FATAL_ERROR "FDB version ${version_dotted} has not been downloaded. Call download_and_setup_fdb first.")
228+
endif()
229+
230+
set(FDB_INSTALL_DIR "${FDB_INSTALL_DIR_${version}}")
231+
set(FDB_LIB_SO "${FDB_LIB_SO_${version}}")
232+
233+
# Set default FDB paths to parent scope
234+
set(FDB_INSTALL_DIR "${FDB_INSTALL_DIR_${version}}" PARENT_SCOPE)
235+
set(FDB_LIB_SO "${FDB_LIB_SO_${version}}" PARENT_SCOPE)
236+
237+
# Install the default FDB library
238+
execute_process(COMMAND "rm" "-rf" "${THIRDPARTY_DIR}/include/foundationdb")
239+
execute_process(COMMAND "rm" "-rf" "${THIRDPARTY_DIR}/lib64/libfdb_c.so")
240+
execute_process(COMMAND "cp" "-r" "${FDB_INSTALL_DIR}/include/foundationdb" "${THIRDPARTY_DIR}/include/foundationdb")
241+
execute_process(COMMAND "cp" "${FDB_INSTALL_DIR}/lib64/libfdb_c.so" "${THIRDPARTY_DIR}/lib64/libfdb_c.so")
242+
243+
# Set FDB API version for the default version
244+
set(api_version_var "FDB_CONFIG_${version}_API_VERSION")
245+
if (DEFINED ${api_version_var})
246+
set(fdb_api_version "${${api_version_var}}")
247+
add_definitions(-DFDB_API_VERSION=${fdb_api_version})
248+
message(STATUS "Default FDB API version: ${fdb_api_version}")
249+
else()
250+
message(WARNING "FDB API version not defined for version ${version_dotted}")
251+
endif()
252+
endfunction()
253+
254+
function(install_fdb_library target_dir)
255+
install(FILES
256+
${THIRDPARTY_DIR}/lib/libfdb_c.so
257+
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
258+
GROUP_READ GROUP_WRITE GROUP_EXECUTE
259+
WORLD_READ WORLD_EXECUTE
260+
DESTINATION ${OUTPUT_DIR}/lib)
261+
endfunction()
262+
263+
# ============================================================================
264+
# Main Execution
265+
# ============================================================================
266+
267+
# Download and setup all specified FDB versions
268+
foreach (version IN LISTS FDB_VERSIONS)
269+
string(REPLACE "." "_" version_underscored ${version})
270+
download_and_setup_fdb(${version_underscored})
271+
endforeach()
272+
273+
# Select the default FDB version
274+
string(REPLACE "." "_" FDB_DEFAULT_VERSION_UNDERSCORED ${FDB_DEFAULT_VERSION})
275+
setup_default_fdb(${FDB_DEFAULT_VERSION_UNDERSCORED})
276+
277+
# Note: To add more FDB versions, call download_and_setup_fdb with other versions:
278+
# Example:
279+
# download_and_setup_fdb("7_1_57")
280+
# # Access via: ${FDB_INSTALL_DIR_7_1_57} and ${FDB_LIB_SO_7_1_57}

cloud/src/common/config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ CONF_Int32(brpc_idle_timeout_sec, "-1");
3030
CONF_String(hostname, "");
3131
CONF_String(fdb_cluster, "xxx:[email protected]:4500");
3232
CONF_String(fdb_cluster_file_path, "./conf/fdb.cluster");
33+
CONF_Bool(enable_fdb_external_client_directory, "true");
34+
// The directory path of external foundationdb client library.
35+
// eg: /path/to/dir1:/path/to/dir2:...
36+
CONF_String(fdb_external_client_directory, "");
3337
CONF_String(http_token, "greedisgood9999");
3438
// use volatile mem kv for test. MUST NOT be `true` in production environment.
3539
CONF_Bool(use_mem_kv, "false");

0 commit comments

Comments
 (0)