Skip to content

Commit

Permalink
server: support customized addr/status_addr (tikv#13234) (#170)
Browse files Browse the repository at this point in the history
ref tikv#12849

Support self-defined addr/status_addr

Signed-off-by: CalvinNeo <[email protected]>

Co-authored-by: Ti Chi Robot <[email protected]>

Co-authored-by: Ti Chi Robot <[email protected]>
  • Loading branch information
CalvinNeo and ti-chi-bot authored Sep 13, 2022
1 parent 1ffec9a commit 16b9415
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 27 deletions.
8 changes: 3 additions & 5 deletions components/proxy_server/src/status_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,9 @@ use tikv::{
config::{log_level_serde, ConfigController},
server::{
status_server::{
profile::{
activate_heap_profile, deactivate_heap_profile, jeprof_heap_profile,
list_heap_profiles, read_file, start_one_cpu_profile, start_one_heap_profile,
},
region_meta,
activate_heap_profile, deactivate_heap_profile, jeprof_heap_profile,
list_heap_profiles, read_file, region_meta, start_one_cpu_profile,
start_one_heap_profile,
},
Result,
},
Expand Down
8 changes: 2 additions & 6 deletions components/test_raftstore/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,18 +382,14 @@ impl ServerCluster {
cfg.quota.max_delay_duration,
));

// we don't care since we don't start this service
let dummy_dynamic_configs = crate::server::storage::DynamicConfigs {
pipelined_pessimistic_lock: Arc::new(AtomicBool::new(true)),
in_memory_pessimistic_lock: Arc::new(AtomicBool::new(true)),
};
let dynamic_config = lock_mgr.get_storage_dynamic_configs();
let store = create_raft_storage::<_, _, _, F, _>(
engine,
&cfg.storage,
storage_read_pool.handle(),
lock_mgr,
concurrency_manager.clone(),
dummy_dynamic_configs,
dynamic_config,
Arc::new(FlowController::empty()),
pd_sender,
res_tag_factory.clone(),
Expand Down
34 changes: 23 additions & 11 deletions src/server/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ use crate::{
read_pool::ReadPoolHandle,
server::Config as ServerConfig,
storage::{
config::Config as StorageConfig, kv::FlowStatsReporter,
lock_manager::LockManager as LockManagerTrait, txn::flow_controller::FlowController,
DynamicConfigs as StorageDynamicConfigs, Storage,
config::Config as StorageConfig, kv::FlowStatsReporter, lock_manager,
txn::flow_controller::FlowController, DynamicConfigs as StorageDynamicConfigs, Storage,
},
};

Expand All @@ -48,7 +47,13 @@ const CHECK_CLUSTER_BOOTSTRAPPED_RETRY_SECONDS: u64 = 3;

/// Creates a new storage engine which is backed by the Raft consensus
/// protocol.
pub fn create_raft_storage<S, EK, R: FlowStatsReporter, F: KvFormat, LM: LockManagerTrait>(
pub fn create_raft_storage<
S,
EK,
R: FlowStatsReporter,
F: KvFormat,
LM: lock_manager::LockManager,
>(
engine: RaftKv<EK, S>,
cfg: &StorageConfig,
read_pool: ReadPoolHandle,
Expand Down Expand Up @@ -120,22 +125,27 @@ where
Some(s) => s,
};
store.set_id(INVALID_ID);
if store.get_address() == "" {
if store.get_address().is_empty() {
if cfg.advertise_addr.is_empty() {
store.set_address(cfg.addr.clone());
if store.get_peer_address().is_empty() {
store.set_peer_address(cfg.addr.clone());
}
} else {
store.set_address(cfg.advertise_addr.clone())
store.set_address(cfg.advertise_addr.clone());
if store.get_peer_address().is_empty() {
store.set_peer_address(cfg.advertise_addr.clone());
}
}
}
if store.get_status_address() == "" {
if store.get_status_address().is_empty() {
if cfg.advertise_status_addr.is_empty() {
store.set_status_address(cfg.status_addr.clone());
} else {
store.set_status_address(cfg.advertise_status_addr.clone())
}
}

if store.get_version() == "" {
if store.get_version().is_empty() {
store.set_version(env!("CARGO_PKG_VERSION").to_string());
}

Expand All @@ -146,7 +156,7 @@ where
};

store.set_start_timestamp(chrono::Local::now().timestamp());
if store.get_git_hash() == "" {
if store.get_git_hash().is_empty() {
store.set_git_hash(
option_env!("TIKV_BUILD_GIT_HASH")
.unwrap_or("Unknown git hash")
Expand Down Expand Up @@ -255,11 +265,13 @@ where
self.store.get_id()
}

/// Gets a copy of Store which is registered to Pd.
pub fn store(&self) -> metapb::Store {
self.store.clone()
}

/// Gets the Scheduler of RaftstoreConfigTask, it must be called after start.
/// Gets the Scheduler of RaftstoreConfigTask, it must be called after
/// start.
pub fn refresh_config_scheduler(&mut self) -> Scheduler<RefreshConfigTask> {
self.system.refresh_config_scheduler()
}
Expand Down
12 changes: 7 additions & 5 deletions src/server/status_server/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2018 TiKV Project Authors. Licensed under Apache-2.0.

pub mod profile;
/// Provides profilers for TiKV.
mod profile;
pub mod region_meta;
use std::{
error::Error as StdError,
Expand Down Expand Up @@ -38,6 +39,11 @@ use openssl::{
x509::X509,
};
use pin_project::pin_project;
pub use profile::{
activate_heap_profile, deactivate_heap_profile, jeprof_heap_profile, list_heap_profiles,
read_file, start_one_cpu_profile, start_one_heap_profile,
};
use prometheus::TEXT_FORMAT;
use raftstore::store::{transport::CasualRouter, CasualMessage};
use regex::Regex;
use security::{self, SecurityConfig};
Expand All @@ -50,10 +56,6 @@ use tokio::{
};
use tokio_openssl::SslStream;

use self::profile::{
activate_heap_profile, deactivate_heap_profile, jeprof_heap_profile, list_heap_profiles,
read_file, start_one_cpu_profile, start_one_heap_profile,
};
use crate::{
config::{log_level_serde, ConfigController},
server::Result,
Expand Down

0 comments on commit 16b9415

Please sign in to comment.