Skip to content

Commit

Permalink
replace gscoped_ptr with std::unique_ptr
Browse files Browse the repository at this point in the history
The remaining usages are in gutil, where we've imported code wholesale which
contained gscoped_ptr and I'm loathe to remove it right now.

Given the high number of touched files, there are also a fair number of iwyu
and clang-tidy fixups in this patch.

Change-Id: I9a35557b49dba7cc6a0c131841ae3c96230bb2fc
Reviewed-on: http://gerrit.cloudera.org:8080/15387
Reviewed-by: Alexey Serbin <[email protected]>
Tested-by: Adar Dembo <[email protected]>
  • Loading branch information
adembo committed Mar 10, 2020
1 parent ef8696a commit eaed5fb
Show file tree
Hide file tree
Showing 146 changed files with 679 additions and 818 deletions.
6 changes: 3 additions & 3 deletions docs/design-docs/cpp-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ void ExplicitBatchingExample() {
}

// Update a row.
gscoped_ptr<Update> upd = t->NewUpdate();
unique_ptr<Update> upd = t->NewUpdate();
upd->mutable_row()->SetInt64("key", 1);
upd->mutable_row()->SetInt64("val", 1 * 2 + 1);

// Delete a row.
gscoped_ptr<Delete> del = t->NewDelete();
unique_ptr<Delete> del = t->NewDelete();
del->mutable_row()->SetInt64("key", 2); // only specify key.

