Skip to content

Commit

Permalink
[#11949] DocDB: Update C++ standard to C++20
Browse files Browse the repository at this point in the history
Summary: This diff updates C++ standard to C++20 and fixes all build related issues that occured because of that.

Test Plan: Jenkins

Reviewers: bogdan, dmitry, dfelsing

Reviewed By: dmitry, dfelsing

Subscribers: dfelsing, ybase

Differential Revision: https://phabricator.dev.yugabyte.com/D16320
  • Loading branch information
spolitov committed Apr 22, 2022
1 parent 3b16512 commit f79548c
Show file tree
Hide file tree
Showing 29 changed files with 67 additions and 66 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ string (REPLACE "-Woverloaded-virtual" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})

message("CMAKE_C_FLAGS ${CMAKE_C_FLAGS}")

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)

if (IS_GCC AND
"${COMPILER_VERSION}" VERSION_GREATER_EQUAL "8.0.0")
Expand Down
6 changes: 3 additions & 3 deletions ent/src/yb/cdc/cdc_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1627,18 +1627,18 @@ void CDCServiceImpl::TabletLeaderGetChanges(const GetChangesRequestPB* req,
GetChangesRequestPB new_req;
new_req.CopyFrom(*req);
new_req.set_serve_as_proxy(false);
CoarseTimePoint deadline = GetDeadline(*context.get(), client());
CoarseTimePoint deadline = GetDeadline(*context, client());

*rpc_handle = CreateGetChangesCDCRpc(
deadline,
nullptr, /* RemoteTablet: will get this from 'new_req' */
client(),
&new_req,
[=] (Status status, GetChangesResponsePB&& new_resp) {
[this, resp, context, rpc_handle] (const Status& status, GetChangesResponsePB&& new_resp) {
auto retained = rpcs_.Unregister(rpc_handle);
*resp = std::move(new_resp);
RPC_STATUS_RETURN_ERROR(status, resp->mutable_error(), resp->error().code(),
*context.get());
*context);
context->RespondSuccess();
});
(**rpc_handle).SendRpc();
Expand Down
4 changes: 2 additions & 2 deletions ent/src/yb/integration-tests/twodc-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,15 @@ class TwoDCTest : public TwoDCTestBase, public testing::WithParamInterface<TwoDC
Status VerifyWrittenRecords(const YBTableName& producer_table,
const YBTableName& consumer_table,
int timeout_secs = kRpcTimeout) {
return LoggedWaitFor([=]() -> Result<bool> {
return LoggedWaitFor([this, producer_table, consumer_table]() -> Result<bool> {
auto producer_results = ScanToStrings(producer_table, producer_client());
auto consumer_results = ScanToStrings(consumer_table, consumer_client());
return producer_results == consumer_results;
}, MonoDelta::FromSeconds(timeout_secs), "Verify written records");
}

Status VerifyNumRecords(const YBTableName& table, YBClient* client, size_t expected_size) {
return LoggedWaitFor([=]() -> Result<bool> {
return LoggedWaitFor([this, table, client, expected_size]() -> Result<bool> {
auto results = ScanToStrings(table, client);
return results.size() == expected_size;
}, MonoDelta::FromSeconds(kRpcTimeout), "Verify number of records");
Expand Down
4 changes: 2 additions & 2 deletions ent/src/yb/integration-tests/twodc_test_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ Status TwoDCTestBase::VerifyUniverseReplicationDeleted(MiniCluster* consumer_clu

Status TwoDCTestBase::GetCDCStreamForTable(
const std::string& table_id, master::ListCDCStreamsResponsePB* resp) {
return LoggedWaitFor([=]() -> Result<bool> {
return LoggedWaitFor([this, table_id, resp]() -> Result<bool> {
master::ListCDCStreamsRequestPB req;
req.set_table_id(table_id);
resp->Clear();
Expand Down Expand Up @@ -232,7 +232,7 @@ size_t TwoDCTestBase::NumProducerTabletsPolled(MiniCluster* cluster) {

Status TwoDCTestBase::CorrectlyPollingAllTablets(
MiniCluster* cluster, uint32_t num_producer_tablets) {
return LoggedWaitFor([=]() -> Result<bool> {
return LoggedWaitFor([this, cluster, num_producer_tablets]() -> Result<bool> {
static int i = 0;
constexpr int kNumIterationsWithCorrectResult = 5;
auto cur_tablets = NumProducerTabletsPolled(cluster);
Expand Down
4 changes: 2 additions & 2 deletions ent/src/yb/integration-tests/twodc_ysql-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ class TwoDCYsqlTest : public TwoDCTestBase, public testing::WithParamInterface<T

Status VerifyWrittenRecords(const YBTableName& producer_table,
const YBTableName& consumer_table) {
return LoggedWaitFor([=]() -> Result<bool> {
return LoggedWaitFor([this, producer_table, consumer_table]() -> Result<bool> {
auto producer_results = ScanToStrings(producer_table, &producer_cluster_);
auto consumer_results = ScanToStrings(consumer_table, &consumer_cluster_);
if (PQntuples(producer_results.get()) != PQntuples(consumer_results.get())) {
Expand All @@ -473,7 +473,7 @@ class TwoDCYsqlTest : public TwoDCTestBase, public testing::WithParamInterface<T
}

Status VerifyNumRecords(const YBTableName& table, Cluster* cluster, int expected_size) {
return LoggedWaitFor([=]() -> Result<bool> {
return LoggedWaitFor([this, table, cluster, expected_size]() -> Result<bool> {
auto results = ScanToStrings(table, cluster);
return PQntuples(results.get()) == expected_size;
}, MonoDelta::FromSeconds(kRpcTimeout), "Verify number of records");
Expand Down
2 changes: 1 addition & 1 deletion ent/src/yb/tools/yb-admin-test_ent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class AdminCliTest : public client::KeyValueTableTest<MiniCluster> {

CHECKED_STATUS WaitForRestoreSnapshot() {
return WaitFor([this]() -> Result<bool> {
auto document = VERIFY_RESULT(RunAdminToolCommandJson("list_snapshot_restorations"));
const auto document = VERIFY_RESULT(RunAdminToolCommandJson("list_snapshot_restorations"));
auto it = document.FindMember("restorations");
if (it == document.MemberEnd()) {
LOG(INFO) << "No restorations";
Expand Down
4 changes: 2 additions & 2 deletions ent/src/yb/tserver/cdc_poller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ void CDCPoller::DoPoll() {
nullptr, /* RemoteTablet: will get this from 'req' */
producer_client_->client.get(),
&req,
[=](const Status &status, cdc::GetChangesResponsePB &&new_resp) {
auto retained = rpcs->Unregister(&poll_handle_);
[this](const Status &status, cdc::GetChangesResponsePB &&new_resp) {
auto retained = rpcs_->Unregister(&poll_handle_);
auto resp = std::make_shared<cdc::GetChangesResponsePB>(std::move(new_resp));
WARN_NOT_OK(thread_pool_->SubmitFunc(std::bind(&CDCPoller::HandlePoll, this,
status, resp)),
Expand Down
2 changes: 1 addition & 1 deletion src/yb/client/ql-tablet-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ class QLTabletTest : public QLDmlTestBase<MiniCluster> {

Status WaitForTableCreation(const YBTableName& table_name,
master::IsCreateTableDoneResponsePB *resp) {
return LoggedWaitFor([=]() -> Result<bool> {
return LoggedWaitFor([this, table_name, resp]() -> Result<bool> {
master::IsCreateTableDoneRequestPB req;
req.mutable_table()->set_table_name(table_name.table_name());
req.mutable_table()->mutable_namespace_()->set_name(table_name.namespace_name());
Expand Down
2 changes: 1 addition & 1 deletion src/yb/docdb/cql_operation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ CHECKED_STATUS FindMemberForIndex(const QLColumnValuePB& column_value,

const auto& member = column_value.json_args(index).operand().value().string_value().c_str();
*memberit = document->FindMember(member);
if (*memberit == document->MemberEnd()) {
if (memberit->operator==(document->MemberEnd())) {
return STATUS_SUBSTITUTE(QLError, "Could not find member: ", member);
}
} else {
Expand Down
17 changes: 8 additions & 9 deletions src/yb/gutil/stl_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -856,8 +856,7 @@ BinaryComposeBinary<F, G1, G2> BinaryCompose2(F f, G1 g1, G2 g2) {
template <typename T, typename Alloc = std::allocator<T> >
class STLCountingAllocator : public Alloc {
public:
typedef typename Alloc::pointer pointer;
typedef typename Alloc::size_type size_type;
using size_type = typename Alloc::size_type;

STLCountingAllocator() : bytes_used_(NULL) { }
explicit STLCountingAllocator(int64* b) : bytes_used_(b) {}
Expand All @@ -869,23 +868,23 @@ class STLCountingAllocator : public Alloc {
bytes_used_(x.bytes_used()) {
}

pointer allocate(size_type n, std::allocator<void>::const_pointer hint = 0) {
T* allocate(size_type n) {
assert(bytes_used_ != NULL);
*bytes_used_ += n * sizeof(T);
return Alloc::allocate(n, hint);
return Alloc::allocate(n);
}

void deallocate(pointer p, size_type n) {
void deallocate(T* p, size_type n) {
Alloc::deallocate(p, n);
assert(bytes_used_ != NULL);
*bytes_used_ -= n * sizeof(T);
}

// Rebind allows an allocator<T> to be used for a different type
template <class U> struct rebind {
typedef STLCountingAllocator<U,
typename Alloc::template
rebind<U>::other> other;
template <class U>
struct rebind {
using other = STLCountingAllocator<
U, typename std::allocator_traits<Alloc>::template rebind_alloc<U>>;
};

int64* bytes_used() const { return bytes_used_; }
Expand Down
4 changes: 2 additions & 2 deletions src/yb/integration-tests/external_mini_cluster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1885,13 +1885,13 @@ struct GlobalLogTailerState {

class ExternalDaemon::LogTailerThread {
public:
LogTailerThread(const string line_prefix,
LogTailerThread(const std::string& line_prefix,
const int child_fd,
ostream* const out)
: id_(global_state()->next_log_tailer_id.fetch_add(1)),
stopped_(CreateStoppedFlagForId(id_)),
thread_desc_(Substitute("log tailer thread for prefix $0", line_prefix)),
thread_([=] {
thread_([this, line_prefix, child_fd, out] {
VLOG(1) << "Starting " << thread_desc_;
FILE* const fp = fdopen(child_fd, "rb");
char buf[65536];
Expand Down
2 changes: 1 addition & 1 deletion src/yb/integration-tests/ts_itest-base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ itest::TServerDetails* TabletServerIntegrationTestBase::GetLeaderReplicaOrNull(
replicas_copy.push_back((*range.first).second);
}

std::shuffle(replicas_copy.begin(), replicas_copy.end(), yb::ThreadLocalRandom());
std::shuffle(replicas_copy.begin(), replicas_copy.end(), ThreadLocalRandom());
for (itest::TServerDetails* replica : replicas_copy) {
if (GetReplicaStatusAndCheckIfLeader(replica, tablet_id,
MonoDelta::FromMilliseconds(100)).ok()) {
Expand Down
6 changes: 3 additions & 3 deletions src/yb/master/master_service_base-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void MasterServiceBase::HandleIn(
int line_number,
const char* function_name,
HoldCatalogLock hold_catalog_lock) {
HandleOnLeader(req, resp, rpc, [=]() -> Status {
HandleOnLeader(req, resp, rpc, [this, resp, f]() -> Status {
return (handler(static_cast<HandlerType*>(nullptr))->*f)(resp); },
file_name, line_number, function_name, hold_catalog_lock);
}
Expand All @@ -127,7 +127,7 @@ void MasterServiceBase::HandleIn(
HoldCatalogLock hold_catalog_lock) {
LongOperationTracker long_operation_tracker("HandleIn", std::chrono::seconds(10));

HandleOnLeader(req, resp, rpc, [=]() -> Status {
HandleOnLeader(req, resp, rpc, [this, req, resp, f]() -> Status {
return (handler(static_cast<HandlerType*>(nullptr))->*f)(req, resp); },
file_name, line_number, function_name, hold_catalog_lock);
}
Expand All @@ -142,7 +142,7 @@ void MasterServiceBase::HandleIn(
int line_number,
const char* function_name,
HoldCatalogLock hold_catalog_lock) {
HandleOnLeader(req, resp, rpc, [=]() -> Status {
HandleOnLeader(req, resp, rpc, [this, req, resp, f, rpc]() -> Status {
return (handler(static_cast<HandlerType*>(nullptr))->*f)(req, resp, rpc); },
file_name, line_number, function_name, hold_catalog_lock);
}
Expand Down
4 changes: 3 additions & 1 deletion src/yb/rocksdb/ldb_tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
// or implied. See the License for the specific language governing permissions and limitations
// under the License.
//
#ifndef ROCKSDB_LITE

#pragma once

#ifndef ROCKSDB_LITE
#include <string>
#include <vector>
#include "yb/rocksdb/db.h"
Expand Down
4 changes: 2 additions & 2 deletions src/yb/rocksdb/tools/db_repl_stress.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static void DataPumpThreadBody(void* arg) {
struct ReplicationThread {
std::atomic<bool> stop;
DB* db;
volatile size_t no_read;
std::atomic<size_t> no_read;
};

static void ReplicationThreadBody(void* arg) {
Expand Down Expand Up @@ -154,7 +154,7 @@ int db_repl_stress(int argc, const char** argv) {
stderr,
"No. of Record's written and read not same\nRead : %" ROCKSDB_PRIszt
" Written : %" ROCKSDB_PRIszt "\n",
replThread.no_read, dataPump.no_records);
replThread.no_read.load(), dataPump.no_records);
exit(1);
}
fprintf(stderr, "Successful!\n");
Expand Down
5 changes: 3 additions & 2 deletions src/yb/rocksdb/util/concurrent_arena.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ConcurrentArena : public Allocator {

char* Allocate(size_t bytes) override {
return AllocateImpl(bytes, false /*force_arena*/,
[=]() { return arena_.Allocate(bytes); });
[this, bytes]() { return arena_.Allocate(bytes); });
}

char* AllocateAligned(size_t bytes, size_t huge_page_size = 0,
Expand All @@ -78,7 +78,8 @@ class ConcurrentArena : public Allocator {
assert(rounded_up >= bytes && rounded_up < bytes + sizeof(void*) &&
(rounded_up % sizeof(void*)) == 0);

return AllocateImpl(rounded_up, huge_page_size != 0 /*force_arena*/, [=]() {
return AllocateImpl(rounded_up, huge_page_size != 0 /*force_arena*/,
[this, rounded_up, huge_page_size, logger]() {
return arena_.AllocateAligned(rounded_up, huge_page_size, logger);
});
}
Expand Down
3 changes: 2 additions & 1 deletion src/yb/rocksdb/utilities/redis/redis_list_exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
*
*/

#ifndef ROCKSDB_LITE
#pragma once

#ifndef ROCKSDB_LITE
#include <exception>

namespace rocksdb {
Expand Down
1 change: 0 additions & 1 deletion src/yb/rpc/rpc-test-base.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ class GenericCalculatorService : public ServiceIf {
};

struct MessengerOptions {
MessengerOptions() = delete;
int n_reactors;
std::chrono::milliseconds keep_alive_timeout;
int num_connections_to_server = -1;
Expand Down
2 changes: 1 addition & 1 deletion src/yb/tablet/tablet.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class Tablet : public AbstractTablet, public TransactionIntentApplier {
// Returns true if it was the first call to StartShutdown.
bool StartShutdown();
bool IsShutdownRequested() const {
return shutdown_requested_.load(std::memory_order::memory_order_acquire);
return shutdown_requested_.load(std::memory_order::acquire);
}

// Complete the shutdown of this tablet. This includes shutdown of internal structures such as:
Expand Down
2 changes: 1 addition & 1 deletion src/yb/tools/admin-test-base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Result<const rapidjson::Value&> Get(const rapidjson::Value& value, const char* n

Result<rapidjson::Value&> Get(rapidjson::Value* value, const char* name) {
auto it = value->FindMember(name);
if (it == value->MemberEnd()) {
if (it.operator==(value->MemberEnd())) {
return STATUS_FORMAT(InvalidArgument, "Missing $0 field", name);
}
return it->value;
Expand Down
2 changes: 1 addition & 1 deletion src/yb/util/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ AtomicUniquePtr<T> MakeAtomicUniquePtr(Args&&... args) {
template <class T>
T GetAtomicFlag(T* flag) {
std::atomic<T>& atomic_flag = *pointer_cast<std::atomic<T>*>(flag);
return atomic_flag.load(std::memory_order::memory_order_relaxed);
return atomic_flag.load(std::memory_order::relaxed);
}

template <class U, class T>
Expand Down
14 changes: 7 additions & 7 deletions src/yb/util/lockfree-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,14 @@ template <class T, class Allocator = std::allocator<T>>
struct BlockAllocator {
template <class U>
struct rebind {
typedef BlockAllocator<U, typename Allocator::template rebind<U>::other> other;
using other = BlockAllocator<
U, typename std::allocator_traits<Allocator>::template rebind_alloc<U>>;
};

typedef typename Allocator::value_type value_type;
typedef typename Allocator::pointer pointer;
typedef typename Allocator::size_type size_type;
using value_type = typename Allocator::value_type;
using size_type = typename Allocator::size_type;

void deallocate(pointer p, size_type n) {
void deallocate(T* p, size_type n) {
BlockEntry* entry = OBJECT_FROM_MEMBER(BlockEntry, value, p);
if (entry->counter->fetch_sub(1, std::memory_order_acq_rel) == 1) {
Block* block = OBJECT_FROM_MEMBER(Block, counter, entry->counter);
Expand Down Expand Up @@ -190,7 +190,7 @@ struct BlockAllocator {

static thread_local std::unique_ptr<TSS> tss_;

pointer allocate(size_type n) {
T* allocate(size_type n) {
TSS* tss = tss_.get();
if (PREDICT_FALSE(!tss)) {
tss_.reset(new TSS);
Expand All @@ -206,7 +206,7 @@ struct BlockAllocator {
return &entry.value;
}

typedef typename Allocator::template rebind<Block>::other Impl;
using Impl = typename std::allocator_traits<Allocator>::template rebind_alloc<Block>;
Impl impl_;
};

Expand Down
13 changes: 6 additions & 7 deletions src/yb/util/mem_tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,7 @@ class MemTracker : public std::enable_shared_from_this<MemTracker> {
template<typename T, typename Alloc = std::allocator<T> >
class MemTrackerAllocator : public Alloc {
public:
typedef typename Alloc::pointer pointer;
typedef typename Alloc::const_pointer const_pointer;
typedef typename Alloc::size_type size_type;
using size_type = typename Alloc::size_type;

explicit MemTrackerAllocator(std::shared_ptr<MemTracker> mem_tracker)
: mem_tracker_(std::move(mem_tracker)) {}
Expand All @@ -486,23 +484,24 @@ class MemTrackerAllocator : public Alloc {
~MemTrackerAllocator() {
}

pointer allocate(size_type n, const_pointer hint = 0) {
T* allocate(size_type n) {
// Ideally we'd use TryConsume() here to enforce the tracker's limit.
// However, that means throwing bad_alloc if the limit is exceeded, and
// it's not clear that the rest of YB can handle that.
mem_tracker_->Consume(n * sizeof(T));
return Alloc::allocate(n, hint);
return Alloc::allocate(n);
}

void deallocate(pointer p, size_type n) {
void deallocate(T* p, size_type n) {
Alloc::deallocate(p, n);
mem_tracker_->Release(n * sizeof(T));
}

// This allows an allocator<T> to be used for a different type.
template <class U>
struct rebind {
typedef MemTrackerAllocator<U, typename Alloc::template rebind<U>::other> other;
using other = MemTrackerAllocator<
U, typename std::allocator_traits<Alloc>::template rebind_alloc<U>>;
};

const std::shared_ptr<MemTracker>& mem_tracker() const { return mem_tracker_; }
Expand Down
2 changes: 1 addition & 1 deletion src/yb/util/memory/arena.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ class ArenaAllocatorBase {
CHECK_NOTNULL(arena_);
}

pointer allocate(size_type n, std::allocator<void>::const_pointer /*hint*/ = 0) {
pointer allocate(size_type n) {
return reinterpret_cast<T*>(arena_->AllocateBytesAligned(n * sizeof(T), alignof(T)));
}

Expand Down
Loading

0 comments on commit f79548c

Please sign in to comment.