Skip to content

Commit a20a7d0

Browse files
authored
[Feature] upgrade c++17 to c++20 (StarRocks#26432)
upgrade to c++20 to benefit from std::coroutine --------- Signed-off-by: Zhuhe Fang <[email protected]>
1 parent 6f9b36b commit a20a7d0

32 files changed

+78
-69
lines changed

.clang-tidy

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ Checks: >
55
modernize-concat-nested-namespaces,
66
modernize-deprecated-headers,
77
modernize-deprecated-ios-base-aliases,
8-
modernize-loop-convert,
98
modernize-make-shared,
109
modernize-make-unique,
1110
modernize-pass-by-value,

be/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} $ENV{STARROCKS_CXX_LINKER_
511511
# -fno-omit-frame-pointers: Keep frame pointer for functions in register
512512
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wall -Wno-sign-compare -Wno-unknown-pragmas -pthread -Wno-register")
513513
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wno-strict-aliasing -fno-omit-frame-pointer")
514-
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -std=gnu++17 -D__STDC_FORMAT_MACROS")
514+
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -std=gnu++20 -D__STDC_FORMAT_MACROS")
515515
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wno-deprecated -Wno-vla -Wno-comment")
516516

517517
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
@@ -522,7 +522,7 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
522522
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wno-documentation-unknown-command -Wno-old-style-cast")
523523
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wno-c++20-designator -Wno-mismatched-tags")
524524
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "14.0.0")
525-
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wno-bitwise-instead-of-logical")
525+
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wno-bitwise-instead-of-logical -Wno-inconsistent-missing-override -Wno-ambiguous-reversed-operator")
526526
endif()
527527
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "16.0.0")
528528
# ignore warning from apache-orc

be/src/column/column_hash.h

