This is an automated email from the ASF dual-hosted git repository.

gavinchou pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new cf57972ad1a [feat](cloud) Support fdb multi version clients (#59360)
cf57972ad1a is described below

commit cf57972ad1aa2d49f8f413372653da6664e25214
Author: walter <[email protected]>
AuthorDate: Fri Dec 26 16:57:41 2025 +0800

    [feat](cloud) Support fdb multi version clients (#59360)
---
 cloud/CMakeLists.txt            |  75 +++--------
 cloud/cmake/install_fdb.cmake   | 280 ++++++++++++++++++++++++++++++++++++++++
 cloud/src/common/config.h       |   4 +
 cloud/src/meta-store/txn_kv.cpp |  55 +++++++-
 cloud/src/meta-store/txn_kv.h   |   3 +-
 cloud/test/txn_kv_test.cpp      |   2 +-
 6 files changed, 352 insertions(+), 67 deletions(-)

diff --git a/cloud/CMakeLists.txt b/cloud/CMakeLists.txt
index 40e24ec1b45..1c3591610c8 100644
--- a/cloud/CMakeLists.txt
+++ b/cloud/CMakeLists.txt
@@ -394,67 +394,12 @@ if (ENABLE_INJECTION_POINT)
     add_definitions(-DENABLE_INJECTION_POINT)
 endif()
 
-# Add libs if needed, download to current dir -- ${BUILD_DIR}
-set(FDB_LIB "fdb_lib_7_1_23.tar.xz")
-if (ARCH_AARCH64)
-    set(FDB_LIB "fdb_lib_7_1_57.aarch64.tar.xz")
-endif ()
-file(GLOB RELEASE_FILE_LIST LIST_DIRECTORIES false "/etc/*release*")
-execute_process(COMMAND "cat" ${RELEASE_FILE_LIST}
-                RESULT_VARIABLE CAT_RET_CODE
-                OUTPUT_VARIABLE CAT_RET_CONTENT)
-string(TOUPPER "${CAT_RET_CONTENT}" CAT_RET_CONTENT)
-
-if (ARCH_AARCH64)
-        message("Centos OS")
-        SET(OS_RELEASE "Centos")
-        set(FDB_LIB_URL 
"https://doris-build.oss-cn-beijing.aliyuncs.com/thirdparty/fdb/aarch64/";)
-        string(APPEND FDB_LIB_URL "${FDB_LIB}")
-        set(FDB_LIB_MD5SUM "2d01a431b7a7465077e4ae5520f89693")
-else ()
-    if ("${CAT_RET_CONTENT}" MATCHES "UBUNTU")
-        message("Ubuntu OS")
-        SET(OS_RELEASE "Ubuntu")
-        set(FDB_LIB_URL 
"https://doris-build.oss-cn-beijing.aliyuncs.com/thirdparty/fdb/ubuntu/";)
-        string(APPEND FDB_LIB_URL "${FDB_LIB}")
-        set(FDB_LIB_MD5SUM "a00fe45da95cfac4e0caffa274bb2b30")
-    else()
-        # If it is not ubuntu, it is regarded as centos by default
-        message("Centos OS")
-        SET(OS_RELEASE "Centos")
-        set(FDB_LIB_URL 
"https://doris-build.oss-cn-beijing.aliyuncs.com/thirdparty/fdb/centos/";)
-        string(APPEND FDB_LIB_URL "${FDB_LIB}")
-        set(FDB_LIB_MD5SUM "f9839a564849c0232a351143b4340de0")
-    endif()
-endif()
-
-if (NOT EXISTS "${THIRDPARTY_SRC}/${FDB_LIB}")
-    file(MAKE_DIRECTORY ${THIRDPARTY_SRC})
-    execute_process(COMMAND curl --retry 10 --retry-delay 2 --retry-max-time 
30 ${FDB_LIB_URL}
-                            -o ${THIRDPARTY_SRC}/${FDB_LIB} -k
-                    RESULTS_VARIABLE DOWNLOAD_RET)
-    if (NOT ${DOWNLOAD_RET} STREQUAL "0")
-        execute_process(COMMAND "rm" "-rf" "${THIRDPARTY_SRC}/${FDB_LIB}")
-        message(FATAL_ERROR "Failed to download dependency of fdb 
${FDB_LIB_URL}, remove it")
-    endif ()
-endif ()
-
-# Add fdb dependencies
-add_definitions(-DFDB_API_VERSION=710)
-if (NOT EXISTS ${THIRDPARTY_DIR}/include/foundationdb)
-    execute_process(COMMAND "md5sum" "${THIRDPARTY_SRC}/${FDB_LIB}"
-                    RESULT_VARIABLE MD5SUM_RET_CODE
-                    OUTPUT_VARIABLE MD5SUM_CONTENT)
-    if (NOT "${MD5SUM_CONTENT}" MATCHES "${FDB_LIB_MD5SUM}")
-        execute_process(COMMAND "rm" "-rf" "${THIRDPARTY_SRC}/${FDB_LIB}")
-        message(FATAL_ERROR "${THIRDPARTY_SRC}/${FDB_LIB} md5sum check failed, 
remove it")
-    endif ()
-    execute_process(COMMAND tar xf ${THIRDPARTY_SRC}/${FDB_LIB} -C 
${THIRDPARTY_DIR}/)
-endif ()
-
 # enable glog custom prefix
 add_definitions(-DGLOG_CUSTOM_PREFIX_SUPPORT)
 
+set(FDB_VERSIONS "7.1.57" "7.3.69")
+set(FDB_DEFAULT_VERSION "7.1.57")
+include(install_fdb)
 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lfdb_c 
-L${THIRDPARTY_DIR}/lib")
 
 set(DORIS_CLOUD_LIBS
@@ -556,3 +501,17 @@ install(FILES
     GROUP_READ GROUP_WRITE GROUP_EXECUTE
     WORLD_READ WORLD_EXECUTE
     DESTINATION ${OUTPUT_DIR}/lib)
+
+foreach(version ${FDB_VERSIONS})
+    if (version STREQUAL ${FDB_DEFAULT_VERSION})
+        continue()
+    endif()
+
+    string(REPLACE "." "_" version_underscored ${version})
+    install(FILES
+        ${FDB_INSTALL_DIR_${version_underscored}}/lib64/libfdb_c.so
+        PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
+        GROUP_READ GROUP_WRITE GROUP_EXECUTE
+        WORLD_READ WORLD_EXECUTE
+        DESTINATION ${OUTPUT_DIR}/lib/fdb/${version}/libfdb_c.so)
+endforeach()
diff --git a/cloud/cmake/install_fdb.cmake b/cloud/cmake/install_fdb.cmake
new file mode 100644
index 00000000000..67fceb16e69
--- /dev/null
+++ b/cloud/cmake/install_fdb.cmake
@@ -0,0 +1,280 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# ============================================================================
+# FDB Library Configuration
+# ============================================================================
+# Configuration format:
+#   FDB_CONFIG_${version}_${arch}_${os}_FILE - Tarball filename
+#   FDB_CONFIG_${version}_${arch}_${os}_MD5  - MD5 checksum
+#   FDB_CONFIG_${version}_${arch}_${os}_URL  - Base download URL
+#   FDB_CONFIG_${version}_API_VERSION        - FDB API version (e.g., 710)
+#
+# Supported combinations:
+#   - version: 7_1_23, 7_1_57
+#   - arch: AMD64, AARCH64
+#   - os: UBUNTU, CENTOS (all uppercase)
+# ============================================================================
+
+# Version 7.1.23 Configuration
+set(FDB_CONFIG_7_1_23_API_VERSION "710")
+
+# Version 7.1.23 - AMD64 - UBUNTU
+set(FDB_CONFIG_7_1_23_AMD64_UBUNTU_FILE "fdb_lib_7_1_23.tar.xz")
+set(FDB_CONFIG_7_1_23_AMD64_UBUNTU_MD5 "a00fe45da95cfac4e0caffa274bb2b30")
+set(FDB_CONFIG_7_1_23_AMD64_UBUNTU_URL 
"https://doris-build.oss-cn-beijing.aliyuncs.com/thirdparty/fdb/ubuntu/";)
+
+# Version 7.1.23 - AMD64 - CENTOS
+set(FDB_CONFIG_7_1_23_AMD64_CENTOS_FILE "fdb_lib_7_1_23.tar.xz")
+set(FDB_CONFIG_7_1_23_AMD64_CENTOS_MD5 "f9839a564849c0232a351143b4340de0")
+set(FDB_CONFIG_7_1_23_AMD64_CENTOS_URL 
"https://doris-build.oss-cn-beijing.aliyuncs.com/thirdparty/fdb/centos/";)
+
+# Version 7.1.57 Configuration
+set(FDB_CONFIG_7_1_57_API_VERSION "710")
+
+# Version 7.1.57 - AARCH64 - CENTOS
+set(FDB_CONFIG_7_1_57_AARCH64_CENTOS_FILE "fdb_lib_7_1_57.aarch64.tar.xz")
+set(FDB_CONFIG_7_1_57_AARCH64_CENTOS_MD5 "2d01a431b7a7465077e4ae5520f89693")
+set(FDB_CONFIG_7_1_57_AARCH64_CENTOS_URL 
"https://doris-build.oss-cn-beijing.aliyuncs.com/thirdparty/fdb/aarch64/";)
+
+# Version 7.1.57 - AMD64 - UBUNTU
+set(FDB_CONFIG_7_1_57_AMD64_UBUNTU_FILE "fdb_lib_7_1_57.tar.xz")
+set(FDB_CONFIG_7_1_57_AMD64_UBUNTU_MD5 "5a4aec35de0e041b952a3e39078f327a")
+set(FDB_CONFIG_7_1_57_AMD64_UBUNTU_URL 
"https://doris-build.oss-cn-beijing.aliyuncs.com/thirdparty/fdb/amd64/";)
+
+# Version 7.1.57 - AMD64 - CENTOS
+set(FDB_CONFIG_7_1_57_AMD64_CENTOS_FILE "fdb_lib_7_1_57.tar.xz")
+set(FDB_CONFIG_7_1_57_AMD64_CENTOS_MD5 "5a4aec35de0e041b952a3e39078f327a")
+set(FDB_CONFIG_7_1_57_AMD64_CENTOS_URL 
"https://doris-build.oss-cn-beijing.aliyuncs.com/thirdparty/fdb/amd64/";)
+
+# Version 7.3.69 Configuration
+set(FDB_CONFIG_7_3_69_API_VERSION "730")
+
+# Version 7.3.69 - AARCH64 - CENTOS
+set(FDB_CONFIG_7_3_69_AARCH64_CENTOS_FILE "fdb_lib_7_3_69.tar.xz")
+set(FDB_CONFIG_7_3_69_AARCH64_CENTOS_MD5 "7c6c676b41c70ef31eca617de7879364")
+set(FDB_CONFIG_7_3_69_AARCH64_CENTOS_URL 
"https://doris-build.oss-cn-beijing.aliyuncs.com/thirdparty/fdb/aarch64/";)
+
+# Version 7.3.69 - AMD64 - UBUNTU
+set(FDB_CONFIG_7_3_69_AMD64_UBUNTU_FILE "fdb_lib_7_3_69.tar.xz")
+set(FDB_CONFIG_7_3_69_AMD64_UBUNTU_MD5 "5454db8a8aaa4bcc580c1a40d1171f61")
+set(FDB_CONFIG_7_3_69_AMD64_UBUNTU_URL 
"https://doris-build.oss-cn-beijing.aliyuncs.com/thirdparty/fdb/amd64/";)
+
+# Version 7.3.69 - AMD64 - CENTOS
+set(FDB_CONFIG_7_3_69_AMD64_CENTOS_FILE "fdb_lib_7_3_69.tar.xz")
+set(FDB_CONFIG_7_3_69_AMD64_CENTOS_MD5 "5454db8a8aaa4bcc580c1a40d1171f61")
+set(FDB_CONFIG_7_3_69_AMD64_CENTOS_URL 
"https://doris-build.oss-cn-beijing.aliyuncs.com/thirdparty/fdb/amd64/";)
+
+# ============================================================================
+# Detect OS (run once)
+# ============================================================================
+
+if (NOT DEFINED FDB_OS_DETECTED)
+    file(GLOB RELEASE_FILE_LIST LIST_DIRECTORIES false "/etc/*release*")
+    execute_process(COMMAND "cat" ${RELEASE_FILE_LIST}
+                    RESULT_VARIABLE CAT_RET_CODE
+                    OUTPUT_VARIABLE CAT_RET_CONTENT)
+    string(TOUPPER "${CAT_RET_CONTENT}" CAT_RET_CONTENT)
+
+    if ("${CAT_RET_CONTENT}" MATCHES "UBUNTU")
+        set(FDB_OS_RELEASE "UBUNTU" CACHE INTERNAL "Detected OS for FDB")
+    else()
+        # If it is not ubuntu, it is regarded as centos by default
+        set(FDB_OS_RELEASE "CENTOS" CACHE INTERNAL "Detected OS for FDB")
+    endif()
+
+    set(FDB_OS_DETECTED TRUE CACHE INTERNAL "OS detection flag")
+    message(STATUS "Detected OS: ${FDB_OS_RELEASE}")
+endif()
+
+# ============================================================================
+# Function: Download and Setup FDB Library
+# ============================================================================
+# Downloads, verifies, and extracts a specific version of FDB library
+#
+# Parameters:
+#   version - FDB version in format like "7_1_23" or "7_1_57"
+#
+# Exports:
+#   FDB_INSTALL_DIR_${version} - Installation directory for this version
+#   FDB_LIB_SO_${version}      - Path to libfdb_c.so for this version
+# ============================================================================
+
+function(download_and_setup_fdb version)
+    # Determine architecture
+    if (ARCH_AARCH64)
+        set(fdb_arch "AARCH64")
+    else()
+        set(fdb_arch "AMD64")
+    endif()
+
+    # Construct configuration variable names
+    set(config_prefix "FDB_CONFIG_${version}_${fdb_arch}_${FDB_OS_RELEASE}")
+    set(fdb_file_var "${config_prefix}_FILE")
+    set(fdb_md5_var "${config_prefix}_MD5")
+    set(fdb_url_var "${config_prefix}_URL")
+    set(fdb_api_version_var "FDB_CONFIG_${version}_API_VERSION")
+
+    # Check if all required configurations exist
+    set(missing_configs "")
+    if (NOT DEFINED ${fdb_file_var})
+        list(APPEND missing_configs ${fdb_file_var})
+    endif()
+    if (NOT DEFINED ${fdb_md5_var})
+        list(APPEND missing_configs ${fdb_md5_var})
+    endif()
+    if (NOT DEFINED ${fdb_url_var})
+        list(APPEND missing_configs ${fdb_url_var})
+    endif()
+    if (NOT DEFINED ${fdb_api_version_var})
+        list(APPEND missing_configs ${fdb_api_version_var})
+    endif()
+
+    if (missing_configs)
+        message(FATAL_ERROR "FDB version ${version} is missing required 
configurations for "
+            "architecture ${fdb_arch} and OS ${FDB_OS_RELEASE}:\n"
+            "  Missing variables: ${missing_configs}\n"
+            "  Please add the following configurations:\n"
+            "    ${fdb_file_var}\n"
+            "    ${fdb_md5_var}\n"
+            "    ${fdb_url_var}\n"
+            "    ${fdb_api_version_var}")
+    endif()
+
+    # Get configuration values
+    set(fdb_lib ${${fdb_file_var}})
+    set(fdb_md5 ${${fdb_md5_var}})
+    set(fdb_url ${${fdb_url_var}})
+
+    string(APPEND fdb_url "${fdb_lib}")
+
+    # Set version-specific installation directory
+    string(REPLACE "_" "." version_dotted ${version})
+    set(install_dir "${THIRDPARTY_DIR}/lib/fdb/${version_dotted}")
+    set(lib_so "${install_dir}/lib64/libfdb_c.so")
+
+    # Download FDB library if not exists
+    if (NOT EXISTS "${THIRDPARTY_SRC}/${fdb_lib}")
+        message(STATUS "Downloading FDB library from ${fdb_url}")
+        file(MAKE_DIRECTORY ${THIRDPARTY_SRC})
+        execute_process(COMMAND curl --retry 10 --retry-delay 2 
--retry-max-time 30 ${fdb_url}
+                                -o ${THIRDPARTY_SRC}/${fdb_lib} -k
+                        RESULTS_VARIABLE download_ret)
+        if (NOT ${download_ret} STREQUAL "0")
+            execute_process(COMMAND "rm" "-rf" "${THIRDPARTY_SRC}/${fdb_lib}")
+            message(FATAL_ERROR "Failed to download dependency of fdb 
${fdb_url}, remove it")
+        endif ()
+    endif ()
+
+    if (NOT EXISTS ${install_dir}/include/foundationdb)
+        execute_process(COMMAND "md5sum" "${THIRDPARTY_SRC}/${fdb_lib}"
+                        RESULT_VARIABLE md5sum_ret_code
+                        OUTPUT_VARIABLE md5sum_content)
+        if (NOT "${md5sum_content}" MATCHES "${fdb_md5}")
+            execute_process(COMMAND "rm" "-rf" "${THIRDPARTY_SRC}/${fdb_lib}")
+            message(FATAL_ERROR "${THIRDPARTY_SRC}/${fdb_lib} md5sum check 
failed, remove it")
+        endif ()
+
+        make_directory(${install_dir})
+        execute_process(COMMAND tar xf ${THIRDPARTY_SRC}/${fdb_lib} -C 
${install_dir})
+    endif ()
+
+    # Export version-specific API version to parent scope
+    set(api_version_var "FDB_CONFIG_${version}_API_VERSION")
+    if (DEFINED ${api_version_var})
+        set(FDB_API_VERSION_${version} "${${api_version_var}}" PARENT_SCOPE)
+    endif()
+
+    # Export to parent scope
+    set(FDB_INSTALL_DIR_${version} "${install_dir}" PARENT_SCOPE)
+    set(FDB_LIB_SO_${version} "${lib_so}" PARENT_SCOPE)
+
+    message(STATUS "FDB ${version_dotted} installation directory: 
${install_dir}")
+endfunction()
+
+# ============================================================================
+# Function: Setup Default FDB Library
+# ============================================================================
+# Sets up the default FDB library for static linking
+#
+# Parameters:
+#   version - FDB version to use as default (e.g., "7_1_23")
+#
+# Exports:
+#   FDB_INSTALL_DIR - Installation directory for default version
+#   FDB_LIB_SO      - Path to libfdb_c.so for default version
+# ============================================================================
+
+function(setup_default_fdb version)
+    string(REPLACE "_" "." version_dotted ${version})
+
+    # Ensure the version has been downloaded and set up
+    if (NOT DEFINED FDB_INSTALL_DIR_${version})
+        message(FATAL_ERROR "FDB version ${version_dotted} has not been 
downloaded. Call download_and_setup_fdb first.")
+    endif()
+
+    set(FDB_INSTALL_DIR "${FDB_INSTALL_DIR_${version}}")
+    set(FDB_LIB_SO "${FDB_LIB_SO_${version}}")
+
+    # Set default FDB paths to parent scope
+    set(FDB_INSTALL_DIR "${FDB_INSTALL_DIR_${version}}" PARENT_SCOPE)
+    set(FDB_LIB_SO "${FDB_LIB_SO_${version}}" PARENT_SCOPE)
+
+    # Install the default FDB library
+    execute_process(COMMAND "rm" "-rf" 
"${THIRDPARTY_DIR}/include/foundationdb")
+    execute_process(COMMAND "rm" "-rf" "${THIRDPARTY_DIR}/lib64/libfdb_c.so")
+    execute_process(COMMAND "cp" "-r" 
"${FDB_INSTALL_DIR}/include/foundationdb" 
"${THIRDPARTY_DIR}/include/foundationdb")
+    execute_process(COMMAND "cp" "${FDB_INSTALL_DIR}/lib64/libfdb_c.so" 
"${THIRDPARTY_DIR}/lib64/libfdb_c.so")
+
+    # Set FDB API version for the default version
+    set(api_version_var "FDB_CONFIG_${version}_API_VERSION")
+    if (DEFINED ${api_version_var})
+        set(fdb_api_version "${${api_version_var}}")
+        add_definitions(-DFDB_API_VERSION=${fdb_api_version})
+        message(STATUS "Default FDB API version: ${fdb_api_version}")
+    else()
+        message(WARNING "FDB API version not defined for version 
${version_dotted}")
+    endif()
+endfunction()
+
+function(install_fdb_library target_dir)
+    install(FILES
+        ${THIRDPARTY_DIR}/lib/libfdb_c.so
+        PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
+        GROUP_READ GROUP_WRITE GROUP_EXECUTE
+        WORLD_READ WORLD_EXECUTE
+        DESTINATION ${OUTPUT_DIR}/lib)
+endfunction()
+
+# ============================================================================
+# Main Execution
+# ============================================================================
+
+# Download and setup all specified FDB versions
+foreach (version IN LISTS FDB_VERSIONS)
+    string(REPLACE "." "_" version_underscored ${version})
+    download_and_setup_fdb(${version_underscored})
+endforeach()
+
+# Select the default FDB version
+string(REPLACE "." "_" FDB_DEFAULT_VERSION_UNDERSCORED ${FDB_DEFAULT_VERSION})
+setup_default_fdb(${FDB_DEFAULT_VERSION_UNDERSCORED})
+
+# Note: To add more FDB versions, call download_and_setup_fdb with other 
versions:
+# Example:
+#   download_and_setup_fdb("7_1_57")
+#   # Access via: ${FDB_INSTALL_DIR_7_1_57} and ${FDB_LIB_SO_7_1_57}
diff --git a/cloud/src/common/config.h b/cloud/src/common/config.h
index 0a420d1d007..5f2e9c5a32c 100644
--- a/cloud/src/common/config.h
+++ b/cloud/src/common/config.h
@@ -30,6 +30,10 @@ CONF_Int32(brpc_idle_timeout_sec, "-1");
 CONF_String(hostname, "");
 CONF_String(fdb_cluster, "xxx:[email protected]:4500");
 CONF_String(fdb_cluster_file_path, "./conf/fdb.cluster");
+CONF_Bool(enable_fdb_external_client_directory, "true");
+// The directory path of external foundationdb client library.
+// eg: /path/to/dir1:/path/to/dir2:...
+CONF_String(fdb_external_client_directory, "");
 CONF_String(http_token, "greedisgood9999");
 // use volatile mem kv for test. MUST NOT be `true` in production environment.
 CONF_Bool(use_mem_kv, "false");
diff --git a/cloud/src/meta-store/txn_kv.cpp b/cloud/src/meta-store/txn_kv.cpp
index d7c27503a10..497f5c57a70 100644
--- a/cloud/src/meta-store/txn_kv.cpp
+++ b/cloud/src/meta-store/txn_kv.cpp
@@ -125,7 +125,7 @@ static std::tuple<fdb_bool_t, int> 
apply_key_selector(RangeKeySelector selector)
 }
 
 int FdbTxnKv::init() {
-    network_ = std::make_shared<fdb::Network>(FDBNetworkOption {});
+    network_ = std::make_shared<fdb::Network>();
     int ret = network_->init();
     if (ret != 0) {
         LOG(WARNING) << "failed to init network";
@@ -138,7 +138,30 @@ int FdbTxnKv::init() {
         LOG(WARNING) << "failed to init database";
         return ret;
     }
-    return 0;
+
+    // Access the database to ensure the cluster file is valid, and eat the 
first cluster_version_changed error if any.
+    while (true) {
+        std::unique_ptr<Transaction> txn;
+        TxnErrorCode err = create_txn(&txn);
+        if (err != TxnErrorCode::TXN_OK) {
+            LOG(WARNING) << "init fdb txn kv failed, create txn: " << err;
+            return -1;
+        }
+
+        std::string status_json_key = "\xff\xff/status/json";
+        std::string value;
+        err = txn->get(status_json_key, &value, true);
+        if (err == TxnErrorCode::TXN_RETRYABLE_NOT_COMMITTED) {
+            continue;
+        }
+        if (err != TxnErrorCode::TXN_OK) {
+            LOG(WARNING) << "init fdb txn kv failed, get status json key: " << 
err;
+            return -1;
+        }
+
+        LOG(INFO) << "fdb txn kv is initialized";
+        return 0;
+    }
 }
 
 TxnErrorCode FdbTxnKv::create_txn(std::unique_ptr<Transaction>* txn) {
@@ -250,6 +273,7 @@ constexpr fdb_error_t FDB_ERROR_CODE_TXN_CONFLICT = 1020;
 constexpr fdb_error_t FDB_ERROR_COMMIT_UNKNOWN_RESULT = 1021;
 constexpr fdb_error_t FDB_ERROR_CODE_TXN_TIMED_OUT = 1031;
 constexpr fdb_error_t FDB_ERROR_CODE_TOO_MANY_WATCHES = 1032;
+constexpr fdb_error_t FDB_ERROR_CODE_CLUSTER_VERSION_CHANGED = 1039;
 constexpr fdb_error_t FDB_ERROR_CODE_INVALID_OPTION_VALUE = 2006;
 constexpr fdb_error_t FDB_ERROR_CODE_INVALID_OPTION = 2007;
 constexpr fdb_error_t FDB_ERROR_CODE_VERSION_INVALID = 2011;
@@ -288,6 +312,8 @@ static TxnErrorCode cast_as_txn_code(fdb_error_t err) {
         return TxnErrorCode::TXN_CONFLICT;
     case FDB_ERROR_CODE_TOO_MANY_WATCHES:
         return TxnErrorCode::TXN_TOO_MANY_WATCHES;
+    case FDB_ERROR_CODE_CLUSTER_VERSION_CHANGED:
+        return TxnErrorCode::TXN_RETRYABLE_NOT_COMMITTED;
     }
 
     if (fdb_error_predicate(FDB_ERROR_PREDICATE_MAYBE_COMMITTED, err)) {
@@ -316,11 +342,23 @@ int Network::init() {
         return 1;
     }
 
+    LOG(INFO) << "select fdb api version: " << fdb_get_max_api_version();
+
     // Setup network thread
-    // Optional setting
-    // FDBNetworkOption opt;
-    // fdb_network_set_option()
-    (void)opt_;
+    if (config::enable_fdb_external_client_directory &&
+        !config::fdb_external_client_directory.empty()) {
+        err = fdb_network_set_option(FDB_NET_OPTION_EXTERNAL_CLIENT_DIRECTORY,
+                                     (const 
uint8_t*)config::fdb_external_client_directory.c_str(),
+                                     
config::fdb_external_client_directory.size());
+        if (err) {
+            LOG(WARNING) << "failed to set fdb external client directory, dir: 
"
+                         << config::fdb_external_client_directory
+                         << ", err: " << fdb_get_error(err);
+            return 1;
+        }
+        LOG(INFO) << "set fdb external client directory: " << 
config::fdb_external_client_directory;
+    }
+
     // ATTN: Network can be configured only once,
     //       even if fdb_stop_network() is called successfully
     err = fdb_setup_network(); // Must be called only once before any
@@ -748,6 +786,11 @@ TxnErrorCode Transaction::commit() {
         } else {
             g_bvar_txn_kv_commit_error_counter << 1;
         }
+        // If cluster_version_changed is thrown during commit, it should be 
interpreted similarly to
+        // commit_unknown_result. The commit may or may not have been 
completed.
+        if (err == FDB_ERROR_CODE_CLUSTER_VERSION_CHANGED) {
+            return TxnErrorCode::TXN_MAYBE_COMMITTED;
+        }
         return cast_as_txn_code(err);
     }
 
diff --git a/cloud/src/meta-store/txn_kv.h b/cloud/src/meta-store/txn_kv.h
index d93ad46823c..200ea1e7768 100644
--- a/cloud/src/meta-store/txn_kv.h
+++ b/cloud/src/meta-store/txn_kv.h
@@ -551,7 +551,7 @@ namespace fdb {
 
 class Network {
 public:
-    Network(FDBNetworkOption opt) : opt_(opt) {}
+    Network() {}
 
     /**
      * @return 0 for success otherwise non-zero
@@ -570,7 +570,6 @@ public:
 
 private:
     std::shared_ptr<std::thread> network_thread_;
-    FDBNetworkOption opt_;
 
     // Global state, only one instance of Network is allowed
     static std::atomic<bool> working;
diff --git a/cloud/test/txn_kv_test.cpp b/cloud/test/txn_kv_test.cpp
index 7be9845bc46..d82fe3806fa 100644
--- a/cloud/test/txn_kv_test.cpp
+++ b/cloud/test/txn_kv_test.cpp
@@ -63,7 +63,7 @@ int main(int argc, char** argv) {
 }
 
 TEST(TxnKvTest, Network) {
-    fdb::Network network(FDBNetworkOption {});
+    fdb::Network network;
     network.init();
     network.stop();
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to