Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/load_balancing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@
namespace cass {

ControlConnection* LoadBalancingPolicy::control_connection() {
return session_ == NULL ? NULL : session_->control_connection();
auto* session = session_.load(std::memory_order_acquire);
return session ? session->control_connection() : nullptr;
}

const Metadata* LoadBalancingPolicy::metadata() const {
const Session* s = session_; // const cast
return s == NULL ? NULL : &s->metadata();
const auto* session = session_.load(std::memory_order_acquire);
return session ? &session->metadata() : nullptr;
}

const TokenMap* LoadBalancingPolicy::token_map() const {
return session_ == NULL ? NULL : session_->token_map();
auto* session = session_.load(std::memory_order_acquire);
return session ? session->token_map() : nullptr;
}

} // namespace cass
6 changes: 4 additions & 2 deletions src/load_balancing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <list>
#include <set>
#include <string>
#include <atomic>

#include <uv.h>

Expand Down Expand Up @@ -82,7 +83,7 @@ class LoadBalancingPolicy : public Host::StateListener, public RefCounted<LoadBa
typedef SharedRefPtr<LoadBalancingPolicy> Ptr;

LoadBalancingPolicy()
: RefCounted<LoadBalancingPolicy>(), session_(NULL) {}
: RefCounted<LoadBalancingPolicy>() {}

virtual ~LoadBalancingPolicy() {}

Expand Down Expand Up @@ -112,7 +113,8 @@ class LoadBalancingPolicy : public Host::StateListener, public RefCounted<LoadBa
const Metadata* metadata() const;
const TokenMap* token_map() const;

Session* session_;
private:
std::atomic<Session*> session_{nullptr};
};


Expand Down
5 changes: 3 additions & 2 deletions src/partition_aware_policy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ QueryPlan* PartitionAwarePolicy::new_query_plan(const std::string& keyspace,
RequestHandler* request_handler) {
QueryPlan* const child_plan = child_policy_->new_query_plan(keyspace, request_handler);

if (request_handler == NULL || request_handler->request() == NULL || metadata() == NULL) {
auto* metadata = this->metadata();
if (request_handler == NULL || request_handler->request() == NULL || metadata == NULL) {
LOG_TRACE("Request or metadata is not available - child policy will be used");
return child_plan;
}
Expand All @@ -215,7 +216,7 @@ QueryPlan* PartitionAwarePolicy::new_query_plan(const std::string& keyspace,
return child_plan;
}

const Metadata::SchemaSnapshot schema = metadata()->schema_snapshot(
const Metadata::SchemaSnapshot schema = metadata->schema_snapshot(
CASS_HIGHEST_SUPPORTED_PROTOCOL_VERSION, VersionNumber(3, 0, 0));
const TableSplitMetadata::MapPtr& partitions = schema.get_partitions();

Expand Down