+7-4
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,12 @@ class SliceHashWithSeed<PhmapSeed2> {
227227

228228
#if defined(__SSE2__) && !defined(ADDRESS_SANITIZER)
229229

230-
// NOTE: This function will access 15 excessive bytes after p1 and p2.
230+
// NOTE: This function will access 15 excessive bytes after p1 and p2, which should has padding bytes when allocating
231+
// memory. if withoud pad, please use memequal.
231232
// NOTE: typename T must be uint8_t or int8_t
232233
template <typename T>
233-
typename std::enable_if<sizeof(T) == 1, bool>::type memequal(const T* p1, size_t size1, const T* p2, size_t size2) {
234+
typename std::enable_if<sizeof(T) == 1, bool>::type memequal_padded(const T* p1, size_t size1, const T* p2,
235+
size_t size2) {
234236
if (size1 != size2) {
235237
return false;
236238
}
@@ -249,15 +251,16 @@ typename std::enable_if<sizeof(T) == 1, bool>::type memequal(const T* p1, size_t
249251
#else
250252

251253
template <typename T>
252-
typename std::enable_if<sizeof(T) == 1, bool>::type memequal(const T* p1, size_t size1, const T* p2, size_t size2) {
254+
typename std::enable_if<sizeof(T) == 1, bool>::type memequal_padded(const T* p1, size_t size1, const T* p2,
255+
size_t size2) {
253256
return (size1 == size2) && (memcmp(p1, p2, size1) == 0);
254257
}
255258
#endif
256259

257260
static constexpr uint16_t SLICE_MEMEQUAL_OVERFLOW_PADDING = 15;
258261
class SliceEqual {
259262
public:
260-
bool operator()(const Slice& x, const Slice& y) const { return memequal(x.data, x.size, y.data, y.size); }
263+
bool operator()(const Slice& x, const Slice& y) const { return memequal_padded(x.data, x.size, y.data, y.size); }
261264
};
262265

263266
class SliceNormalEqual {

be/src/column/column_pool.h

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "common/type_list.h"
3131
#include "gutil/dynamic_annotations.h"
3232
#include "runtime/current_thread.h"
33+
#include "util/json.h"
3334

3435
namespace starrocks {
3536

be/src/column/hash_set.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class EqualOnSliceWithHash {
5050
bool operator()(const SliceWithHash& x, const SliceWithHash& y) const {
5151
// by comparing hash value first, we can avoid comparing real data
5252
// which may touch another memory area and has bad cache locality.
53-
return x.hash == y.hash && memequal(x.data, x.size, y.data, y.size);
53+
return x.hash == y.hash && memequal_padded(x.data, x.size, y.data, y.size);
5454
}
5555
};
5656

@@ -74,7 +74,7 @@ class TEqualOnSliceWithHash {
7474
bool operator()(const TSliceWithHash<seed>& x, const TSliceWithHash<seed>& y) const {
7575
// by comparing hash value first, we can avoid comparing real data
7676
// which may touch another memory area and has bad cache locality.
77-
return x.hash == y.hash && memequal(x.data, x.size, y.data, y.size);
77+
return x.hash == y.hash && memequal_padded(x.data, x.size, y.data, y.size);
7878
}
7979
};
8080

be/src/connector/binlog_connector.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Status BinlogDataSource::get_next(RuntimeState* state, ChunkPtr* chunk) {
9090
return _mock_chunk_test(chunk);
9191
}
9292
#endif
93-
if (_need_seek_binlog.load(std::memory_order::memory_order_acquire)) {
93+
if (_need_seek_binlog.load(std::memory_order::acquire)) {
9494
if (!_is_stream_pipeline) {
9595
RETURN_IF_ERROR(_prepare_non_stream_pipeline());
9696
}

be/src/exec/except_hash_set.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class ExceptSliceFlag {
3838

3939
struct ExceptSliceFlagEqual {
4040
bool operator()(const ExceptSliceFlag& x, const ExceptSliceFlag& y) const {
41-
return memequal(x.slice.data, x.slice.size, y.slice.data, y.slice.size);
41+
return memequal_padded(x.slice.data, x.slice.size, y.slice.data, y.slice.size);
4242
}
4343
};
4444

be/src/exec/intersect_hash_set.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class IntersectSliceFlag {
3636

3737
struct IntersectSliceFlagEqual {
3838
bool operator()(const IntersectSliceFlag& x, const IntersectSliceFlag& y) const {
39-
return memequal(x.slice.data, x.slice.size, y.slice.data, y.slice.size);
39+
return memequal_padded(x.slice.data, x.slice.size, y.slice.data, y.slice.size);
4040
}
4141
};
4242

be/src/exec/schema_scanner/schema_be_compactions_scanner.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Status SchemaBeCompactionsScanner::start(RuntimeState* state) {
4545
auto o_id = get_backend_id();
4646
_be_id = o_id.has_value() ? o_id.value() : -1;
4747
_infos.clear();
48-
CompactionInfo info;
48+
CompactionInformation info;
4949
auto compaction_manager = StorageEngine::instance()->compaction_manager();
5050
info.candidates_num = compaction_manager->candidates_size();
5151
info.base_compaction_concurrency = compaction_manager->base_compaction_concurrency();

be/src/exec/schema_scanner/schema_be_compactions_scanner.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
namespace starrocks {
2323

24-
struct CompactionInfo {
24+
struct CompactionInformation {
2525
int64_t candidates_num = 0;
2626
int64_t base_compaction_concurrency = 0;
2727
int64_t cumulative_compaction_concurrency = 0;
@@ -43,7 +43,7 @@ class SchemaBeCompactionsScanner : public SchemaScanner {
4343
Status fill_chunk(ChunkPtr* chunk);
4444

4545
int64_t _be_id{0};
46-
std::vector<CompactionInfo> _infos;
46+
std::vector<CompactionInformation> _infos;
4747
size_t _cur_idx{0};
4848
static SchemaScanner::ColumnDesc _s_columns[];
4949
};

be/src/exec/schema_scanner/schema_load_tracking_logs_scanner.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <climits>
1818

1919
#include "exec/schema_scanner/schema_helper.h"
20+
#include "gutil/strings/substitute.h"
2021
#include "http/http_client.h"
2122
#include "runtime/runtime_state.h"
2223
#include "runtime/string_value.h"
@@ -75,7 +76,7 @@ Status SchemaLoadTrackingLogsScanner::fill_chunk(ChunkPtr* chunk) {
7576
auto& info = _result.trackingLoads[_cur_idx];
7677
for (const auto& [slot_id, index] : slot_id_to_index_map) {
7778
if (slot_id < 1 || slot_id > 5) {
78-
return Status::InternalError(fmt::format("invalid slot id:{}}", slot_id));
79+
return Status::InternalError(strings::Substitute("invalid slot id: $0", slot_id));
7980
}
8081
ColumnPtr column = (*chunk)->get_column_by_slot_id(slot_id);
8182
switch (slot_id) {

be/src/exec/schema_scanner/schema_routine_load_jobs_scanner.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "exec/schema_scanner/schema_routine_load_jobs_scanner.h"
1616

1717
#include "exec/schema_scanner/schema_helper.h"
18+
#include "gutil/strings/substitute.h"
1819
#include "http/http_client.h"
1920
#include "runtime/runtime_state.h"
2021
#include "runtime/string_value.h"
@@ -79,7 +80,7 @@ Status SchemaRoutineLoadJobsScanner::fill_chunk(ChunkPtr* chunk) {
7980
auto& info = _result.loads[_cur_idx];
8081
for (const auto& [slot_id, index] : slot_id_to_index_map) {
8182
if (slot_id < 1 || slot_id > 19) {
82-
return Status::InternalError(fmt::format("invalid slot id:{}}", slot_id));
83+
return Status::InternalError(strings::Substitute("invalid slot id: $0", slot_id));
8384
}
8485
ColumnPtr column = (*chunk)->get_column_by_slot_id(slot_id);
8586
switch (slot_id) {

be/src/exec/spill/spiller.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ Status PartitionedSpillerWriter::flush(RuntimeState* state, bool is_final_flush,
273273
DCHECK_EQ(_running_flush_tasks, 0);
274274
_running_flush_tasks++;
275275

276-
auto task = [this, state, guard = guard, splitting_partitions = std::move(splitting_partitions),
276+
auto task = [this, guard = guard, splitting_partitions = std::move(splitting_partitions),
277277
spilling_partitions = std::move(spilling_partitions), trace = TraceInfo(state)]() {
278278
SCOPED_SET_TRACE_INFO({}, trace.query_id, trace.fragment_id);
279279
RETURN_IF(!guard.scoped_begin(), Status::Cancelled("cancelled"));

be/src/exprs/cast_expr.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1450,7 +1450,7 @@ StatusOr<ColumnPtr> MustNullExpr::evaluate_checked(ExprContext* context, Chunk*
14501450
// only null
14511451
auto column = ColumnHelper::create_column(_type, true);
14521452
column->append_nulls(1);
1453-
auto only_null = std::move(ConstColumn::create(column, 1));
1453+
auto only_null = ConstColumn::create(column, 1);
14541454
if (ptr != nullptr) {
14551455
only_null->resize(ptr->num_rows());
14561456
}

be/src/formats/orc/apache-orc/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ if (NOT MSVC)
115115
endif ()
116116
message(STATUS "compiler ${CMAKE_CXX_COMPILER_ID} version ${CMAKE_CXX_COMPILER_VERSION}")
117117
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
118-
set (CMAKE_CXX_STANDARD 17)
118+
set (CMAKE_CXX_STANDARD 20)
119119
set (WARN_FLAGS "-Weverything -Wno-c++98-compat -Wno-missing-prototypes")
120120
set (WARN_FLAGS "${WARN_FLAGS} -Wno-c++98-compat-pedantic -Wno-padded")
121121
set (WARN_FLAGS "${WARN_FLAGS} -Wno-covered-switch-default")
@@ -138,7 +138,7 @@ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
138138
CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.7")
139139
set (CXX11_FLAGS "-std=c++0x")
140140
else ()
141-
set (CMAKE_CXX_STANDARD 17)
141+
set (CMAKE_CXX_STANDARD 20)
142142
endif ()
143143
elseif (MSVC)
144144
add_definitions (-D_SCL_SECURE_NO_WARNINGS)

be/src/fs/fs.h

-2
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ struct SequentialFileOptions {
9090
};
9191

9292
struct RandomAccessFileOptions {
93-
RandomAccessFileOptions() = default;
94-
9593
// Don't cache remote file locally on read requests.
9694
// This options can be ignored if the underlying filesystem does not support local cache.
9795
bool skip_fill_local_cache = false;

be/src/fs/fs_s3.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static Status to_status(Aws::S3::S3Errors error, const std::string& msg) {
6060
case Aws::S3::S3Errors::NO_SUCH_UPLOAD:
6161
return Status::NotFound(fmt::format("no such upload: {}", msg));
6262
default:
63-
return Status::InternalError(fmt::format(msg));
63+
return Status::InternalError(msg);
6464
}
6565
}
6666

be/src/fs/fs_starlet.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,9 @@ class StarletFileSystem : public FileSystem {
250250
if (!fs_st.ok()) {
251251
return to_status(fs_st.status());
252252
}
253-
254-
auto file_st = (*fs_st)->open(pair.first, ReadOptions{.skip_fill_local_cache = opts.skip_fill_local_cache});
253+
auto opt = ReadOptions();
254+
opt.skip_fill_local_cache = opts.skip_fill_local_cache;
255+
auto file_st = (*fs_st)->open(pair.first, std::move(opt));
255256

256257
if (!file_st.ok()) {
257258
return to_status(file_st.status());
@@ -274,7 +275,9 @@ class StarletFileSystem : public FileSystem {
274275
if (!fs_st.ok()) {
275276
return to_status(fs_st.status());
276277
}
277-
auto file_st = (*fs_st)->open(pair.first, ReadOptions{.skip_fill_local_cache = opts.skip_fill_local_cache});
278+
auto opt = ReadOptions();
279+
opt.skip_fill_local_cache = opts.skip_fill_local_cache;
280+
auto file_st = (*fs_st)->open(pair.first, std::move(opt));
278281

279282
if (!file_st.ok()) {
280283
return to_status(file_st.status());

be/src/gutil/stl_util.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -756,8 +756,10 @@ BinaryComposeBinary<F, G1, G2> BinaryCompose2(F f, G1 g1, G2 g2) {
756756
template <typename T, typename Alloc = std::allocator<T> >
757757
class STLCountingAllocator : public Alloc {
758758
public:
759-
typedef typename Alloc::pointer pointer;
760-
typedef typename Alloc::size_type size_type;
759+
using AllocatorTraits = std::allocator_traits<Alloc>;
760+
761+
typedef typename AllocatorTraits::pointer pointer;
762+
typedef typename AllocatorTraits::size_type size_type;
761763

762764
STLCountingAllocator() {}
763765
STLCountingAllocator(int64* b) : bytes_used_(b) {} // TODO(user): explicit?
@@ -766,10 +768,10 @@ class STLCountingAllocator : public Alloc {
766768
template <class U>
767769
STLCountingAllocator(const STLCountingAllocator<U>& x) : Alloc(x), bytes_used_(x.bytes_used()) {}
768770

769-
pointer allocate(size_type n, std::allocator<void>::const_pointer hint = nullptr) {
771+
pointer allocate(size_type n) {
770772
assert(bytes_used_ != NULL);
771773
*bytes_used_ += n * sizeof(T);
772-
return Alloc::allocate(n, hint);
774+
return Alloc::allocate(n);
773775
}
774776

775777
void deallocate(pointer p, size_type n) {

be/src/storage/persistent_index.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ struct StringHasher2 {
874874
class EqualOnStringWithHash {
875875
public:
876876
bool operator()(const std::string& lhs, const std::string& rhs) const {
877-
return memequal(lhs.data(), lhs.size() - kIndexValueSize, rhs.data(), rhs.size() - kIndexValueSize);
877+
return memequal_padded(lhs.data(), lhs.size() - kIndexValueSize, rhs.data(), rhs.size() - kIndexValueSize);
878878
}
879879
};
880880

be/src/util/download_util.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <boost/algorithm/string/predicate.hpp>
1818

1919
#include "fmt/format.h"
20+
#include "gutil/strings/substitute.h"
2021
#include "http/http_client.h"
2122
#include "util/defer_op.h"
2223
#include "util/md5.h"
@@ -47,7 +48,8 @@ Status DownloadUtil::download(const std::string& url, const std::string& tmp_fil
4748
auto res = fwrite(data, length, 1, fp);
4849
if (res != 1) {
4950
LOG(ERROR) << fmt::format("fail to write data to file {}, error={}", tmp_file, ferror(fp));
50-
status = Status::InternalError(fmt::format("file to write data when downloading file from {}" + url));
51+
status =
52+
Status::InternalError(strings::Substitute("file to write data when downloading file from $0", url));
5153
return false;
5254
}
5355
return true;

be/src/util/memcmp.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,11 @@ inline int compare(T lhs, T rhs) {
5656
}
5757
}
5858

59-
// mem_equal is used to optimize the comparastion between the two strings.
59+
// memequal is used to optimize the comparison between the two strings.
6060
// 1. If the length is equal and larger than 16, use SSE4.1
6161
// 2. If the length is small than 16, convert the address to int16/int32/int64
62-
// to comparasion
62+
// to comparison
63+
// so it does not need to consider extra padding bytes for SIMD, which is required by memequal_padded().
6364
// TODO: If know the size in advance, call the function by constant parameter
6465
// like memequal(p1, 10, p2, 10) is efficient
6566

0 commit comments

Comments
 (0)