Skip to content
Merged
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
2 changes: 1 addition & 1 deletion cmake/modules/CppDriver.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ macro(CassAddIncludes)
${CASS_SOURCE_DIR}/src/third_party/sparsehash/src
${CASS_INCLUDES}
)
add_subdirectory(src/third_party/sparsehash)
add_subdirectory(${CASS_SOURCE_DIR}/src/third_party/sparsehash)
endmacro()

#------------------------
Expand Down
11 changes: 3 additions & 8 deletions src/address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@

#include <assert.h>
#include <sstream>
#include <string.h>

namespace cass {

const Address Address::EMPTY_KEY("0.0.0.0", 0);
const Address Address::DELETED_KEY("0.0.0.0", 1);

Address::Address() {
init();
memset(&addr_, 0, sizeof(addr_));
}

Address::Address(const std::string& ip, int port) {
init();
memset(&addr_, 0, sizeof(addr_));
from_string(ip, port, this);
}

Expand Down Expand Up @@ -117,7 +118,6 @@ int Address::port() const {
} else if (family() == AF_INET6) {
return htons(addr_in6()->sin6_port);
} else {
assert(false);
return -1;
}
}
Expand All @@ -136,8 +136,6 @@ std::string Address::to_string(bool with_port) const {
if (with_port) ss << "[";
ss << host;
if (with_port) ss << "]:" << port();
} else {
assert(false);
}
return ss.str();
}
Expand Down Expand Up @@ -166,9 +164,6 @@ int Address::compare(const Address& a) const {
} else if (family() == AF_INET6) {
return memcmp(&(addr_in6()->sin6_addr), &(a.addr_in6()->sin6_addr),
sizeof(addr_in6()->sin6_addr));
} else {
assert(false);
return -1;
}
return 0;
}
Expand Down
9 changes: 3 additions & 6 deletions src/address.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@

#include <sparsehash/dense_hash_set>

#include <uv.h>
#include <set>
#include <string.h>
#include <string>
#include <uv.h>
#include <vector>

