From 779abb672666d467aa38651946c13dc801503143 Mon Sep 17 00:00:00 2001 From: yongman Date: Tue, 30 Jun 2026 11:37:14 +0800 Subject: [PATCH 1/5] columnar: register metrics for hub Signed-off-by: yongman --- .../hub-runtime/src/run.rs | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/contrib/tiflash-columnar-hub/hub-runtime/src/run.rs b/contrib/tiflash-columnar-hub/hub-runtime/src/run.rs index 8330f4cc2f3..733e4cec0a2 100644 --- a/contrib/tiflash-columnar-hub/hub-runtime/src/run.rs +++ b/contrib/tiflash-columnar-hub/hub-runtime/src/run.rs @@ -21,7 +21,7 @@ use std::{ process, sync::{ atomic::{AtomicBool, AtomicU8, Ordering}, - Arc, + Arc, Once, }, thread, time::{Duration, SystemTime, UNIX_EPOCH}, @@ -240,6 +240,27 @@ const STORE_HEARTBEAT_INTERVAL: Duration = Duration::from_secs(10); const HEARTBEAT_SHUTDOWN_POLL_INTERVAL: Duration = Duration::from_millis(200); const STORE_TOMBSTONE_WAIT_TIMEOUT: Duration = Duration::from_secs(30); const STORE_TOMBSTONE_POLL_INTERVAL: Duration = Duration::from_secs(1); +const METRICS_PREFIX: &str = "tiflash_proxy"; + +fn init_metrics() { + static INIT: Once = Once::new(); + + INIT.call_once(|| { + tikv_util::metrics::monitor_process().unwrap_or_else(|err| { + panic!("failed to start process monitor: {}", err); + }); + tikv_util::metrics::warn_if_kernel_metrics_disabled(); + tikv_util::metrics::monitor_threads(METRICS_PREFIX).unwrap_or_else(|err| { + panic!("failed to start thread monitor: {}", err); + }); + tikv_util::metrics::monitor_system_psi(METRICS_PREFIX).unwrap_or_else(|err| { + panic!("failed to start PSI monitor: {}", err); + }); + tikv_util::metrics::monitor_allocator_stats(METRICS_PREFIX).unwrap_or_else(|err| { + panic!("failed to monitor allocator stats: {}", err); + }); + }); +} fn load_config(path: Option<&OsStr>) -> ConfigFile { path.map_or_else(ConfigFile::default, |path| { @@ -1321,6 +1342,8 @@ pub unsafe fn run_proxy(argc: c_int, argv: *const *const c_char, helper_ptr: *co process::exit(0); } + init_metrics(); + let security_mgr = Arc::new(SecurityManager::new(&config.security).unwrap()); let env = Arc::new(EnvBuilder::new().cq_count(1).name_prefix("pd").build()); let pd_client: Arc = From 6c6686d6e2928387e9bc8997ee2a7f9f2b3e44ed Mon Sep 17 00:00:00 2001 From: yongman Date: Tue, 30 Jun 2026 14:36:45 +0800 Subject: [PATCH 2/5] fix store path stats Signed-off-by: yongman --- .../tiflash-columnar-hub/.cargo/config.toml | 2 ++ .../hub-runtime/src/engine_store_helper.rs | 9 ++++++-- .../hub-runtime/src/run.rs | 21 +++++++++++++++++-- 3 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 contrib/tiflash-columnar-hub/.cargo/config.toml diff --git a/contrib/tiflash-columnar-hub/.cargo/config.toml b/contrib/tiflash-columnar-hub/.cargo/config.toml new file mode 100644 index 00000000000..0527bb15476 --- /dev/null +++ b/contrib/tiflash-columnar-hub/.cargo/config.toml @@ -0,0 +1,2 @@ +[target.'cfg(not(target_os = "macos"))'] +rustflags = ["-C", "link-arg=-Wl,--allow-multiple-definition"] diff --git a/contrib/tiflash-columnar-hub/hub-runtime/src/engine_store_helper.rs b/contrib/tiflash-columnar-hub/hub-runtime/src/engine_store_helper.rs index 28f9fa08651..97e8dfa0837 100644 --- a/contrib/tiflash-columnar-hub/hub-runtime/src/engine_store_helper.rs +++ b/contrib/tiflash-columnar-hub/hub-runtime/src/engine_store_helper.rs @@ -17,8 +17,8 @@ use std::sync::atomic::{AtomicPtr, Ordering}; use crate::{ interfaces_ffi::{ BaseBuffView, EngineStoreServerHelper, EngineStoreServerStatus, HttpRequestRes, MsgPBType, - RaftStoreProxyFFIHelper, RawCppStringPtr, RawVoidPtr, RAFT_STORE_PROXY_MAGIC_NUMBER, - RAFT_STORE_PROXY_VERSION, + RaftStoreProxyFFIHelper, RawCppStringPtr, RawVoidPtr, StoreStats, + RAFT_STORE_PROXY_MAGIC_NUMBER, RAFT_STORE_PROXY_VERSION, }, UnwrapExternCFunc, }; @@ -41,6 +41,7 @@ unsafe impl Sync for EngineStoreServerHelper {} pub trait EngineStoreServerHelperExt { fn check(&self); fn set_proxy(&self, proxy: &mut RaftStoreProxyFFIHelper); + fn handle_compute_store_stats(&self) -> StoreStats; fn handle_get_engine_store_server_status(&self) -> EngineStoreServerStatus; fn handle_http_request( &self, @@ -66,6 +67,10 @@ impl EngineStoreServerHelperExt for EngineStoreServerHelper { } } + fn handle_compute_store_stats(&self) -> StoreStats { + unsafe { self.fn_handle_compute_store_stats.into_inner()(self.inner) } + } + fn handle_get_engine_store_server_status(&self) -> EngineStoreServerStatus { unsafe { self.fn_handle_get_engine_store_server_status.into_inner()(self.inner) } } diff --git a/contrib/tiflash-columnar-hub/hub-runtime/src/run.rs b/contrib/tiflash-columnar-hub/hub-runtime/src/run.rs index 733e4cec0a2..9d3e7a46e58 100644 --- a/contrib/tiflash-columnar-hub/hub-runtime/src/run.rs +++ b/contrib/tiflash-columnar-hub/hub-runtime/src/run.rs @@ -937,6 +937,14 @@ fn collect_store_space_stats(data_dir: &Path) -> Option<(u64, u64)> { } } +fn collect_store_space_stats_from_engine_store() -> Option<(u64, u64)> { + let stats = get_engine_store_server_helper().handle_compute_store_stats(); + if stats.fs_stats.ok == 0 { + return None; + } + Some((stats.fs_stats.capacity_size, stats.fs_stats.avail_size)) +} + fn build_store_heartbeat_stats_from_space( store_id: u64, start_time: u32, @@ -967,7 +975,8 @@ fn build_store_heartbeat_stats( last_report_ts: u64, data_dir: &Path, ) -> Option { - let (capacity, available) = collect_store_space_stats(data_dir)?; + let (capacity, available) = collect_store_space_stats_from_engine_store() + .or_else(|| collect_store_space_stats(data_dir))?; if capacity == 0 { warn!( "skip store heartbeat because disk capacity is unavailable"; @@ -1820,7 +1829,15 @@ log-rotation-size = "1024MiB" )); fs::create_dir_all(&temp_dir).unwrap(); - let stats = build_store_heartbeat_stats(9527, 123, 456, &temp_dir).unwrap(); + let (capacity, available) = collect_store_space_stats(&temp_dir).unwrap(); + let stats = build_store_heartbeat_stats_from_space( + 9527, + 123, + 456, + capacity, + available, + ) + .unwrap(); assert_eq!(stats.get_store_id(), 9527); assert_eq!(stats.get_start_time(), 123); assert!(stats.get_capacity() > 0); From 51e24fe822e102dcc88d1b0cdce1e5fb28cb6fdf Mon Sep 17 00:00:00 2001 From: yongman Date: Tue, 30 Jun 2026 17:13:52 +0800 Subject: [PATCH 3/5] fix metrics prefix Signed-off-by: yongman --- .../tiflash-columnar-hub/.cargo/config.toml | 3 +++ contrib/tiflash-columnar-hub/Cargo.lock | 3 +-- contrib/tiflash-columnar-hub/Cargo.toml | 2 ++ contrib/tiflash-columnar-hub/Makefile | 1 + .../hub-runtime/Cargo.toml | 2 +- .../hub-runtime/src/run.rs | 18 +++++------------- contrib/tiflash-proxy-cmake/CMakeLists.txt | 8 ++++++++ 7 files changed, 21 insertions(+), 16 deletions(-) diff --git a/contrib/tiflash-columnar-hub/.cargo/config.toml b/contrib/tiflash-columnar-hub/.cargo/config.toml index 0527bb15476..ff11e6d064b 100644 --- a/contrib/tiflash-columnar-hub/.cargo/config.toml +++ b/contrib/tiflash-columnar-hub/.cargo/config.toml @@ -1,2 +1,5 @@ [target.'cfg(not(target_os = "macos"))'] rustflags = ["-C", "link-arg=-Wl,--allow-multiple-definition"] + +[env] +PROMETHEUS_METRIC_NAME_PREFIX = "tiflash_proxy_" diff --git a/contrib/tiflash-columnar-hub/Cargo.lock b/contrib/tiflash-columnar-hub/Cargo.lock index a2cae00f566..8c499ab1e06 100644 --- a/contrib/tiflash-columnar-hub/Cargo.lock +++ b/contrib/tiflash-columnar-hub/Cargo.lock @@ -5116,8 +5116,7 @@ dependencies = [ [[package]] name = "prometheus" version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7f64969ffd5dd8f39bd57a68ac53c163a095ed9d0fb707146da1b27025a3504" +source = "git+https://github.com/solotzg/rust-prometheus.git?rev=b4fe98a06a58d29f9b9987a0d7186f6ed5230193#b4fe98a06a58d29f9b9987a0d7186f6ed5230193" dependencies = [ "cfg-if", "fnv", diff --git a/contrib/tiflash-columnar-hub/Cargo.toml b/contrib/tiflash-columnar-hub/Cargo.toml index 9de8d6ce257..85f31932e02 100644 --- a/contrib/tiflash-columnar-hub/Cargo.toml +++ b/contrib/tiflash-columnar-hub/Cargo.toml @@ -11,6 +11,7 @@ keys = { git = "https://github.com/tidbcloud/cloud-storage-engine.git", branch = kvengine = { git = "https://github.com/tidbcloud/cloud-storage-engine.git", branch = "cloud-engine" } kvenginepb = { git = "https://github.com/tidbcloud/cloud-storage-engine.git", branch = "cloud-engine" } pd_client = { git = "https://github.com/tidbcloud/cloud-storage-engine.git", branch = "cloud-engine", default-features = false } +prometheus = { version = "=0.13.0", features = ["nightly", "push"], default-features = true } security = { git = "https://github.com/tidbcloud/cloud-storage-engine.git", branch = "cloud-engine", default-features = false } tikv_util = { git = "https://github.com/tidbcloud/cloud-storage-engine.git", branch = "cloud-engine" } url = { version = "2", default-features = true } @@ -26,6 +27,7 @@ tokio-executor = { git = "https://github.com/tikv/tokio", branch = "tokio-timer- lindera = { git = "https://github.com/breezewish/lindera", branch = "v0.43.1-tokio-1.24" } tantivy = { git = "https://github.com/breezewish/tikv-tantivy.git", branch = "patch-0.22.1" } pprof = { git = "https://github.com/tikv/pprof-rs.git", rev = "01cff82dbe6fe110a707bf2b38d8ebb1d14a18f8" } +prometheus = { git = "https://github.com/solotzg/rust-prometheus.git", rev = "b4fe98a06a58d29f9b9987a0d7186f6ed5230193", features = ["nightly", "push"], default-features = true } kvproto = { git = "https://github.com/pingcap/kvproto.git" } tipb = { git = "https://github.com/pingcap/tipb.git" } diff --git a/contrib/tiflash-columnar-hub/Makefile b/contrib/tiflash-columnar-hub/Makefile index 63dc570ce3c..bd75b0fc9bb 100644 --- a/contrib/tiflash-columnar-hub/Makefile +++ b/contrib/tiflash-columnar-hub/Makefile @@ -11,6 +11,7 @@ export PROXY_BUILD_RUSTC_VERSION := $(shell rustc --version 2> /dev/null || echo export PROXY_BUILD_GIT_HASH ?= $(shell git -C $(PROJECT_DIR) rev-parse HEAD 2> /dev/null || echo ${BUILD_INFO_GIT_FALLBACK}) export PROXY_BUILD_GIT_BRANCH ?= $(shell git -C $(PROJECT_DIR) rev-parse --abbrev-ref HEAD 2> /dev/null || echo ${BUILD_INFO_GIT_FALLBACK}) export PROXY_PROFILE ?= debug +export PROMETHEUS_METRIC_NAME_PREFIX ?= tiflash_proxy_ # `kvengine` pulls in both `usearch` and the standalone `simsimd` crate from # cloud-storage-engine. They currently export the same C symbols, so allow the diff --git a/contrib/tiflash-columnar-hub/hub-runtime/Cargo.toml b/contrib/tiflash-columnar-hub/hub-runtime/Cargo.toml index 6be6881b235..07296cdb65d 100644 --- a/contrib/tiflash-columnar-hub/hub-runtime/Cargo.toml +++ b/contrib/tiflash-columnar-hub/hub-runtime/Cargo.toml @@ -35,7 +35,7 @@ num_cpus = "1" pd_client = { workspace = true } pprof = { version = "0.15", default-features = false, features = ["flamegraph", "cpp", "framehop-unwinder", "protobuf-codec"] } pprof_util = { version = "0.8.2", features = ["flamegraph"] } -prometheus = { version = "=0.13.0", features = ["nightly", "push"], default-features = true } +prometheus = { workspace = true } protobuf = { version = "2.8", features = ["bytes"], default-features = true } quick_cache = "0.6.14" regex = "1" diff --git a/contrib/tiflash-columnar-hub/hub-runtime/src/run.rs b/contrib/tiflash-columnar-hub/hub-runtime/src/run.rs index 9d3e7a46e58..9d43cbfc018 100644 --- a/contrib/tiflash-columnar-hub/hub-runtime/src/run.rs +++ b/contrib/tiflash-columnar-hub/hub-runtime/src/run.rs @@ -240,8 +240,6 @@ const STORE_HEARTBEAT_INTERVAL: Duration = Duration::from_secs(10); const HEARTBEAT_SHUTDOWN_POLL_INTERVAL: Duration = Duration::from_millis(200); const STORE_TOMBSTONE_WAIT_TIMEOUT: Duration = Duration::from_secs(30); const STORE_TOMBSTONE_POLL_INTERVAL: Duration = Duration::from_secs(1); -const METRICS_PREFIX: &str = "tiflash_proxy"; - fn init_metrics() { static INIT: Once = Once::new(); @@ -250,13 +248,13 @@ fn init_metrics() { panic!("failed to start process monitor: {}", err); }); tikv_util::metrics::warn_if_kernel_metrics_disabled(); - tikv_util::metrics::monitor_threads(METRICS_PREFIX).unwrap_or_else(|err| { + tikv_util::metrics::monitor_threads("").unwrap_or_else(|err| { panic!("failed to start thread monitor: {}", err); }); - tikv_util::metrics::monitor_system_psi(METRICS_PREFIX).unwrap_or_else(|err| { + tikv_util::metrics::monitor_system_psi("").unwrap_or_else(|err| { panic!("failed to start PSI monitor: {}", err); }); - tikv_util::metrics::monitor_allocator_stats(METRICS_PREFIX).unwrap_or_else(|err| { + tikv_util::metrics::monitor_allocator_stats("").unwrap_or_else(|err| { panic!("failed to monitor allocator stats: {}", err); }); }); @@ -1830,14 +1828,8 @@ log-rotation-size = "1024MiB" fs::create_dir_all(&temp_dir).unwrap(); let (capacity, available) = collect_store_space_stats(&temp_dir).unwrap(); - let stats = build_store_heartbeat_stats_from_space( - 9527, - 123, - 456, - capacity, - available, - ) - .unwrap(); + let stats = + build_store_heartbeat_stats_from_space(9527, 123, 456, capacity, available).unwrap(); assert_eq!(stats.get_store_id(), 9527); assert_eq!(stats.get_start_time(), 123); assert!(stats.get_capacity() > 0); diff --git a/contrib/tiflash-proxy-cmake/CMakeLists.txt b/contrib/tiflash-proxy-cmake/CMakeLists.txt index cf27b62ba75..e7176bcb547 100644 --- a/contrib/tiflash-proxy-cmake/CMakeLists.txt +++ b/contrib/tiflash-proxy-cmake/CMakeLists.txt @@ -118,6 +118,7 @@ list(FILTER _TIFLASH_PROXY_SRCS EXCLUDE REGEX "/target/") set(_TIFLASH_PROXY_MAKEFILE "${_TIFLASH_PROXY_SOURCE_DIR}/Makefile") set(_TIFLASH_PROXY_CARGO_MANIFEST "${_TIFLASH_PROXY_SOURCE_DIR}/Cargo.toml") set(_TIFLASH_PROXY_CARGO_LOCK "${_TIFLASH_PROXY_SOURCE_DIR}/Cargo.lock") +set(_TIFLASH_PROXY_CARGO_CONFIG "${_TIFLASH_PROXY_SOURCE_DIR}/.cargo/config.toml") set(_TIFLASH_PROXY_RUST_TOOLCHAIN "${TiFlash_SOURCE_DIR}/rust-toolchain.toml") if (EXISTS "${_TIFLASH_PROXY_SOURCE_DIR}/rust-toolchain.toml") set(_TIFLASH_PROXY_RUST_TOOLCHAIN "${_TIFLASH_PROXY_SOURCE_DIR}/rust-toolchain.toml") @@ -128,6 +129,10 @@ endif() # Build in the build directory instead of the default source directory set(TIFLASH_RUST_ENV "CARGO_TARGET_DIR=${CMAKE_CURRENT_BINARY_DIR}" ${TIFLASH_RUST_ENV}) +if (ENABLE_NEXT_GEN_COLUMNAR) + set(TIFLASH_RUST_ENV "PROMETHEUS_METRIC_NAME_PREFIX=tiflash_proxy_" ${TIFLASH_RUST_ENV}) +endif() + # Set CMAKE_POLICY_VERSION_MINIMUM to support CMake 4.0+ with older crate CMakeLists.txt files. set(TIFLASH_RUST_ENV "CMAKE_POLICY_VERSION_MINIMUM=3.5" ${TIFLASH_RUST_ENV}) @@ -169,6 +174,9 @@ set(_TIFLASH_PROXY_CUSTOM_DEPENDS if (EXISTS "${_TIFLASH_PROXY_CARGO_LOCK}") list(APPEND _TIFLASH_PROXY_CUSTOM_DEPENDS "${_TIFLASH_PROXY_CARGO_LOCK}") endif() +if (EXISTS "${_TIFLASH_PROXY_CARGO_CONFIG}") + list(APPEND _TIFLASH_PROXY_CUSTOM_DEPENDS "${_TIFLASH_PROXY_CARGO_CONFIG}") +endif() add_custom_command(OUTPUT ${_TIFLASH_PROXY_LIBRARY} COMMENT "Building TiFlash Proxy using ${_TIFLASH_PROXY_BUILD_PROFILE} profile" From 2dde5e47d6288b2b78075fb6df02947a15f206fb Mon Sep 17 00:00:00 2001 From: yongman Date: Tue, 30 Jun 2026 17:31:42 +0800 Subject: [PATCH 4/5] add prometheus prefix to version info Signed-off-by: yongman --- .../hub-runtime/src/lib.rs | 3 +- contrib/tiflash-proxy-cmake/CMakeLists.txt | 60 +++++++++++-------- 2 files changed, 37 insertions(+), 26 deletions(-) diff --git a/contrib/tiflash-columnar-hub/hub-runtime/src/lib.rs b/contrib/tiflash-columnar-hub/hub-runtime/src/lib.rs index 4c4cb2e811e..7d884f91211 100644 --- a/contrib/tiflash-columnar-hub/hub-runtime/src/lib.rs +++ b/contrib/tiflash-columnar-hub/hub-runtime/src/lib.rs @@ -53,9 +53,10 @@ use std::os::raw::{c_char, c_int}; pub(crate) fn proxy_version_info() -> String { let fallback = "Unknown"; format!( - "Git Commit Hash: {}\nRust Version: {}\nProfile: {}", + "Git Commit Hash: {}\nRust Version: {}\nPrometheus Prefix: {}\nProfile: {}", option_env!("CLOUD_STORAGE_ENGINE_GIT_HASH").unwrap_or(fallback), option_env!("PROXY_BUILD_RUSTC_VERSION").unwrap_or(fallback), + option_env!("PROMETHEUS_METRIC_NAME_PREFIX").unwrap_or(fallback), option_env!("PROXY_PROFILE").unwrap_or(fallback), ) } diff --git a/contrib/tiflash-proxy-cmake/CMakeLists.txt b/contrib/tiflash-proxy-cmake/CMakeLists.txt index e7176bcb547..450afa32071 100644 --- a/contrib/tiflash-proxy-cmake/CMakeLists.txt +++ b/contrib/tiflash-proxy-cmake/CMakeLists.txt @@ -4,7 +4,7 @@ # 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 +# 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, @@ -14,14 +14,15 @@ # Helper: extract openssl version from a Cargo.lock file. # Cargo.lock stores each dependency as: -# [[package]] -# name = "openssl" -# version = "0.10.72" +# [[package]] +# name = "openssl" +# version = "0.10.72" # This function scans name/version lines and returns the version # that immediately follows the openssl name entry. function(_extract_openssl_version CARGO_LOCK_PATH OUT_VAR) file(STRINGS "${CARGO_LOCK_PATH}" _LINES REGEX "^(name|version) = \"") set(_FOUND FALSE) + foreach(_LINE IN LISTS _LINES) if(_LINE MATCHES "^name = \"openssl\"$") set(_FOUND TRUE) @@ -30,19 +31,22 @@ function(_extract_openssl_version CARGO_LOCK_PATH OUT_VAR) return() endif() endforeach() + # openssl not found — leave OUT_VAR empty so caller can decide how to handle set(${OUT_VAR} "" PARENT_SCOPE) endfunction() set(_TIFLASH_PROXY_ENABLE_FEATURES "") -if (ENABLE_JEMALLOC) - if (APPLE) + +if(ENABLE_JEMALLOC) + if(APPLE) message(STATUS "proxy's jemalloc is disabled (AppleOS)") else() message(STATUS "proxy's jemalloc is enabled") - if (ENABLE_NEXT_GEN_COLUMNAR) + + if(ENABLE_NEXT_GEN_COLUMNAR) set(_TIFLASH_PROXY_ENABLE_FEATURES ENABLE_FEATURES="external-jemalloc") - elseif (ENABLE_NEXT_GEN) + elseif(ENABLE_NEXT_GEN) set(_TIFLASH_PROXY_ENABLE_FEATURES ENABLE_FEATURES="raftstore-proxy/external-jemalloc") else() set(_TIFLASH_PROXY_ENABLE_FEATURES ENABLE_FEATURES="external-jemalloc") @@ -51,17 +55,19 @@ if (ENABLE_JEMALLOC) else() message(STATUS "proxy's jemalloc is disabled") endif() -if (CMAKE_BUILD_TYPE_UC STREQUAL "DEBUG" OR SAN_DEBUG) + +if(CMAKE_BUILD_TYPE_UC STREQUAL "DEBUG" OR SAN_DEBUG) set(_TIFLASH_PROXY_BUILD_PROFILE "debug") else() set(_TIFLASH_PROXY_BUILD_PROFILE "release") endif() + set(_TIFLASH_PROXY_MAKE_COMMAND "${_TIFLASH_PROXY_ENABLE_FEATURES}" make "${_TIFLASH_PROXY_BUILD_PROFILE}") # use different tiflash-proxy for classic, next-gen, or columnar -if (ENABLE_NEXT_GEN_COLUMNAR) +if(ENABLE_NEXT_GEN_COLUMNAR) set(_TIFLASH_PROXY_SOURCE_DIR "${TiFlash_SOURCE_DIR}/contrib/tiflash-columnar-hub") -elseif (ENABLE_NEXT_GEN) +elseif(ENABLE_NEXT_GEN) set(_TIFLASH_PROXY_SOURCE_DIR "${TiFlash_SOURCE_DIR}/contrib/tiflash-proxy-next-gen") else() set(_TIFLASH_PROXY_SOURCE_DIR "${TiFlash_SOURCE_DIR}/contrib/tiflash-proxy") @@ -71,11 +77,11 @@ endif() # cloud-storage-engine must use the same openssl crate version. # Mismatched openssl versions may cause features such as CMEK # be broken. -if (ENABLE_NEXT_GEN_COLUMNAR) +if(ENABLE_NEXT_GEN_COLUMNAR) set(_COLUMNAR_HUB_CARGO_LOCK "${TiFlash_SOURCE_DIR}/contrib/tiflash-columnar-hub/Cargo.lock") set(_CLOUD_STORAGE_CARGO_LOCK "${TiFlash_SOURCE_DIR}/contrib/cloud-storage-engine/Cargo.lock") - if (EXISTS "${_COLUMNAR_HUB_CARGO_LOCK}" AND EXISTS "${_CLOUD_STORAGE_CARGO_LOCK}") + if(EXISTS "${_COLUMNAR_HUB_CARGO_LOCK}" AND EXISTS "${_CLOUD_STORAGE_CARGO_LOCK}") _extract_openssl_version("${_COLUMNAR_HUB_CARGO_LOCK}" _HUB_OPENSSL_VERSION) _extract_openssl_version("${_CLOUD_STORAGE_CARGO_LOCK}" _CS_OPENSSL_VERSION) @@ -83,6 +89,7 @@ if (ENABLE_NEXT_GEN_COLUMNAR) message(FATAL_ERROR "Could not find openssl version in ${_COLUMNAR_HUB_CARGO_LOCK}") endif() + if(NOT _CS_OPENSSL_VERSION) message(FATAL_ERROR "Could not find openssl version in ${_CLOUD_STORAGE_CARGO_LOCK}") @@ -104,6 +111,7 @@ if (ENABLE_NEXT_GEN_COLUMNAR) if(NOT EXISTS "${_COLUMNAR_HUB_CARGO_LOCK}") message(WARNING "${_COLUMNAR_HUB_CARGO_LOCK} not found, skipping openssl version check") endif() + if(NOT EXISTS "${_CLOUD_STORAGE_CARGO_LOCK}") message(WARNING "${_CLOUD_STORAGE_CARGO_LOCK} not found, skipping openssl version check") endif() @@ -120,24 +128,21 @@ set(_TIFLASH_PROXY_CARGO_MANIFEST "${_TIFLASH_PROXY_SOURCE_DIR}/Cargo.toml") set(_TIFLASH_PROXY_CARGO_LOCK "${_TIFLASH_PROXY_SOURCE_DIR}/Cargo.lock") set(_TIFLASH_PROXY_CARGO_CONFIG "${_TIFLASH_PROXY_SOURCE_DIR}/.cargo/config.toml") set(_TIFLASH_PROXY_RUST_TOOLCHAIN "${TiFlash_SOURCE_DIR}/rust-toolchain.toml") -if (EXISTS "${_TIFLASH_PROXY_SOURCE_DIR}/rust-toolchain.toml") + +if(EXISTS "${_TIFLASH_PROXY_SOURCE_DIR}/rust-toolchain.toml") set(_TIFLASH_PROXY_RUST_TOOLCHAIN "${_TIFLASH_PROXY_SOURCE_DIR}/rust-toolchain.toml") -elseif (EXISTS "${_TIFLASH_PROXY_SOURCE_DIR}/rust-toolchain") +elseif(EXISTS "${_TIFLASH_PROXY_SOURCE_DIR}/rust-toolchain") set(_TIFLASH_PROXY_RUST_TOOLCHAIN "${_TIFLASH_PROXY_SOURCE_DIR}/rust-toolchain") endif() # Build in the build directory instead of the default source directory set(TIFLASH_RUST_ENV "CARGO_TARGET_DIR=${CMAKE_CURRENT_BINARY_DIR}" ${TIFLASH_RUST_ENV}) -if (ENABLE_NEXT_GEN_COLUMNAR) - set(TIFLASH_RUST_ENV "PROMETHEUS_METRIC_NAME_PREFIX=tiflash_proxy_" ${TIFLASH_RUST_ENV}) -endif() - # Set CMAKE_POLICY_VERSION_MINIMUM to support CMake 4.0+ with older crate CMakeLists.txt files. set(TIFLASH_RUST_ENV "CMAKE_POLICY_VERSION_MINIMUM=3.5" ${TIFLASH_RUST_ENV}) # use `CFLAGS=-w CXXFLAGS=-w` to inhibit warning messages. -if (TIFLASH_LLVM_TOOLCHAIN) +if(TIFLASH_LLVM_TOOLCHAIN) set(TIFLASH_RUST_ENV CMAKE=${CMAKE_COMMAND} "CFLAGS=-w -fuse-ld=lld" "CXXFLAGS=-w -fuse-ld=lld -stdlib=libc++" ${TIFLASH_RUST_ENV}) else() set(TIFLASH_RUST_ENV CMAKE=${CMAKE_COMMAND} CFLAGS=-w CXXFLAGS=-w ${TIFLASH_RUST_ENV}) @@ -149,17 +154,20 @@ if(TIFLASH_LLVM_TOOLCHAIN AND USE_LIBCXX) set(TIFLASH_RUST_LINKER ${CMAKE_CURRENT_BINARY_DIR}/tiflash-linker) set(TIFLASH_RUST_LINKER_TMP ${CMAKE_CURRENT_BINARY_DIR}/tmp/tiflash-linker) file(WRITE ${TIFLASH_RUST_LINKER_TMP} - "#!/usr/bin/env sh\n${CMAKE_CXX_COMPILER} -l:libc++.so -l:libc++abi.so $@") + "#!/usr/bin/env sh\n${CMAKE_CXX_COMPILER} -l:libc++.so -l:libc++abi.so $@") file(COPY ${TIFLASH_RUST_LINKER_TMP} - DESTINATION ${CMAKE_CURRENT_BINARY_DIR} - FILE_PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE) + DESTINATION ${CMAKE_CURRENT_BINARY_DIR} + FILE_PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE) set(TIFLASH_RUSTFLAGS "-C rpath=yes -C linker=${TIFLASH_RUST_LINKER}") + if(ARCH_AARCH64) set(TIFLASH_RUSTFLAGS "-C link-arg=-Wl,-Bsymbolic ${TIFLASH_RUSTFLAGS}") endif() + if(LINKER_NAME) set(TIFLASH_RUSTFLAGS "-C link-arg=-fuse-ld=${LINKER_NAME} ${TIFLASH_RUSTFLAGS}") endif() + set(TIFLASH_RUST_ENV CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER} CXXSTDLIB=c++ RUSTFLAGS=${TIFLASH_RUSTFLAGS} ${TIFLASH_RUST_ENV}) message(STATUS "Enforce LLVM toolchain for rust") endif() @@ -171,10 +179,12 @@ set(_TIFLASH_PROXY_CUSTOM_DEPENDS "${_TIFLASH_PROXY_MAKEFILE}" "${_TIFLASH_PROXY_CARGO_MANIFEST}" "${_TIFLASH_PROXY_RUST_TOOLCHAIN}") -if (EXISTS "${_TIFLASH_PROXY_CARGO_LOCK}") + +if(EXISTS "${_TIFLASH_PROXY_CARGO_LOCK}") list(APPEND _TIFLASH_PROXY_CUSTOM_DEPENDS "${_TIFLASH_PROXY_CARGO_LOCK}") endif() -if (EXISTS "${_TIFLASH_PROXY_CARGO_CONFIG}") + +if(EXISTS "${_TIFLASH_PROXY_CARGO_CONFIG}") list(APPEND _TIFLASH_PROXY_CUSTOM_DEPENDS "${_TIFLASH_PROXY_CARGO_CONFIG}") endif() From 99b1a70d9741b3a193428c926c3bd928c6d96138 Mon Sep 17 00:00:00 2001 From: yongman Date: Tue, 30 Jun 2026 18:14:39 +0800 Subject: [PATCH 5/5] polish Signed-off-by: yongman --- contrib/tiflash-proxy-cmake/CMakeLists.txt | 60 +++++++++------------- 1 file changed, 25 insertions(+), 35 deletions(-) diff --git a/contrib/tiflash-proxy-cmake/CMakeLists.txt b/contrib/tiflash-proxy-cmake/CMakeLists.txt index 450afa32071..e7176bcb547 100644 --- a/contrib/tiflash-proxy-cmake/CMakeLists.txt +++ b/contrib/tiflash-proxy-cmake/CMakeLists.txt @@ -4,7 +4,7 @@ # 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 +# 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, @@ -14,15 +14,14 @@ # Helper: extract openssl version from a Cargo.lock file. # Cargo.lock stores each dependency as: -# [[package]] -# name = "openssl" -# version = "0.10.72" +# [[package]] +# name = "openssl" +# version = "0.10.72" # This function scans name/version lines and returns the version # that immediately follows the openssl name entry. function(_extract_openssl_version CARGO_LOCK_PATH OUT_VAR) file(STRINGS "${CARGO_LOCK_PATH}" _LINES REGEX "^(name|version) = \"") set(_FOUND FALSE) - foreach(_LINE IN LISTS _LINES) if(_LINE MATCHES "^name = \"openssl\"$") set(_FOUND TRUE) @@ -31,22 +30,19 @@ function(_extract_openssl_version CARGO_LOCK_PATH OUT_VAR) return() endif() endforeach() - # openssl not found — leave OUT_VAR empty so caller can decide how to handle set(${OUT_VAR} "" PARENT_SCOPE) endfunction() set(_TIFLASH_PROXY_ENABLE_FEATURES "") - -if(ENABLE_JEMALLOC) - if(APPLE) +if (ENABLE_JEMALLOC) + if (APPLE) message(STATUS "proxy's jemalloc is disabled (AppleOS)") else() message(STATUS "proxy's jemalloc is enabled") - - if(ENABLE_NEXT_GEN_COLUMNAR) + if (ENABLE_NEXT_GEN_COLUMNAR) set(_TIFLASH_PROXY_ENABLE_FEATURES ENABLE_FEATURES="external-jemalloc") - elseif(ENABLE_NEXT_GEN) + elseif (ENABLE_NEXT_GEN) set(_TIFLASH_PROXY_ENABLE_FEATURES ENABLE_FEATURES="raftstore-proxy/external-jemalloc") else() set(_TIFLASH_PROXY_ENABLE_FEATURES ENABLE_FEATURES="external-jemalloc") @@ -55,19 +51,17 @@ if(ENABLE_JEMALLOC) else() message(STATUS "proxy's jemalloc is disabled") endif() - -if(CMAKE_BUILD_TYPE_UC STREQUAL "DEBUG" OR SAN_DEBUG) +if (CMAKE_BUILD_TYPE_UC STREQUAL "DEBUG" OR SAN_DEBUG) set(_TIFLASH_PROXY_BUILD_PROFILE "debug") else() set(_TIFLASH_PROXY_BUILD_PROFILE "release") endif() - set(_TIFLASH_PROXY_MAKE_COMMAND "${_TIFLASH_PROXY_ENABLE_FEATURES}" make "${_TIFLASH_PROXY_BUILD_PROFILE}") # use different tiflash-proxy for classic, next-gen, or columnar -if(ENABLE_NEXT_GEN_COLUMNAR) +if (ENABLE_NEXT_GEN_COLUMNAR) set(_TIFLASH_PROXY_SOURCE_DIR "${TiFlash_SOURCE_DIR}/contrib/tiflash-columnar-hub") -elseif(ENABLE_NEXT_GEN) +elseif (ENABLE_NEXT_GEN) set(_TIFLASH_PROXY_SOURCE_DIR "${TiFlash_SOURCE_DIR}/contrib/tiflash-proxy-next-gen") else() set(_TIFLASH_PROXY_SOURCE_DIR "${TiFlash_SOURCE_DIR}/contrib/tiflash-proxy") @@ -77,11 +71,11 @@ endif() # cloud-storage-engine must use the same openssl crate version. # Mismatched openssl versions may cause features such as CMEK # be broken. -if(ENABLE_NEXT_GEN_COLUMNAR) +if (ENABLE_NEXT_GEN_COLUMNAR) set(_COLUMNAR_HUB_CARGO_LOCK "${TiFlash_SOURCE_DIR}/contrib/tiflash-columnar-hub/Cargo.lock") set(_CLOUD_STORAGE_CARGO_LOCK "${TiFlash_SOURCE_DIR}/contrib/cloud-storage-engine/Cargo.lock") - if(EXISTS "${_COLUMNAR_HUB_CARGO_LOCK}" AND EXISTS "${_CLOUD_STORAGE_CARGO_LOCK}") + if (EXISTS "${_COLUMNAR_HUB_CARGO_LOCK}" AND EXISTS "${_CLOUD_STORAGE_CARGO_LOCK}") _extract_openssl_version("${_COLUMNAR_HUB_CARGO_LOCK}" _HUB_OPENSSL_VERSION) _extract_openssl_version("${_CLOUD_STORAGE_CARGO_LOCK}" _CS_OPENSSL_VERSION) @@ -89,7 +83,6 @@ if(ENABLE_NEXT_GEN_COLUMNAR) message(FATAL_ERROR "Could not find openssl version in ${_COLUMNAR_HUB_CARGO_LOCK}") endif() - if(NOT _CS_OPENSSL_VERSION) message(FATAL_ERROR "Could not find openssl version in ${_CLOUD_STORAGE_CARGO_LOCK}") @@ -111,7 +104,6 @@ if(ENABLE_NEXT_GEN_COLUMNAR) if(NOT EXISTS "${_COLUMNAR_HUB_CARGO_LOCK}") message(WARNING "${_COLUMNAR_HUB_CARGO_LOCK} not found, skipping openssl version check") endif() - if(NOT EXISTS "${_CLOUD_STORAGE_CARGO_LOCK}") message(WARNING "${_CLOUD_STORAGE_CARGO_LOCK} not found, skipping openssl version check") endif() @@ -128,21 +120,24 @@ set(_TIFLASH_PROXY_CARGO_MANIFEST "${_TIFLASH_PROXY_SOURCE_DIR}/Cargo.toml") set(_TIFLASH_PROXY_CARGO_LOCK "${_TIFLASH_PROXY_SOURCE_DIR}/Cargo.lock") set(_TIFLASH_PROXY_CARGO_CONFIG "${_TIFLASH_PROXY_SOURCE_DIR}/.cargo/config.toml") set(_TIFLASH_PROXY_RUST_TOOLCHAIN "${TiFlash_SOURCE_DIR}/rust-toolchain.toml") - -if(EXISTS "${_TIFLASH_PROXY_SOURCE_DIR}/rust-toolchain.toml") +if (EXISTS "${_TIFLASH_PROXY_SOURCE_DIR}/rust-toolchain.toml") set(_TIFLASH_PROXY_RUST_TOOLCHAIN "${_TIFLASH_PROXY_SOURCE_DIR}/rust-toolchain.toml") -elseif(EXISTS "${_TIFLASH_PROXY_SOURCE_DIR}/rust-toolchain") +elseif (EXISTS "${_TIFLASH_PROXY_SOURCE_DIR}/rust-toolchain") set(_TIFLASH_PROXY_RUST_TOOLCHAIN "${_TIFLASH_PROXY_SOURCE_DIR}/rust-toolchain") endif() # Build in the build directory instead of the default source directory set(TIFLASH_RUST_ENV "CARGO_TARGET_DIR=${CMAKE_CURRENT_BINARY_DIR}" ${TIFLASH_RUST_ENV}) +if (ENABLE_NEXT_GEN_COLUMNAR) + set(TIFLASH_RUST_ENV "PROMETHEUS_METRIC_NAME_PREFIX=tiflash_proxy_" ${TIFLASH_RUST_ENV}) +endif() + # Set CMAKE_POLICY_VERSION_MINIMUM to support CMake 4.0+ with older crate CMakeLists.txt files. set(TIFLASH_RUST_ENV "CMAKE_POLICY_VERSION_MINIMUM=3.5" ${TIFLASH_RUST_ENV}) # use `CFLAGS=-w CXXFLAGS=-w` to inhibit warning messages. -if(TIFLASH_LLVM_TOOLCHAIN) +if (TIFLASH_LLVM_TOOLCHAIN) set(TIFLASH_RUST_ENV CMAKE=${CMAKE_COMMAND} "CFLAGS=-w -fuse-ld=lld" "CXXFLAGS=-w -fuse-ld=lld -stdlib=libc++" ${TIFLASH_RUST_ENV}) else() set(TIFLASH_RUST_ENV CMAKE=${CMAKE_COMMAND} CFLAGS=-w CXXFLAGS=-w ${TIFLASH_RUST_ENV}) @@ -154,20 +149,17 @@ if(TIFLASH_LLVM_TOOLCHAIN AND USE_LIBCXX) set(TIFLASH_RUST_LINKER ${CMAKE_CURRENT_BINARY_DIR}/tiflash-linker) set(TIFLASH_RUST_LINKER_TMP ${CMAKE_CURRENT_BINARY_DIR}/tmp/tiflash-linker) file(WRITE ${TIFLASH_RUST_LINKER_TMP} - "#!/usr/bin/env sh\n${CMAKE_CXX_COMPILER} -l:libc++.so -l:libc++abi.so $@") + "#!/usr/bin/env sh\n${CMAKE_CXX_COMPILER} -l:libc++.so -l:libc++abi.so $@") file(COPY ${TIFLASH_RUST_LINKER_TMP} - DESTINATION ${CMAKE_CURRENT_BINARY_DIR} - FILE_PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE) + DESTINATION ${CMAKE_CURRENT_BINARY_DIR} + FILE_PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE) set(TIFLASH_RUSTFLAGS "-C rpath=yes -C linker=${TIFLASH_RUST_LINKER}") - if(ARCH_AARCH64) set(TIFLASH_RUSTFLAGS "-C link-arg=-Wl,-Bsymbolic ${TIFLASH_RUSTFLAGS}") endif() - if(LINKER_NAME) set(TIFLASH_RUSTFLAGS "-C link-arg=-fuse-ld=${LINKER_NAME} ${TIFLASH_RUSTFLAGS}") endif() - set(TIFLASH_RUST_ENV CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER} CXXSTDLIB=c++ RUSTFLAGS=${TIFLASH_RUSTFLAGS} ${TIFLASH_RUST_ENV}) message(STATUS "Enforce LLVM toolchain for rust") endif() @@ -179,12 +171,10 @@ set(_TIFLASH_PROXY_CUSTOM_DEPENDS "${_TIFLASH_PROXY_MAKEFILE}" "${_TIFLASH_PROXY_CARGO_MANIFEST}" "${_TIFLASH_PROXY_RUST_TOOLCHAIN}") - -if(EXISTS "${_TIFLASH_PROXY_CARGO_LOCK}") +if (EXISTS "${_TIFLASH_PROXY_CARGO_LOCK}") list(APPEND _TIFLASH_PROXY_CUSTOM_DEPENDS "${_TIFLASH_PROXY_CARGO_LOCK}") endif() - -if(EXISTS "${_TIFLASH_PROXY_CARGO_CONFIG}") +if (EXISTS "${_TIFLASH_PROXY_CARGO_CONFIG}") list(APPEND _TIFLASH_PROXY_CUSTOM_DEPENDS "${_TIFLASH_PROXY_CARGO_CONFIG}") endif()