Skip to content

Commit b4bb0fd

Browse files
committed
Fix code review issues #2
1 parent e563c5d commit b4bb0fd

8 files changed

+24
-13
lines changed

cpp-driver/src/connection.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class ConnectionListener {
8383
};
8484

8585
/**
86-
* A connection. It's a socket wrapper that handles Cassadndra/DSE specific
86+
* A connection. It's a socket wrapper that handles Cassandra/DSE specific
8787
* functionality such as decoding responses and heartbeats. It can not be
8888
* connected directly instead use a Connector object.
8989
*

cpp-driver/src/connection_pool_manager.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,11 @@ void ConnectionPoolManager::add(const Address& address) {
9898
}
9999

100100
void ConnectionPoolManager::remove(const Address& address) {
101-
ScopedWriteLock rl(&rwlock_);
101+
ScopedReadLock rl(&rwlock_);
102102
ConnectionPool::Map::iterator it = pools_.find(address);
103103
if (it == pools_.end()) return;
104+
// The connection pool will remove itself from the manager when all of its
105+
// connections are closed.
104106
it->second->close();
105107
}
106108

@@ -141,7 +143,8 @@ void ConnectionPoolManager::add_pool(const ConnectionPool::Ptr& pool, Protected)
141143
}
142144

143145
void ConnectionPoolManager::remove_pool(ConnectionPool* pool, Protected) {
144-
internal_remove_pool(pool->address());
146+
ScopedWriteLock wl(&rwlock_);
147+
internal_remove_pool(wl, pool->address());
145148
}
146149

147150
void ConnectionPoolManager::notify_up(ConnectionPool* pool, Protected) {
@@ -163,20 +166,23 @@ void ConnectionPoolManager::notify_critical_error(ConnectionPool* pool,
163166
if (listener_ != NULL) {
164167
listener_->on_critical_error(pool->address(), code, message);
165168
}
166-
internal_remove_pool(pool->address());
169+
ScopedWriteLock wl(&rwlock_);
170+
internal_remove_pool(wl, pool->address());
167171
}
168172

169173
void ConnectionPoolManager::internal_add_pool(const ConnectionPool::Ptr& pool) {
170174
LOG_DEBUG("Adding pool for host %s", pool->address().to_string().c_str());
171175
pools_[pool->address()] = pool;
172176
}
173177

174-
void ConnectionPoolManager::internal_remove_pool(const Address& address) {
175-
ScopedWriteLock wl(&rwlock_);
178+
void ConnectionPoolManager::internal_remove_pool(ScopedWriteLock& wl,
179+
const Address& address) {
176180
pools_.erase(address);
177181
maybe_closed(wl);
178182
}
179183

184+
// This must be the last call in a function because it can potentially
185+
// deallocate the manager.
180186
void ConnectionPoolManager::maybe_closed(ScopedWriteLock& wl) {
181187
if (is_closing_ && pools_.empty()) {
182188
wl.unlock(); // The manager is destroyed in this step it must be unlocked

cpp-driver/src/connection_pool_manager.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ class ConnectionPoolManager : public RefCounted<ConnectionPoolManager> {
221221

222222
private:
223223
void internal_add_pool(const ConnectionPool::Ptr& pool);
224-
void internal_remove_pool(const Address& address);
224+
void internal_remove_pool(ScopedWriteLock& wl,
225+
const Address& address);
225226
void maybe_closed(ScopedWriteLock& wl);
226227

227228
private:

cpp-driver/src/connector.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ Connector* Connector::with_metrics(Metrics* metrics) {
193193

194194
Connector* Connector::with_settings(const ConnectionSettings& settings) {
195195
settings_ = settings;
196+
// Only use hostname resolution if actually required for SSL or
197+
// authentication.
198+
settings_.socket_settings.hostname_resolution_enabled
199+
= settings.socket_settings.hostname_resolution_enabled &&
200+
(settings.auth_provider || settings.socket_settings.ssl_context);
196201
return this;
197202
}
198203

cpp-driver/src/pooled_connection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class RunClose : public Task {
4141

4242
/**
4343
* A request callback that sets the keyspace then runs the original request
44-
* callback. The happens when the current keyspace wasn't set or has been
44+
* callback. This happens when the current keyspace wasn't set or has been
4545
* changed.
4646
*/
4747
class ChainedSetKeyspaceCallback : public SimpleRequestCallback {

cpp-driver/src/request_callback.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,13 @@ ChainedRequestCallback::ChainedRequestCallback(const String& key, const Request:
234234
, has_pending_(false)
235235
, key_(key) { }
236236

237-
ChainedRequestCallback::Ptr ChainedRequestCallback::chain(const String&key, const String& query) {
237+
ChainedRequestCallback::Ptr ChainedRequestCallback::chain(const String& key, const String& query) {
238238
has_pending_ = true;
239239
return ChainedRequestCallback::Ptr(
240240
Memory::allocate<ChainedRequestCallback>(key, query, Ptr(this)));
241241
}
242242

243-
ChainedRequestCallback::Ptr ChainedRequestCallback::chain(const String&key, const Request::ConstPtr& request) {
243+
ChainedRequestCallback::Ptr ChainedRequestCallback::chain(const String& key, const Request::ConstPtr& request) {
244244
has_pending_ = true;
245245
return ChainedRequestCallback::Ptr(
246246
Memory::allocate<ChainedRequestCallback>(key, request, Ptr(this)));

cpp-driver/src/request_handler.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ class RequestHandler : public RefCounted<RequestHandler> {
170170

171171
void start_request(uv_loop_t* loop, Protected);
172172

173-
void add_execution(RequestExecution* request_execution, Protected);
174173
void add_attempted_address(const Address& address, Protected);
175174

176175
void notify_result_metadata_changed(const String& prepared_id,

cpp-driver/src/socket_connector.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ void SocketConnector::handle_connect(TcpConnector* tcp_connector) {
199199
#if defined(HAVE_NOSIGPIPE) && UV_VERSION_MAJOR >= 1
200200
uv_tcp_t* tcp = &socket_->tcp_;
201201

202-
// This must be done after socket for the socket file descriptor to be
203-
// valid.
202+
// This must be done after the socket is intialized, which is done in the
203+
// connection process, for the socket file descriptor to be valid.
204204
uv_os_fd_t fd = 0;
205205
int enabled = 1;
206206
if (uv_fileno(reinterpret_cast<uv_handle_t*>(tcp), &fd) != 0 ||

0 commit comments

Comments
 (0)