namespace cass {
Expand All @@ -39,7 +37,6 @@ class Address {

Address(const std::string& ip, int port);


static bool from_string(const std::string& ip, int port,
Address* output = NULL);

Expand Down Expand Up @@ -68,6 +65,8 @@ class Address {
return copy_cast<const struct sockaddr_storage*, const sockaddr_in6*>(&addr_);
}

bool is_valid() const { return family() == AF_INET || family() == AF_INET6; }

int family() const { return addr_.ss_family; }

int port() const;
Expand All @@ -78,8 +77,6 @@ class Address {
int compare(const Address& a) const;

private:
void init() { memset(&addr_, 0, sizeof(addr_)); }

struct sockaddr_storage addr_;
};

Expand Down
2 changes: 1 addition & 1 deletion src/auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

#include "auth.hpp"
#include "external_types.hpp"
#include "external.hpp"

#include "cassandra.h"

Expand Down
3 changes: 3 additions & 0 deletions src/auth.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define __CASS_AUTH_HPP_INCLUDED__

#include "buffer.hpp"
#include "external.hpp"
#include "host.hpp"
#include "macros.hpp"
#include "ref_counted.hpp"
Expand Down Expand Up @@ -169,4 +170,6 @@ class PlainTextAuthProvider : public AuthProvider {

} // namespace cass

EXTERNAL_TYPE(cass::ExternalAuthenticator, CassAuthenticator)

#endif
3 changes: 2 additions & 1 deletion src/batch_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

#include "constants.hpp"
#include "execute_request.hpp"
#include "external_types.hpp"
#include "external.hpp"
#include "handler.hpp"
#include "serialization.hpp"
#include "statement.hpp"

Expand Down
7 changes: 5 additions & 2 deletions src/batch_request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@

#include "cassandra.h"
#include "constants.hpp"
#include "external.hpp"
#include "request.hpp"
#include "ref_counted.hpp"

#include <list>
#include <map>
#include <string>
#include <vector>

namespace cass {

Expand All @@ -33,7 +34,7 @@ class ExecuteRequest;

class BatchRequest : public RoutableRequest {
public:
typedef std::list<SharedRefPtr<Statement> > StatementList;
typedef std::vector<SharedRefPtr<Statement> > StatementList;

BatchRequest(uint8_t type_)
: RoutableRequest(CQL_OPCODE_BATCH)
Expand Down Expand Up @@ -62,4 +63,6 @@ class BatchRequest : public RoutableRequest {

} // namespace cass

EXTERNAL_TYPE(cass::BatchRequest, CassBatch)

#endif
2 changes: 1 addition & 1 deletion src/cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "dc_aware_policy.hpp"
#include "logger.hpp"
#include "round_robin_policy.hpp"
#include "external_types.hpp"
#include "external.hpp"
#include "utils.hpp"

#include <sstream>
Expand Down
3 changes: 3 additions & 0 deletions src/cluster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define __CASS_CLUSTER_HPP_INCLUDED__

#include "config.hpp"
#include "external.hpp"

namespace cass {

Expand All @@ -32,4 +33,6 @@ class Cluster {

} // namespace cass

EXTERNAL_TYPE(cass::Cluster, CassCluster)

#endif
3 changes: 2 additions & 1 deletion src/collection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
#include "collection.hpp"

#include "constants.hpp"
#include "external_types.hpp"
#include "external.hpp"
#include "macros.hpp"
#include "tuple.hpp"
#include "user_type_value.hpp"

#include <string.h>
Expand Down
3 changes: 3 additions & 0 deletions src/collection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "cassandra.h"
#include "data_type.hpp"
#include "encode.hpp"
#include "external.hpp"
#include "buffer.hpp"
#include "ref_counted.hpp"
#include "types.hpp"
Expand Down Expand Up @@ -139,5 +140,7 @@ class Collection : public RefCounted<Collection> {

} // namespace cass

EXTERNAL_TYPE(cass::Collection, CassCollection)

#endif

10 changes: 10 additions & 0 deletions src/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "auth.hpp"
#include "cassandra.h"
#include "dc_aware_policy.hpp"
#include "host_targeting_policy.hpp"
#include "latency_aware_policy.hpp"
#include "retry_policy.hpp"
#include "ssl.hpp"
Expand Down Expand Up @@ -66,6 +67,7 @@ class Config {
, load_balancing_policy_(new DCAwarePolicy())
, token_aware_routing_(true)
, latency_aware_routing_(false)
, host_targeting_(false)
, tcp_nodelay_enable_(true)
, tcp_keepalive_enable_(false)
, tcp_keepalive_delay_secs_(0)
Expand Down Expand Up @@ -260,6 +262,9 @@ class Config {
if (latency_aware()) {
chain = new LatencyAwarePolicy(chain, latency_aware_routing_settings_);
}
if (host_targeting()) {
chain = new HostTargetingPolicy(chain);
}
return chain;
}

Expand All @@ -282,6 +287,10 @@ class Config {

void set_latency_aware_routing(bool is_latency_aware) { latency_aware_routing_ = is_latency_aware; }

bool host_targeting() const { return host_targeting_; }

void set_host_targeting(bool is_host_targeting) { host_targeting_ = is_host_targeting; }

void set_latency_aware_routing_settings(const LatencyAwarePolicy::Settings& settings) {
latency_aware_routing_settings_ = settings;
}
Expand Down Expand Up @@ -394,6 +403,7 @@ class Config {
SharedRefPtr<SslContext> ssl_context_;
bool token_aware_routing_;
bool latency_aware_routing_;
bool host_targeting_;
LatencyAwarePolicy::Settings latency_aware_routing_settings_;
ContactPointList whitelist_;
ContactPointList blacklist_;
Expand Down
2 changes: 1 addition & 1 deletion src/data_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "data_type.hpp"

#include "collection.hpp"
#include "external_types.hpp"
#include "external.hpp"
#include "tuple.hpp"
#include "types.hpp"
#include "user_type_value.hpp"
Expand Down
3 changes: 3 additions & 0 deletions src/data_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define __CASS_DATA_TYPE_HPP_INCLUDED__

#include "cassandra.h"
#include "external.hpp"
#include "hash_table.hpp"
#include "macros.hpp"
#include "ref_counted.hpp"
Expand Down Expand Up @@ -591,4 +592,6 @@ struct IsValidDataType<const UserTypeValue*> {

} // namespace cass

EXTERNAL_TYPE(cass::DataType, CassDataType)

#endif
9 changes: 4 additions & 5 deletions src/dc_aware_policy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "dc_aware_policy.hpp"

#include "logger.hpp"

#include "request_handler.hpp"
#include "scoped_lock.hpp"

#include <algorithm>
Expand Down Expand Up @@ -62,10 +62,9 @@ CassHostDistance DCAwarePolicy::distance(const SharedRefPtr<Host>& host) const {
}

QueryPlan* DCAwarePolicy::new_query_plan(const std::string& connected_keyspace,
const Request* request,
const TokenMap* token_map,
Request::EncodingCache* cache) {
CassConsistency cl = request != NULL ? request->consistency() : Request::DEFAULT_CONSISTENCY;
RequestHandler* request_handler,
const TokenMap* token_map) {
CassConsistency cl = request_handler != NULL ? request_handler->request()->consistency() : Request::DEFAULT_CONSISTENCY;
return new DCAwareQueryPlan(this, cl, index_++);
}

Expand Down
5 changes: 2 additions & 3 deletions src/dc_aware_policy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ class DCAwarePolicy : public LoadBalancingPolicy {
virtual CassHostDistance distance(const SharedRefPtr<Host>& host) const;

virtual QueryPlan* new_query_plan(const std::string& connected_keyspace,
const Request* request,
const TokenMap* token_map,
Request::EncodingCache* cache);
RequestHandler* request_handler,
const TokenMap* token_map);

virtual void on_add(const SharedRefPtr<Host>& host);

Expand Down
2 changes: 1 addition & 1 deletion src/error_response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include "error_response.hpp"

#include "external_types.hpp"
#include "external.hpp"
#include "logger.hpp"
#include "serialization.hpp"

Expand Down
3 changes: 3 additions & 0 deletions src/error_response.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#ifndef __CASS_ERROR_RESPONSE_HPP_INCLUDED__
#define __CASS_ERROR_RESPONSE_HPP_INCLUDED__

#include "external.hpp"
#include "response.hpp"
#include "constants.hpp"
#include "scoped_ptr.hpp"
Expand Down Expand Up @@ -84,4 +85,6 @@ bool check_error_or_invalid_response(const std::string& prefix, uint8_t expected

} // namespace cass

EXTERNAL_TYPE(cass::ErrorResponse, CassErrorResult)

#endif
5 changes: 4 additions & 1 deletion src/external_types.cpp → src/external.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
limitations under the License.
*/

#include "external_types.hpp"
#include "external.hpp"

#include "cassandra.h"

#include <string.h>
#include <uv.h>

#define NUM_SECONDS_PER_DAY (24U * 60U * 60U)
Expand Down
38 changes: 38 additions & 0 deletions src/external.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
Copyright (c) 2014-2016 DataStax

Licensed under the Apache License, Version 2.0 (the "License");
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

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#ifndef __CASS_EXTERNAL_HPP_INCLUDED__
#define __CASS_EXTERNAL_HPP_INCLUDED__

// This abstraction allows us to separate internal types from the
// external opaque pointers that we expose.
template <typename In, typename Ex>
struct External : public In {
In* from() { return static_cast<In*>(this); }
const In* from() const { return static_cast<const In*>(this); }
static Ex* to(In* in) { return static_cast<Ex*>(in); }
static const Ex* to(const In* in) { return static_cast<const Ex*>(in); }
};

#define EXTERNAL_TYPE(InternalType, ExternalType) \
extern "C" { \
struct ExternalType##_ : public External<InternalType, ExternalType> { \
private: \
~ExternalType##_() { } \
}; \
}

#endif
Loading