Skip to content

Commit

Permalink
remove last vestiges of boost::bind, boost::function, and std::bind
Browse files Browse the repository at this point in the history
With this patch, all Kudu functors use std::function, and all capturing or
binding is done via C++ lambdas.

The lack of support for capture-via-move rears its ugly head in
raft_consensus.cc, but I verified that this only leads to inefficiency, not
incorrectness (i.e. lifecycle issues). C++14 (or 17) support can't come soon
enough!

Change-Id: Ifd876f200f680f3d3617d78852f1e0a9c5649372
Reviewed-on: http://gerrit.cloudera.org:8080/15639
Tested-by: Kudu Jenkins
Reviewed-by: Alexey Serbin <[email protected]>
Reviewed-by: Andrew Wong <[email protected]>
  • Loading branch information
adembo committed Apr 4, 2020
1 parent 447b45d commit 5739add
Show file tree
Hide file tree
Showing 57 changed files with 528 additions and 556 deletions.
11 changes: 5 additions & 6 deletions src/kudu/benchmarks/tpch/rpc_line_item_dao-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@

#include <algorithm>
#include <cstdint>
#include <functional>
#include <memory>
#include <string>
#include <utility>
#include <vector>

#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <glog/logging.h>
#include <gtest/gtest.h>

Expand Down Expand Up @@ -140,12 +139,12 @@ class RpcLineItemDAOTest : public KuduTest {
}; // class RpcLineItemDAOTest

TEST_F(RpcLineItemDAOTest, TestInsert) {
dao_->WriteLine(boost::bind(BuildTestRow, 1, 1, _1));
dao_->WriteLine([](KuduPartialRow* row) { BuildTestRow(1, 1, row); });
dao_->FinishWriting();
ASSERT_EQ(1, CountRows());
for (int i = 2; i < 10; i++) {
for (int y = 0; y < 5; y++) {
dao_->WriteLine(boost::bind(BuildTestRow, i, y, _1));
dao_->WriteLine([=](KuduPartialRow* row) { BuildTestRow(i, y, row); });
}
}
dao_->FinishWriting();
Expand All @@ -159,11 +158,11 @@ TEST_F(RpcLineItemDAOTest, TestInsert) {
}

TEST_F(RpcLineItemDAOTest, TestUpdate) {
dao_->WriteLine(boost::bind(BuildTestRow, 1, 1, _1));
dao_->WriteLine([](KuduPartialRow* row) { BuildTestRow(1, 1, row); });
dao_->FinishWriting();
ASSERT_EQ(1, CountRows());

dao_->MutateLine(boost::bind(UpdateTestRow, 1, 1, 12345, _1));
dao_->MutateLine([](KuduPartialRow* row) { UpdateTestRow(1, 1, 12345, row); });
dao_->FinishWriting();
unique_ptr<RpcLineItemDAO::Scanner> scanner;
dao_->OpenScanner({ tpch::kQuantityColName }, &scanner);
Expand Down
6 changes: 3 additions & 3 deletions src/kudu/benchmarks/tpch/rpc_line_item_dao.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

#include "kudu/benchmarks/tpch/rpc_line_item_dao.h"

#include <functional>
#include <memory>
#include <ostream>
#include <vector>
#include <utility>

#include <boost/function.hpp>
#include <gflags/gflags.h>
#include <glog/logging.h>

Expand Down Expand Up @@ -162,14 +162,14 @@ void RpcLineItemDAO::Init() {
: KuduSession::AUTO_FLUSH_BACKGROUND));
}

