Skip to content

Commit e2ebb37

Browse files
authored
CPP-885 Fix filtering load balancing policies (#16)
Also, the load balancing policy chains were being duplicated in `RequestProcessor` initialization code.
1 parent 9958710 commit e2ebb37

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Features
1818

1919
Bug Fixes
2020
--------
21+
* [CPP-885] Fix filtering load balancing policies (and remove duplicated load balancing policy chain)
2122
* [CPP-884] Deprecate pending request timeouts metric and remove unused internal logic
2223
* [CPP-871] Fix SSL cleanup on error conditions in mockssandra
2324
* [CPP-855] Fix C\*/DSE protocol lowering attempts when `cass_cluster_set_use_beta_protocol_version()` is true

src/execution_profile.hpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ class ExecutionProfile : public Allocated {
4444
, serial_consistency_(CASS_CONSISTENCY_UNKNOWN)
4545
, latency_aware_routing_(false)
4646
, token_aware_routing_(true)
47-
, token_aware_routing_shuffle_replicas_(true)
48-
, load_balancing_policy_(NULL)
49-
, retry_policy_(NULL) {}
47+
, token_aware_routing_shuffle_replicas_(true) {}
5048

5149
uint64_t request_timeout_ms() const { return request_timeout_ms_; }
5250

@@ -102,13 +100,27 @@ class ExecutionProfile : public Allocated {
102100

103101
const LoadBalancingPolicy::Ptr& load_balancing_policy() const { return load_balancing_policy_; }
104102

105-
void set_load_balancing_policy(LoadBalancingPolicy* lbp) { load_balancing_policy_.reset(lbp); }
103+
void set_load_balancing_policy(LoadBalancingPolicy* lbp) {
104+
base_load_balancing_policy_.reset(lbp);
105+
}
106+
107+
/**
108+
* Use another profile's load balancing policy. This is used to override profiles that don't have
109+
* policies of their own with the default profile's load balancing policy.
110+
*
111+
* @param lbp The other profile's load balancing policy chain.
112+
*/
113+
void use_load_balancing_policy(const LoadBalancingPolicy::Ptr& lbp) {
114+
assert(!base_load_balancing_policy_ &&
115+
"The profile should have a no base load balancing policy");
116+
load_balancing_policy_ = lbp;
117+
}
106118

107119
void build_load_balancing_policy() {
108120
// The base LBP can be augmented by special wrappers (whitelist,
109121
// token aware, latency aware)
110-
if (load_balancing_policy_) {
111-
LoadBalancingPolicy* chain = load_balancing_policy_->new_instance();
122+
if (base_load_balancing_policy_) {
123+
LoadBalancingPolicy* chain = base_load_balancing_policy_->new_instance();
112124

113125
if (!blacklist_.empty()) {
114126
chain = new BlacklistPolicy(chain, blacklist_);
@@ -159,6 +171,7 @@ class ExecutionProfile : public Allocated {
159171
ContactPointList whitelist_;
160172
DcList whitelist_dc_;
161173
LoadBalancingPolicy::Ptr load_balancing_policy_;
174+
LoadBalancingPolicy::Ptr base_load_balancing_policy_;
162175
RetryPolicy::Ptr retry_policy_;
163176
SpeculativeExecutionPolicy::Ptr speculative_execution_policy_;
164177
};

src/list_policy.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ void ListPolicy::on_host_added(const Host::Ptr& host) {
5757
}
5858
}
5959

60-
void ListPolicy::on_host_removed(const Host::Ptr& host) {
60+
void ListPolicy::on_host_up(const Host::Ptr& host) {
6161
if (is_valid_host(host)) {
62-
child_policy_->on_host_removed(host);
62+
child_policy_->on_host_up(host);
6363
}
6464
}

src/list_policy.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class ListPolicy : public ChainedLoadBalancingPolicy {
3939
const TokenMap* token_map);
4040

4141
virtual void on_host_added(const Host::Ptr& host);
42-
virtual void on_host_removed(const Host::Ptr& host);
42+
virtual void on_host_up(const Host::Ptr& host);
4343

4444
virtual ListPolicy* new_instance() = 0;
4545

src/request_processor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ RequestProcessor::RequestProcessor(RequestProcessorListener* listener, EventLoop
204204
LOG_TRACE("Built load balancing policy for '%s' execution profile", it->first.c_str());
205205
load_balancing_policies_.push_back(load_balancing_policy);
206206
} else {
207-
it->second.set_load_balancing_policy(default_profile_.load_balancing_policy().get());
207+
it->second.use_load_balancing_policy(default_profile_.load_balancing_policy());
208208
}
209209
}
210210

0 commit comments

Comments
 (0)