Skip to content

Commit

Permalink
Prevent copying structs and functions in MySQL Client
Browse files Browse the repository at this point in the history
Summary: Stop copying

Reviewed By: fadimounir

Differential Revision: D45791977

fbshipit-source-id: 702863a5c6053afdf2f2a93dba893fad24a827b9
  • Loading branch information
Aditya Jalan authored and facebook-github-bot committed May 16, 2023
1 parent ded3774 commit 945a9f4
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 15 deletions.
5 changes: 3 additions & 2 deletions squangle/logger/DBEventCounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace facebook {
namespace db {

void ConnectionContextBase::collectNormalValues(
AddNormalValueFunction add) const {
const AddNormalValueFunction& add) const {
add("is_ssl", folly::to<std::string>(isSslConnection));
add("is_ssl_session_reused", folly::to<std::string>(sslSessionReused));
if (!sslVersion.empty()) {
Expand All @@ -37,7 +37,8 @@ void ConnectionContextBase::collectNormalValues(
}
}

void ConnectionContextBase::collectIntValues(AddIntValueFunction add) const {
void ConnectionContextBase::collectIntValues(
const AddIntValueFunction& add) const {
add("ssl_server_cert_validated", isServerCertValidated ? 1 : 0);
add("ssl_client_identity_cert", isIdentityClientCert ? 1 : 0);
if (certCacheSize.has_value()) {
Expand Down
4 changes: 2 additions & 2 deletions squangle/logger/DBEventCounter.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ using AddIntValueFunction =
class ConnectionContextBase {
public:
virtual ~ConnectionContextBase() {}
virtual void collectNormalValues(AddNormalValueFunction add) const;
virtual void collectIntValues(AddIntValueFunction add) const;
virtual void collectNormalValues(const AddNormalValueFunction& add) const;
virtual void collectIntValues(const AddIntValueFunction& add) const;
virtual std::unique_ptr<ConnectionContextBase> copy() const {
return std::make_unique<ConnectionContextBase>(*this);
}
Expand Down
2 changes: 1 addition & 1 deletion squangle/mysql_client/AsyncConnectionPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ std::ostream& operator<<(std::ostream& os, const PoolOptions& options) {
<< ",pool per instance:" << options.poolPerMysqlInstance() << "}";
}

std::ostream& operator<<(std::ostream& os, PoolKey key) {
std::ostream& operator<<(std::ostream& os, const PoolKey& key) {
return os << "{key:" << key.connKey.getDisplayString()
<< ",options:" << key.connOptions.getDisplayString() << "}";
}
Expand Down
4 changes: 2 additions & 2 deletions squangle/mysql_client/DbResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ void StreamedQueryResult::setResult(
}

void StreamedQueryResult::setException(folly::exception_wrapper ex) {
exception_wrapper_ = ex;
exception_wrapper_ = std::move(ex);
}

void StreamedQueryResult::freeHandler() {
Expand All @@ -215,7 +215,7 @@ void StreamedQueryResult::freeHandler() {

MultiQueryStreamHandler::MultiQueryStreamHandler(
std::shared_ptr<MultiQueryStreamOperation> op)
: operation_(op) {}
: operation_(std::move(op)) {}

folly::Optional<StreamedQueryResult> MultiQueryStreamHandler::nextQuery() {
if (state_ == State::RunQuery) {
Expand Down
2 changes: 1 addition & 1 deletion squangle/mysql_client/PoolKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct PoolKeyStats {
size_t connection_limit;
};

std::ostream& operator<<(std::ostream& os, PoolKey key);
std::ostream& operator<<(std::ostream& os, const PoolKey& key);

class PoolKeyHash {
public:
Expand Down
12 changes: 8 additions & 4 deletions squangle/mysql_client/Query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,17 @@ QueryArgument::QueryArgument(folly::fbstring&& val) : value_(std::move(val)) {}

QueryArgument::QueryArgument(double double_val) : value_(double_val) {}

QueryArgument::QueryArgument(std::initializer_list<QueryArgument> list)
QueryArgument::QueryArgument(const std::initializer_list<QueryArgument>& list)
: value_(std::vector<QueryArgument>(list.begin(), list.end())) {}

QueryArgument::QueryArgument(std::vector<QueryArgument> arg_list)
: value_(std::vector<QueryArgument>(arg_list.begin(), arg_list.end())) {}
: value_(std::move(arg_list)) {}

QueryArgument::QueryArgument() : value_(std::vector<ArgPair>()) {}

QueryArgument::QueryArgument(folly::StringPiece param1, QueryArgument param2)
QueryArgument::QueryArgument(
folly::StringPiece param1,
const QueryArgument& param2)
: value_(std::vector<ArgPair>()) {
getPairs().emplace_back(ArgPair(param1.str(), param2));
}
Expand Down Expand Up @@ -223,7 +225,9 @@ std::vector<ArgPair>& QueryArgument::getPairs() {
Query::Query(
const folly::StringPiece query_text,
std::vector<QueryArgument> params)
: query_text_(query_text), unsafe_query_(false), params_(params) {}
: query_text_(query_text),
unsafe_query_(false),
params_(std::move(params)) {}

Query::~Query() {}

Expand Down
5 changes: 3 additions & 2 deletions squangle/mysql_client/Query.h
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,8 @@ class QueryArgument {
: value_(static_cast<int64_t>(enum_val)) {}
/* implicit */ QueryArgument(double double_val);

/* implicit */ QueryArgument(std::initializer_list<QueryArgument> list);
/* implicit */ QueryArgument(
const std::initializer_list<QueryArgument>& list);
/* implicit */ QueryArgument(std::vector<QueryArgument> arg_list);
/* implicit */ QueryArgument(std::tuple<folly::fbstring, folly::fbstring> tup)
: value_(tup) {}
Expand Down Expand Up @@ -488,7 +489,7 @@ class QueryArgument {

// Pair constructors
QueryArgument();
QueryArgument(folly::StringPiece param1, QueryArgument param2);
QueryArgument(folly::StringPiece param1, const QueryArgument& param2);

// Since we already have callsites that use dynamic, we are keeping the
// support, but internally we unpack them.
Expand Down
3 changes: 2 additions & 1 deletion squangle/mysql_client/SyncMysqlClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ std::shared_ptr<SyncMysqlClient> SyncMysqlClient::defaultClient() {
std::unique_ptr<Connection> SyncMysqlClient::createConnection(
ConnectionKey conn_key,
MYSQL* mysql_conn) {
return std::make_unique<SyncConnection>(this, conn_key, mysql_conn);
return std::make_unique<SyncConnection>(
this, std::move(conn_key), mysql_conn);
}

SyncConnection::~SyncConnection() {
Expand Down

0 comments on commit 945a9f4

Please sign in to comment.