void RpcLineItemDAO::WriteLine(const boost::function<void(KuduPartialRow*)> &f) {
void RpcLineItemDAO::WriteLine(const std::function<void(KuduPartialRow*)>& f) {
unique_ptr<KuduInsert> insert(client_table_->NewInsert());
f(insert->mutable_row());
CHECK_OK(session_->Apply(insert.release()));
HandleLine();
}

void RpcLineItemDAO::MutateLine(const boost::function<void(KuduPartialRow*)> &f) {
void RpcLineItemDAO::MutateLine(const std::function<void(KuduPartialRow*)>& f) {
unique_ptr<KuduUpdate> update(client_table_->NewUpdate());
f(update->mutable_row());
CHECK_OK(session_->Apply(update.release()));
Expand Down
10 changes: 3 additions & 7 deletions src/kudu/benchmarks/tpch/rpc_line_item_dao.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#pragma once

#include <cstdint>
#include <functional>
#include <memory>
#include <string>
#include <vector>
Expand All @@ -28,11 +29,6 @@
#include "kudu/util/monotime.h"
#include "kudu/util/semaphore.h"

namespace boost {
template <typename Signature>
class function;
} // namespace boost

namespace kudu {

namespace client {
Expand All @@ -59,8 +55,8 @@ class RpcLineItemDAO {
std::vector<const KuduPartialRow*> tablet_splits = {});
~RpcLineItemDAO();
void Init();
void WriteLine(const boost::function<void(KuduPartialRow*)>& f);
void MutateLine(const boost::function<void(KuduPartialRow*)>& f);
void WriteLine(const std::function<void(KuduPartialRow*)>& f);
void MutateLine(const std::function<void(KuduPartialRow*)>& f);
void FinishWriting();

// Deletes previous scanner if one is open.
Expand Down
11 changes: 7 additions & 4 deletions src/kudu/benchmarks/tpch/tpch1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,14 @@

#include <cstdint>
#include <cstdlib>
#include <functional>
#include <memory>
#include <ostream>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <gflags/gflags.h>
#include <glog/logging.h>

Expand All @@ -86,6 +85,10 @@
#include "kudu/util/status.h"
#include "kudu/util/stopwatch.h"

namespace kudu {
class KuduPartialRow;
} // namespace kudu

DEFINE_string(tpch_path_to_data, "/tmp/lineitem.tbl",
"The full path to the '|' separated file containing the lineitem table.");
DEFINE_int32(tpch_num_query_iterations, 1, "Number of times the query will be run.");
Expand Down Expand Up @@ -148,9 +151,9 @@ struct Hash {
void LoadLineItems(const string &path, RpcLineItemDAO *dao) {
LineItemTsvImporter importer(path);

auto f = [&importer](KuduPartialRow* row) { importer.GetNextLine(row); };
while (importer.HasNextLine()) {
dao->WriteLine(boost::bind(&LineItemTsvImporter::GetNextLine,
&importer, _1));
dao->WriteLine(f);
}
dao->FinishWriting();
}
Expand Down
6 changes: 2 additions & 4 deletions src/kudu/benchmarks/tpch/tpch_real_world.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,14 @@
#include <csignal>
#include <cstdint>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <memory>
#include <string>
#include <thread>
#include <utility>
#include <vector>

#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <gflags/gflags.h>
#include <glog/logging.h>

Expand Down Expand Up @@ -311,8 +310,7 @@ void TpchRealWorld::LoadLineItemsThread(int i) {
unique_ptr<RpcLineItemDAO> dao = GetInittedDAO();
LineItemTsvImporter importer(GetNthLineItemFileName(i));

boost::function<void(KuduPartialRow*)> f =
boost::bind(&LineItemTsvImporter::GetNextLine, &importer, _1);
auto f = [&importer](KuduPartialRow* row) { importer.GetNextLine(row); };
const string time_spent_msg = Substitute(
"by thread $0 to load generated data into the database", i);
LOG_TIMING(INFO, time_spent_msg) {
Expand Down
6 changes: 3 additions & 3 deletions src/kudu/cfile/encoding-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class TestEncoding : public KuduTest {
// Insert "hello 0" through "hello 9"
const uint kCount = 10;
Slice s = CreateBinaryBlock(
&sbb, kCount, std::bind(StringPrintf, "hello %d", std::placeholders::_1));
&sbb, kCount, [](int item) { return StringPrintf("hello %d", item); });
DecoderType sbd(s);
ASSERT_OK(sbd.ParseHeader());

Expand Down Expand Up @@ -185,7 +185,7 @@ class TestEncoding : public KuduTest {
const uint kCount = 1000;
// Insert 'hello 000' through 'hello 999'
Slice s = CreateBinaryBlock(
&sbb, kCount, std::bind(StringPrintf, "hello %03d", std::placeholders::_1));
&sbb, kCount, [](int item) { return StringPrintf("hello %03d", item); });
BinaryPrefixBlockDecoder sbd(s);
ASSERT_OK(sbd.ParseHeader());

Expand Down Expand Up @@ -476,7 +476,7 @@ class TestEncoding : public KuduTest {
size_t sbsize;

Slice s = CreateBinaryBlock(
&sbb, kCount, std::bind(StringPrintf, "hello %d", std::placeholders::_1));
&sbb, kCount, [](int item) { return StringPrintf("hello %d", item); });
do {
sbsize = s.size();

Expand Down
50 changes: 27 additions & 23 deletions src/kudu/client/client-internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@
#include <utility>
#include <vector>

#include <boost/bind.hpp> // IWYU pragma: keep
#include <boost/container/small_vector.hpp>
#include <boost/container/vector.hpp>
#include <boost/function.hpp>
#include <gflags/gflags_declare.h>
#include <glog/logging.h>
#include <google/protobuf/stubs/common.h>
Expand Down Expand Up @@ -92,6 +90,7 @@ class SignedTokenPB;

using master::AlterTableRequestPB;
using master::AlterTableResponsePB;
using master::ConnectToMasterResponsePB;
using master::CreateTableRequestPB;
using master::CreateTableResponsePB;
using master::DeleteTableRequestPB;
Expand Down Expand Up @@ -122,7 +121,7 @@ using internal::RemoteTabletServer;
Status RetryFunc(const MonoTime& deadline,
const string& retry_msg,
const string& timeout_msg,
const boost::function<Status(const MonoTime&, bool*)>& func) {
const std::function<Status(const MonoTime&, bool*)>& func) {
DCHECK(deadline.Initialized());

if (deadline < MonoTime::Now()) {
Expand Down Expand Up @@ -183,10 +182,11 @@ KuduClient::Data::~Data() {
dns_resolver_.reset();
}

RemoteTabletServer* KuduClient::Data::SelectTServer(const scoped_refptr<RemoteTablet>& rt,
const ReplicaSelection selection,
const set<string>& blacklist,
vector<RemoteTabletServer*>* candidates) const {
RemoteTabletServer* KuduClient::Data::SelectTServer(
const scoped_refptr<RemoteTablet>& rt,
const ReplicaSelection selection,
const set<string>& blacklist,
vector<RemoteTabletServer*>* candidates) const {
RemoteTabletServer* ret = nullptr;
candidates->clear();
switch (selection) {
Expand Down Expand Up @@ -334,11 +334,13 @@ Status KuduClient::Data::WaitForCreateTableToFinish(
KuduClient* client,
TableIdentifierPB table,
const MonoTime& deadline) {
return RetryFunc(deadline,
"Waiting on Create Table to be completed",
"Timed out waiting for Table Creation",
boost::bind(&KuduClient::Data::IsCreateTableInProgress,
this, client, std::move(table), _1, _2));
return RetryFunc(
deadline,
"Waiting on Create Table to be completed",
"Timed out waiting for Table Creation",
[&](const MonoTime& deadline, bool* retry) {
return IsCreateTableInProgress(client, table, deadline, retry);
});
}

Status KuduClient::Data::DeleteTable(KuduClient* client,
Expand Down Expand Up @@ -400,11 +402,13 @@ Status KuduClient::Data::WaitForAlterTableToFinish(
KuduClient* client,
TableIdentifierPB table,
const MonoTime& deadline) {
return RetryFunc(deadline,
"Waiting on Alter Table to be completed",
"Timed out waiting for AlterTable",
boost::bind(&KuduClient::Data::IsAlterTableInProgress,
this, client, std::move(table), _1, _2));
return RetryFunc(
deadline,
"Waiting on Alter Table to be completed",
"Timed out waiting for AlterTable",
[&](const MonoTime& deadline, bool* retry) {
return IsAlterTableInProgress(client, table, deadline, retry);
});
}

Status KuduClient::Data::InitLocalHostNames() {
Expand Down Expand Up @@ -581,7 +585,7 @@ Status KuduClient::Data::GetTableSchema(KuduClient* client,
void KuduClient::Data::ConnectedToClusterCb(
const Status& status,
const pair<Sockaddr, string>& leader_addr_and_name,
const master::ConnectToMasterResponsePB& connect_response,
const ConnectToMasterResponsePB& connect_response,
CredentialsPolicy cred_policy) {

const auto& leader_addr = leader_addr_and_name.first;
Expand Down Expand Up @@ -734,11 +738,11 @@ void KuduClient::Data::ConnectToClusterAsync(KuduClient* client,
// policy.
scoped_refptr<internal::ConnectToClusterRpc> rpc(
new internal::ConnectToClusterRpc(
std::bind(&KuduClient::Data::ConnectedToClusterCb, this,
std::placeholders::_1,
std::placeholders::_2,
std::placeholders::_3,
creds_policy),
[this, creds_policy](const Status& status,
const std::pair<Sockaddr, string>& leader_master,
const ConnectToMasterResponsePB& connect_response) {
this->ConnectedToClusterCb(status, leader_master, connect_response, creds_policy);
},
std::move(master_addrs_with_names),
deadline,
client->default_rpc_timeout(),
Expand Down
Loading

0 comments on commit 5739add

Please sign in to comment.