Skip to content

Commit b0704a4

Browse files
committed
RSCBC-187: Add way to override alternate addresses network selection
1 parent 5dd942c commit b0704a4

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

sdk/couchbase-core/src/agent.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,15 @@ impl Agent {
536536

537537
state.latest_config = first_config.clone();
538538

539-
let network_type = NetworkTypeHeuristic::identify(&state.latest_config);
539+
let network_type = if let Some(network) = opts.network {
540+
if network == "auto" || network.is_empty() {
541+
NetworkTypeHeuristic::identify(&state.latest_config)
542+
} else {
543+
network
544+
}
545+
} else {
546+
NetworkTypeHeuristic::identify(&state.latest_config)
547+
};
540548
state.network_type = network_type;
541549

542550
let agent_component_configs = AgentInner::gen_agent_component_configs(&mut state);

sdk/couchbase-core/src/options/agent.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use crate::authenticator::Authenticator;
2222
use crate::memdx::dispatcher::OrphanResponseHandler;
2323
use crate::tls_config::TlsConfig;
2424
use std::fmt::Debug;
25-
use std::sync::Arc;
2625
use std::time::Duration;
2726

2827
#[derive(Clone)]
@@ -34,6 +33,7 @@ pub struct AgentOptions {
3433
pub auth_mechanisms: Vec<AuthMechanism>,
3534
pub tls_config: Option<TlsConfig>,
3635
pub bucket_name: Option<String>,
36+
pub network: Option<String>,
3737

3838
pub compression_config: CompressionConfig,
3939
pub config_poller_config: ConfigPollerConfig,
@@ -50,6 +50,7 @@ impl Debug for AgentOptions {
5050
.field("auth_mechanisms", &self.auth_mechanisms)
5151
.field("tls_config", &self.tls_config)
5252
.field("bucket_name", &self.bucket_name)
53+
.field("network", &self.network)
5354
.field("compression_config", &self.compression_config)
5455
.field("config_poller_config", &self.config_poller_config)
5556
.field("kv_config", &self.kv_config)
@@ -65,6 +66,7 @@ impl AgentOptions {
6566
tls_config: None,
6667
authenticator,
6768
bucket_name: None,
69+
network: None,
6870
seed_config,
6971
compression_config: CompressionConfig::default(),
7072
config_poller_config: ConfigPollerConfig::default(),
@@ -96,6 +98,11 @@ impl AgentOptions {
9698
self
9799
}
98100

101+
pub fn network(mut self, network: impl Into<Option<String>>) -> Self {
102+
self.network = network.into();
103+
self
104+
}
105+
99106
pub fn compression_config(mut self, compression_config: CompressionConfig) -> Self {
100107
self.compression_config = compression_config;
101108
self

sdk/couchbase-core/src/options/ondemand_agentmanager.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use crate::options::agent::{
2323
AgentOptions, CompressionConfig, ConfigPollerConfig, HttpConfig, KvConfig, SeedConfig,
2424
};
2525
use crate::tls_config::TlsConfig;
26-
use std::sync::Arc;
2726
use std::time::Duration;
2827

2928
#[derive(Clone)]
@@ -34,6 +33,7 @@ pub struct OnDemandAgentManagerOptions {
3433

3534
pub auth_mechanisms: Vec<AuthMechanism>,
3635
pub tls_config: Option<TlsConfig>,
36+
pub network: Option<String>,
3737

3838
pub compression_config: CompressionConfig,
3939
pub config_poller_config: ConfigPollerConfig,
@@ -52,6 +52,7 @@ impl OnDemandAgentManagerOptions {
5252
compression_config: CompressionConfig::default(),
5353
config_poller_config: ConfigPollerConfig::default(),
5454
auth_mechanisms: vec![],
55+
network: None,
5556
kv_config: KvConfig::default(),
5657
http_config: HttpConfig::default(),
5758
tcp_keep_alive_time: None,
@@ -89,6 +90,11 @@ impl OnDemandAgentManagerOptions {
8990
self
9091
}
9192

93+
pub fn network(mut self, network: impl Into<String>) -> Self {
94+
self.network = Some(network.into());
95+
self
96+
}
97+
9298
pub fn kv_config(mut self, kv_config: KvConfig) -> Self {
9399
self.kv_config = kv_config;
94100
self
@@ -119,6 +125,7 @@ impl From<OnDemandAgentManagerOptions> for AgentOptions {
119125
tls_config: opts.tls_config,
120126
authenticator: opts.authenticator,
121127
bucket_name: None,
128+
network: opts.network,
122129
seed_config: opts.seed_config,
123130
compression_config: opts.compression_config,
124131
config_poller_config: opts.config_poller_config,
@@ -135,6 +142,7 @@ impl From<AgentOptions> for OnDemandAgentManagerOptions {
135142
fn from(opts: AgentOptions) -> Self {
136143
OnDemandAgentManagerOptions {
137144
authenticator: opts.authenticator,
145+
network: opts.network,
138146
tls_config: opts.tls_config,
139147
seed_config: opts.seed_config,
140148
compression_config: opts.compression_config,

sdk/couchbase/src/clients/cluster_client.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,13 @@ impl CouchbaseClusterBackend {
401401
opts.http_config.idle_connection_timeout =
402402
Duration::from_millis(idle_http_connection_timeout);
403403
}
404-
"placeholder" => {}
404+
"network" => {
405+
let network = v[0]
406+
.parse()
407+
.map_err(|e| error::Error::other_failure(format!("{e:?}")))?;
408+
409+
opts.network = Some(network);
410+
}
405411
_ => (),
406412
}
407413
}

0 commit comments

Comments
 (0)