Skip to content

Commit

Permalink
[Fix](compile) Fix clang-18 and libc++ compile problems (apache#34715)
Browse files Browse the repository at this point in the history
## Proposed changes

Issue Number: close #xxx

Fix clang-18 and libc++ compile problems

unique() of shared_ptr is deprecated in clang-18, it's not a strict
implementation, can use use_count() instead.
And fixed some other compie errors in both using clang-18 and libc++.

## Further comments

If this is a relatively large or complex change, kick off the discussion
at [[email protected]](mailto:[email protected]) by explaining why
you chose the solution you did and what alternatives you considered,
etc...
  • Loading branch information
biohazard4321 authored Jul 31, 2024
1 parent 4b4985d commit 4f218b4
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 28 deletions.
12 changes: 7 additions & 5 deletions be/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ set(BOOST_VERSION "1.81.0")

if (NOT APPLE)
find_package(Boost ${BOOST_VERSION} REQUIRED COMPONENTS system date_time)
find_package(Boost ${BOOST_VERSION} REQUIRED COMPONENTS system container)
else()
find_package(Boost ${BOOST_VERSION} COMPONENTS system date_time)
find_package(Boost ${BOOST_VERSION} COMPONENTS system container)
Expand Down Expand Up @@ -298,12 +299,11 @@ if (COMPILER_CLANG)
-Wno-implicit-float-conversion
-Wno-implicit-int-conversion
-Wno-sign-conversion
-Wno-missing-field-initializers
-Wno-unused-const-variable
-Wno-shorten-64-to-32)
if (USE_LIBCPP)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-stdlib=libc++>)
if (NOT OS_MACOSX)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-lstdc++>)
endif()
add_definitions(-DUSE_LIBCPP)
endif()
endif ()
Expand Down Expand Up @@ -517,6 +517,7 @@ find_package(absl)
# add it here first.
set(COMMON_THIRDPARTY
Boost::date_time
Boost::container
${COMMON_THIRDPARTY}
)

