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

w41ter 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 2e2c5f64086 [opt](cloud) Support fdb locality aware load balancing 
(#61312)
2e2c5f64086 is described below

commit 2e2c5f6408615acef1fef1d87beaeeb4e8366971
Author: walter <[email protected]>
AuthorDate: Mon Mar 16 15:24:39 2026 +0800

    [opt](cloud) Support fdb locality aware load balancing (#61312)
---
 cloud/src/common/config.h       |  5 ++++
 cloud/src/meta-store/txn_kv.cpp | 57 ++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/cloud/src/common/config.h b/cloud/src/common/config.h
index 52e7e593dc6..c38bd9d23f0 100644
--- a/cloud/src/common/config.h
+++ b/cloud/src/common/config.h
@@ -34,6 +34,11 @@ 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, "./lib/fdb/7.3.69/");
+// Enable FDB locality-aware load balancing. When enabled, fdb_zone_id and 
fdb_dc_id
+// will be set on the database for better location-aware request routing.
+CONF_Bool(enable_fdb_locality_load_balance, "false");
+CONF_String(fdb_zone_id, "");
+CONF_String(fdb_dc_id, "");
 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 70740ac3747..1e79061c72b 100644
--- a/cloud/src/meta-store/txn_kv.cpp
+++ b/cloud/src/meta-store/txn_kv.cpp
@@ -313,6 +313,10 @@ inline constexpr size_t 
write_clear_range_approximate_size(size_t begin_size, si
 
 } // anonymous namespace
 
+std::string_view KNOB_LOAD_BALANCE_ZONE_ID_LOCALITY_ENABLED =
+        "load_balance_zone_id_locality_enabled=1";
+std::string_view KNOB_LOAD_BALANCE_DC_ID_LOCALITY_ENABLED = 
"load_balance_dc_id_locality_enabled=1";
+
 // Ref 
https://apple.github.io/foundationdb/api-error-codes.html#developer-guide-error-codes.
 constexpr fdb_error_t FDB_ERROR_CODE_TIMED_OUT = 1004;
 constexpr fdb_error_t FDB_ERROR_CODE_TXN_TOO_OLD = 1007;
@@ -406,6 +410,33 @@ int Network::init() {
         LOG(INFO) << "set fdb external client directory: " << 
config::fdb_external_client_directory;
     }
 
+    if (config::enable_fdb_locality_load_balance) {
+        if (!config::fdb_zone_id.empty()) {
+            err = fdb_network_set_option(
+                    FDB_NET_OPTION_KNOB,
+                    (const 
uint8_t*)KNOB_LOAD_BALANCE_ZONE_ID_LOCALITY_ENABLED.data(),
+                    KNOB_LOAD_BALANCE_ZONE_ID_LOCALITY_ENABLED.size());
+            if (err) {
+                LOG(WARNING) << "failed to set fdb load balance zone id 
locality enabled, err: "
+                             << fdb_get_error(err);
+                return 1;
+            }
+            LOG(INFO) << "set fdb load balance zone id locality enabled";
+        }
+        if (!config::fdb_dc_id.empty()) {
+            err = fdb_network_set_option(
+                    FDB_NET_OPTION_KNOB,
+                    (const 
uint8_t*)KNOB_LOAD_BALANCE_DC_ID_LOCALITY_ENABLED.data(),
+                    KNOB_LOAD_BALANCE_DC_ID_LOCALITY_ENABLED.size());
+            if (err) {
+                LOG(WARNING) << "failed to set fdb load balance dc id locality 
enabled, err: "
+                             << fdb_get_error(err);
+                return 1;
+            }
+            LOG(INFO) << "set fdb load balance dc id locality enabled";
+        }
+    }
+
     // 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
@@ -457,7 +488,6 @@ void Network::stop() {
 // 
=============================================================================
 
 int Database::init() {
-    // TODO: process opt
     fdb_error_t err = fdb_create_database(cluster_file_path_.c_str(), &db_);
     if (err) {
         LOG(WARNING) << __PRETTY_FUNCTION__ << " fdb_create_database error: " 
<< fdb_get_error(err)
@@ -465,6 +495,31 @@ int Database::init() {
         return 1;
     }
 
+    if (config::enable_fdb_locality_load_balance) {
+        if (!config::fdb_zone_id.empty()) {
+            err = fdb_database_set_option(db_, FDB_DB_OPTION_MACHINE_ID,
+                                          (const 
uint8_t*)config::fdb_zone_id.c_str(),
+                                          config::fdb_zone_id.size());
+            if (err) {
+                LOG(WARNING) << "failed to set FDB_DB_OPTION_MACHINE_ID: " << 
fdb_get_error(err)
+                             << ", zone_id: " << config::fdb_zone_id;
+                return 1;
+            }
+            LOG(INFO) << "set FDB_DB_OPTION_MACHINE_ID (zone_id): " << 
config::fdb_zone_id;
+        }
+        if (!config::fdb_dc_id.empty()) {
+            err = fdb_database_set_option(db_, FDB_DB_OPTION_DATACENTER_ID,
+                                          (const 
uint8_t*)config::fdb_dc_id.c_str(),
+                                          config::fdb_dc_id.size());
+            if (err) {
+                LOG(WARNING) << "failed to set FDB_DB_OPTION_DATACENTER_ID: " 
<< fdb_get_error(err)
+                             << ", dc_id: " << config::fdb_dc_id;
+                return 1;
+            }
+            LOG(INFO) << "set FDB_DB_OPTION_DATACENTER_ID (dc_id): " << 
config::fdb_dc_id;
+        }
+    }
+
     return 0;
 }
 


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

Reply via email to