// Setting a timeout on the session applies to the next Flush call.
Expand Down Expand Up @@ -107,7 +107,7 @@ void BulkIngestExample() {
CHECK_OK(session->SetFlushMode(KuduSession::AUTO_FLUSH_BACKGROUND));

for (int i = 0; i < 10000; i++) {
gscoped_ptr<Insertion> ins = t->NewInsertion();
unique_ptr<Insertion> ins = t->NewInsertion();
ins->SetInt64("key", i);
ins->SetInt64("val", i * 2);
// This will start getting written in the background.
Expand Down
27 changes: 15 additions & 12 deletions src/kudu/benchmarks/tpch/rpc_line_item_dao-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,22 @@
// specific language governing permissions and limitations
// under the License.

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

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

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

#include "kudu/benchmarks/tpch/rpc_line_item_dao.h"
#include "kudu/benchmarks/tpch/tpch-schemas.h"
#include "kudu/client/row_result.h"
#include "kudu/common/partial_row.h"
#include "kudu/gutil/gscoped_ptr.h"
#include "kudu/gutil/port.h"
#include "kudu/gutil/stringprintf.h"
#include "kudu/master/mini_master.h"
Expand All @@ -38,14 +40,15 @@
#include "kudu/util/test_macros.h"
#include "kudu/util/test_util.h"

namespace kudu {

using client::KuduRowResult;
using cluster::InternalMiniCluster;
using cluster::InternalMiniClusterOptions;
using kudu::client::KuduRowResult;
using kudu::cluster::InternalMiniCluster;
using kudu::cluster::InternalMiniClusterOptions;
using std::string;
using std::unique_ptr;
using std::vector;

namespace kudu {

class RpcLineItemDAOTest : public KuduTest {

public:
Expand Down Expand Up @@ -76,8 +79,8 @@ class RpcLineItemDAOTest : public KuduTest {
}

protected:
gscoped_ptr<InternalMiniCluster> cluster_;
gscoped_ptr<RpcLineItemDAO> dao_;
unique_ptr<InternalMiniCluster> cluster_;
unique_ptr<RpcLineItemDAO> dao_;

// Builds a test row to be inserted into the lineitem table.
// The row's ship_date is set such that it matches the TPCH Q1 predicate.
Expand Down Expand Up @@ -107,7 +110,7 @@ class RpcLineItemDAOTest : public KuduTest {
}

int CountRows() {
gscoped_ptr<RpcLineItemDAO::Scanner> scanner;
unique_ptr<RpcLineItemDAO::Scanner> scanner;
dao_->OpenScanner(vector<string>(), &scanner);
vector<KuduRowResult> rows;
int count = 0;
Expand All @@ -121,7 +124,7 @@ class RpcLineItemDAOTest : public KuduTest {
void ScanTpch1RangeToStrings(int64_t min_orderkey, int64_t max_orderkey,
vector<string>* str_rows) {
str_rows->clear();
gscoped_ptr<RpcLineItemDAO::Scanner> scanner;
unique_ptr<RpcLineItemDAO::Scanner> scanner;
dao_->OpenTpch1ScannerForOrderKeyRange(min_orderkey, max_orderkey,
&scanner);
vector<KuduRowResult> rows;
Expand Down Expand Up @@ -161,7 +164,7 @@ TEST_F(RpcLineItemDAOTest, TestUpdate) {

dao_->MutateLine(boost::bind(UpdateTestRow, 1, 1, 12345, _1));
dao_->FinishWriting();
gscoped_ptr<RpcLineItemDAO::Scanner> scanner;
unique_ptr<RpcLineItemDAO::Scanner> scanner;
dao_->OpenScanner({ tpch::kQuantityColName }, &scanner);
vector<KuduRowResult> rows;
while (scanner->HasMore()) {
Expand Down
53 changes: 25 additions & 28 deletions src/kudu/benchmarks/tpch/rpc_line_item_dao.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

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

#include <memory>
#include <ostream>
#include <vector>
#include <utility>
Expand All @@ -32,7 +33,6 @@
#include "kudu/client/schema.h"
#include "kudu/client/value.h"
#include "kudu/client/write_op.h"
#include "kudu/gutil/gscoped_ptr.h"
#include "kudu/gutil/port.h"
#include "kudu/gutil/stl_util.h"
#include "kudu/util/monotime.h"
Expand All @@ -42,29 +42,26 @@
DEFINE_bool(tpch_cache_blocks_when_scanning, true,
"Whether the scanners should cache the blocks that are read or not");

using kudu::client::KuduInsert;
using kudu::client::KuduClientBuilder;
using kudu::client::KuduError;
using kudu::client::KuduPredicate;
using kudu::client::KuduRowResult;
using kudu::client::KuduScanner;
using kudu::client::KuduSchema;
using kudu::client::KuduSession;
using kudu::client::KuduStatusCallback;
using kudu::client::KuduTableCreator;
using kudu::client::KuduUpdate;
using kudu::client::KuduValue;
using std::string;
using std::unique_ptr;
using std::vector;

namespace kudu {

class KuduPartialRow;

using client::KuduInsert;
using client::KuduClient;
using client::KuduClientBuilder;
using client::KuduError;
using client::KuduPredicate;
using client::KuduRowResult;
using client::KuduScanner;
using client::KuduSchema;
using client::KuduSession;
using client::KuduStatusCallback;
using client::KuduStatusMemberCallback;
using client::KuduTableCreator;
using client::KuduUpdate;
using client::KuduValue;
using std::vector;

namespace {

class FlushCallback : public KuduStatusCallback {
Expand Down Expand Up @@ -137,7 +134,7 @@ void RpcLineItemDAO::Init() {
.Build(&client_));
Status s = client_->OpenTable(table_name_, &client_table_);
if (s.IsNotFound()) {
gscoped_ptr<KuduTableCreator> table_creator(client_->NewTableCreator());
unique_ptr<KuduTableCreator> table_creator(client_->NewTableCreator());
table_creator->table_name(table_name_)
.schema(&schema)
.num_replicas(1);
Expand Down Expand Up @@ -166,14 +163,14 @@ void RpcLineItemDAO::Init() {
}

void RpcLineItemDAO::WriteLine(const boost::function<void(KuduPartialRow*)> &f) {
gscoped_ptr<KuduInsert> insert(client_table_->NewInsert());
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) {
gscoped_ptr<KuduUpdate> update(client_table_->NewUpdate());
unique_ptr<KuduUpdate> update(client_table_->NewUpdate());
f(update->mutable_row());
CHECK_OK(session_->Apply(update.release()));
HandleLine();
Expand All @@ -188,31 +185,31 @@ void RpcLineItemDAO::FinishWriting() {
}

void RpcLineItemDAO::OpenScanner(const vector<string>& columns,
gscoped_ptr<Scanner>* out_scanner) {
unique_ptr<Scanner>* out_scanner) {
vector<KuduPredicate*> preds;
OpenScannerImpl(columns, preds, out_scanner);
}

void RpcLineItemDAO::OpenTpch1Scanner(gscoped_ptr<Scanner>* out_scanner) {
void RpcLineItemDAO::OpenTpch1Scanner(unique_ptr<Scanner>* out_scanner) {
vector<KuduPredicate*> preds;
preds.push_back(client_table_->NewComparisonPredicate(
tpch::kShipDateColName, KuduPredicate::LESS_EQUAL,
KuduValue::CopyString(kScanUpperBound)));
OpenScannerImpl(tpch::GetTpchQ1QueryColumns(), preds, out_scanner);
}

void RpcLineItemDAO::OpenTpch1ScannerForOrderKeyRange(int64_t min_key, int64_t max_key,
gscoped_ptr<Scanner>* out_scanner) {
void RpcLineItemDAO::OpenTpch1ScannerForOrderKeyRange(
int64_t min_orderkey, int64_t max_orderkey, unique_ptr<Scanner>* out_scanner) {
vector<KuduPredicate*> preds;
preds.push_back(client_table_->NewComparisonPredicate(
tpch::kShipDateColName, KuduPredicate::LESS_EQUAL,
KuduValue::CopyString(kScanUpperBound)));
preds.push_back(client_table_->NewComparisonPredicate(
tpch::kOrderKeyColName, KuduPredicate::GREATER_EQUAL,
KuduValue::FromInt(min_key)));
KuduValue::FromInt(min_orderkey)));
preds.push_back(client_table_->NewComparisonPredicate(
tpch::kOrderKeyColName, KuduPredicate::LESS_EQUAL,
KuduValue::FromInt(max_key)));
KuduValue::FromInt(max_orderkey)));
OpenScannerImpl(tpch::GetTpchQ1QueryColumns(), preds, out_scanner);
}

Expand All @@ -224,8 +221,8 @@ bool RpcLineItemDAO::IsTableEmpty() {

void RpcLineItemDAO::OpenScannerImpl(const vector<string>& columns,
const vector<KuduPredicate*>& preds,
gscoped_ptr<Scanner>* out_scanner) {
gscoped_ptr<Scanner> ret(new Scanner);
unique_ptr<Scanner>* out_scanner) {
unique_ptr<Scanner> ret(new Scanner);
ret->scanner_.reset(new KuduScanner(client_table_.get()));
ret->scanner_->SetCacheBlocks(FLAGS_tpch_cache_blocks_when_scanning);
CHECK_OK(ret->scanner_->SetProjectedColumnNames(columns));
Expand Down
21 changes: 10 additions & 11 deletions src/kudu/benchmarks/tpch/rpc_line_item_dao.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
#ifndef KUDU_TPCH_RPC_LINE_ITEM_DAO_H
#define KUDU_TPCH_RPC_LINE_ITEM_DAO_H
#pragma once

#include <cstdint>
#include <memory>
#include <string>
#include <vector>

#include "kudu/client/client.h"
#include "kudu/client/shared_ptr.h"
#include "kudu/client/row_result.h"
#include "kudu/gutil/gscoped_ptr.h"
#include "kudu/util/locks.h"
#include "kudu/util/monotime.h"
#include "kudu/util/semaphore.h"
Expand Down Expand Up @@ -67,18 +66,19 @@ class RpcLineItemDAO {
// Deletes previous scanner if one is open.
// Projects only those column names listed in 'columns'.
void OpenScanner(const std::vector<std::string>& columns,
gscoped_ptr<Scanner>* scanner);
std::unique_ptr<Scanner>* scanner);
// Calls OpenScanner with the tpch1 query parameters.
void OpenTpch1Scanner(gscoped_ptr<Scanner>* scanner);
void OpenTpch1Scanner(std::unique_ptr<Scanner>* scanner);

// Opens a scanner with the TPCH Q1 projection and filter, plus range filter to only
// select rows in the given order key range.
void OpenTpch1ScannerForOrderKeyRange(int64_t min_orderkey, int64_t max_orderkey,
gscoped_ptr<Scanner>* scanner);
std::unique_ptr<Scanner>* scanner);
bool IsTableEmpty();

// TODO: this wrapper class is of limited utility now that we only have a single
// "DAO" implementation -- we could just return the KuduScanner to users directly.
// TODO(unknown): this wrapper class is of limited utility now that we only
// have a single "DAO" implementation -- we could just return the KuduScanner
// to users directly.
class Scanner {
public:
~Scanner() {}
Expand All @@ -93,15 +93,15 @@ class RpcLineItemDAO {
friend class RpcLineItemDAO;
Scanner() {}

gscoped_ptr<client::KuduScanner> scanner_;
std::unique_ptr<client::KuduScanner> scanner_;
};

private:
static const Slice kScanUpperBound;

void OpenScannerImpl(const std::vector<std::string>& columns,
const std::vector<client::KuduPredicate*>& preds,
gscoped_ptr<Scanner>* scanner);
std::unique_ptr<Scanner>* scanner);
void HandleLine();

const std::string master_address_;
Expand All @@ -124,4 +124,3 @@ class RpcLineItemDAO {
};

} //namespace kudu
#endif
14 changes: 7 additions & 7 deletions src/kudu/benchmarks/tpch/tpch1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@

#include <cstdint>
#include <cstdlib>
#include <memory>
#include <ostream>
#include <string>
#include <unordered_map>
Expand All @@ -74,7 +75,6 @@
#include "kudu/benchmarks/tpch/rpc_line_item_dao.h"
#include "kudu/client/row_result.h"
#include "kudu/codegen/compilation_manager.h"
#include "kudu/gutil/gscoped_ptr.h"
#include "kudu/gutil/hash/city.h"
#include "kudu/gutil/stringprintf.h"
#include "kudu/master/mini_master.h"
Expand Down Expand Up @@ -104,14 +104,14 @@ DEFINE_int32(tpch_max_batch_size, 1000,
DEFINE_string(table_name, "lineitem",
"The table name to write/read");

using kudu::client::KuduRowResult;
using std::string;
using std::unique_ptr;
using std::unordered_map;
using std::vector;

namespace kudu {

using client::KuduRowResult;

struct Result {
int32_t l_quantity;
double l_extendedprice;
Expand Down Expand Up @@ -157,7 +157,7 @@ void LoadLineItems(const string &path, RpcLineItemDAO *dao) {

void WarmupScanCache(RpcLineItemDAO* dao) {
// Warms up cache for the tpch1 query.
gscoped_ptr<RpcLineItemDAO::Scanner> scanner;
unique_ptr<RpcLineItemDAO::Scanner> scanner;
dao->OpenTpch1Scanner(&scanner);
codegen::CompilationManager::GetSingleton()->Wait();
}
Expand All @@ -166,7 +166,7 @@ void Tpch1(RpcLineItemDAO *dao) {
typedef unordered_map<SliceMapKey, Result*, Hash> slice_map;
typedef unordered_map<SliceMapKey, slice_map*, Hash> slice_map_map;

gscoped_ptr<RpcLineItemDAO::Scanner> scanner;
unique_ptr<RpcLineItemDAO::Scanner> scanner;
dao->OpenTpch1Scanner(&scanner);

int matching_rows = 0;
Expand Down Expand Up @@ -255,7 +255,7 @@ int main(int argc, char **argv) {
kudu::InitGoogleLoggingSafe(argv[0]);

kudu::Env* env;
gscoped_ptr<kudu::cluster::InternalMiniCluster> cluster;
unique_ptr<kudu::cluster::InternalMiniCluster> cluster;
string master_address;
if (FLAGS_use_mini_cluster) {
env = kudu::Env::Default();
Expand All @@ -270,7 +270,7 @@ int main(int argc, char **argv) {
master_address = FLAGS_master_address;
}

gscoped_ptr<kudu::RpcLineItemDAO> dao(new kudu::RpcLineItemDAO(
unique_ptr<kudu::RpcLineItemDAO> dao(new kudu::RpcLineItemDAO(
master_address, FLAGS_table_name, FLAGS_tpch_max_batch_size,
/* timeout_ms = */ 5000, kudu::RpcLineItemDAO::RANGE,
/* num_buckets = */ 1));
Expand Down
Loading

0 comments on commit eaed5fb

Please sign in to comment.