Expand Down Expand Up @@ -559,7 +560,6 @@ endif()
if (OS_MACOSX)
set(COMMON_THIRDPARTY
${COMMON_THIRDPARTY}
Boost::container
bfd
iberty
intl
Expand Down Expand Up @@ -603,9 +603,11 @@ if (NOT OS_MACOSX)
${DORIS_DEPENDENCIES}
-static-libstdc++
-static-libgcc
-lstdc++fs
-lresolv
)
if (NOT (USE_LIBCPP AND COMPILER_CLANG))
set(DORIS_LINK_LIBS ${DORIS_LINK_LIBS} -lstdc++fs)
endif()
else()
set(DORIS_LINK_LIBS
${DORIS_LINK_LIBS}
Expand Down
16 changes: 8 additions & 8 deletions be/src/cloud/cloud_tablet_hotspot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,20 @@ void TabletHotspot::get_top_n_hot_partition(std::vector<THotTableMessage>* hot_t
hot_partition.qpd = std::max(hot_partition.qpd, counter->qpd());
hot_partition.qpw = std::max(hot_partition.qpw, counter->qpw());
hot_partition.last_access_time =
std::max(hot_partition.last_access_time,
std::chrono::duration_cast<std::chrono::seconds>(
counter->last_access_time.time_since_epoch())
.count());
std::max<int64_t>(hot_partition.last_access_time,
std::chrono::duration_cast<std::chrono::seconds>(
counter->last_access_time.time_since_epoch())
.count());
} else if (counter->qpw() != 0) {
auto& hot_partition = week_hot_partitions[std::make_pair(
counter->table_id, counter->index_id)][counter->partition_id];
hot_partition.qpd = 0;
hot_partition.qpw = std::max(hot_partition.qpw, counter->qpw());
hot_partition.last_access_time =
std::max(hot_partition.last_access_time,
std::chrono::duration_cast<std::chrono::seconds>(
counter->last_access_time.time_since_epoch())
.count());
std::max<int64_t>(hot_partition.last_access_time,
std::chrono::duration_cast<std::chrono::seconds>(
counter->last_access_time.time_since_epoch())
.count());
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion be/src/io/cache/block_file_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void BlockFileCache::remove_query_context(const TUniqueId& query_id) {
std::lock_guard cache_lock(_mutex);
const auto& query_iter = _query_map.find(query_id);

if (query_iter != _query_map.end() && query_iter->second.unique()) {
if (query_iter != _query_map.end() && query_iter->second.use_count() <= 1) {
_query_map.erase(query_iter);
}
}
Expand Down
2 changes: 2 additions & 0 deletions be/test/util/threadpool_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ TEST_F(ThreadPoolTest, TestDeadlocks) {
const char* death_msg = "doris::ThreadPool::check_not_pool_thread_unlocked()";
#elif defined(__APPLE__)
const char* death_msg = "pthread_start";
#elif defined(__clang__) && defined(USE_LIBCPP)
const char* death_msg = "doris::ThreadPool::check_not_pool_thread_unlocked()";
#else
const char* death_msg =
"_ZNSt5_BindIFMN5doris10ThreadPoolEFvvEPS1_EE6__callIvJEJLm0EEEET_OSt5tupleIJDpT0_"
Expand Down
6 changes: 4 additions & 2 deletions cloud/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ if (NOT CUSTUM_LINKER_COMMAND STREQUAL "ld")
endif()

if (USE_LIBCPP AND COMPILER_CLANG)
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -stdlib=libc++ -lstdc++")
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -stdlib=libc++")
add_definitions(-DUSE_LIBCPP)
endif()

Expand Down Expand Up @@ -335,11 +335,13 @@ set(DORIS_LINK_LIBS ${DORIS_LINK_LIBS}
${DORIS_DEPENDENCIES}
-static-libstdc++
-static-libgcc
-lstdc++fs
-lresolv
-L${DORIS_JAVA_HOME}/lib/server
-ljvm
)
if (NOT (USE_LIBCPP AND COMPILER_CLANG))
set(DORIS_LINK_LIBS ${DORIS_LINK_LIBS} -lstdc++fs)
endif()

if (USE_JEMALLOC)
set(MALLOCLIB jemalloc)
Expand Down
4 changes: 2 additions & 2 deletions cloud/src/common/encryption_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,8 @@ static int generate_random_root_key(TxnKv* txn_kv, KmsClient* kms_client, std::s

// 3. otherwise, generate a random data key in memory
std::mt19937 rnd(time(nullptr));
std::uniform_int_distribution<char> dist(std::numeric_limits<char>::min(),
std::numeric_limits<char>::max());
std::uniform_int_distribution<short> dist(std::numeric_limits<char>::min(),
std::numeric_limits<char>::max());
std::string root_key_plaintext(32, '0');
for (char& i : root_key_plaintext) {
i = (char)dist(rnd);
Expand Down
5 changes: 3 additions & 2 deletions cloud/src/recycler/checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ int Checker::start() {
long enqueue_time_s = 0;
{
std::unique_lock lock(mtx_);
pending_instance_cond_.wait(
lock, [&]() { return !pending_instance_queue_.empty() || stopped(); });
pending_instance_cond_.wait(lock, [&]() -> bool {
return !pending_instance_queue_.empty() || stopped();
});
if (stopped()) {
return;
}
Expand Down
3 changes: 3 additions & 0 deletions cloud/src/recycler/checker.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

#pragma once

#if defined(USE_LIBCPP) && _LIBCPP_ABI_VERSION <= 1
#define _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE
#endif
#include <atomic>
#include <condition_variable>
#include <deque>
Expand Down
4 changes: 4 additions & 0 deletions cloud/src/recycler/s3_accessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,11 @@ int GcsAccessor::delete_prefix_impl(const std::string& path_prefix, int64_t expi

int GcsAccessor::delete_files(const std::vector<std::string>& paths) {
std::vector<int> delete_rets(paths.size());
#ifdef USE_LIBCPP
std::transform(paths.begin(), paths.end(), delete_rets.begin(),
#else
std::transform(std::execution::par, paths.begin(), paths.end(), delete_rets.begin(),
#endif
[this](const std::string& path) {
LOG_INFO("delete file").tag("uri", to_uri(path));
return delete_file(path);
Expand Down
4 changes: 2 additions & 2 deletions cloud/test/codec_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ TEST(CodecTest, StringCodecTest) {
std::mt19937 gen(std::random_device("/dev/urandom")());
const int max_len = (2 << 16) + 10086;
std::uniform_int_distribution<int> rd_len(0, max_len);
std::uniform_int_distribution<char> rd_char(std::numeric_limits<char>::min(),
std::numeric_limits<char>::max());
std::uniform_int_distribution<short> rd_char(std::numeric_limits<char>::min(),
std::numeric_limits<char>::max());

int ret = -1;

Expand Down
6 changes: 2 additions & 4 deletions common/cpp/s3_rate_limiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@

#if defined(__APPLE__)
#include <ctime>
#define CURRENT_TIME std::chrono::system_clock::now()
#else
#define CURRENT_TIME std::chrono::high_resolution_clock::now()
#endif
#define CURRENT_TIME std::chrono::system_clock::now()

namespace doris {
// Just 10^6.
Expand Down Expand Up @@ -154,4 +152,4 @@ S3RateLimitType string_to_s3_rate_limit_type(std::string_view value) {
}
return S3RateLimitType::UNKNOWN;
}
} // namespace doris
} // namespace doris
11 changes: 11 additions & 0 deletions run-cloud-ut.sh
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ if [[ -z "${GLIBC_COMPATIBILITY}" ]]; then
GLIBC_COMPATIBILITY=ON
fi

if [[ -z "${USE_LIBCPP}" ]]; then
if [[ "$(uname -s)" != 'Darwin' ]]; then
USE_LIBCPP='OFF'
else
USE_LIBCPP='ON'
fi
fi

if [[ -z "${USE_DWARF}" ]]; then
USE_DWARF=OFF
fi
Expand All @@ -182,6 +190,7 @@ find . -name "*.gcda" -exec rm {} \;
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DMAKE_TEST=ON \
-DGLIBC_COMPATIBILITY="${GLIBC_COMPATIBILITY}" \
-DUSE_LIBCPP="${USE_LIBCPP}" \
-DUSE_DWARF="${USE_DWARF}" \
-DUSE_MEM_TRACKER=ON \
-DUSE_JEMALLOC=OFF \
Expand Down Expand Up @@ -212,6 +221,8 @@ echo "**********************************"
echo " Running MetaService Unit Test "
echo "**********************************"

export ASAN_OPTIONS=detect_container_overflow=0

# test binary output dir
cd test
# FILTER: binary_name:gtest_filter
Expand Down
4 changes: 2 additions & 2 deletions thirdparty/build-thirdparty.sh
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ build_bzip() {
check_if_source_exist "${BZIP_SOURCE}"
cd "${TP_SOURCE_DIR}/${BZIP_SOURCE}"

make -j "${PARALLEL}" install PREFIX="${TP_INSTALL_DIR}"
make -j "${PARALLEL}" install PREFIX="${TP_INSTALL_DIR}" CFLAGS="-fPIC"
}

# lzo2
Expand Down Expand Up @@ -1744,7 +1744,7 @@ build_libuuid() {
check_if_source_exist "${LIBUUID_SOURCE}"
cd "${TP_SOURCE_DIR}/${LIBUUID_SOURCE}"
CC=gcc ./configure --prefix="${TP_INSTALL_DIR}" --disable-shared --enable-static
make -j "${PARALLEL}"
make -j "${PARALLEL}" CFLAGS="-fPIC"
make install
}

Expand Down

0 comments on commit 4f218b4

Please sign in to comment.