From 2950e992191f80c6898e5b7ca7716d1a96d8ad1e Mon Sep 17 00:00:00 2001 From: Peter Dillinger Date: Thu, 28 Aug 2025 16:59:16 -0700 Subject: [PATCH] Require C++20 (#13904) Summary: I am wanting to use std::counting_semaphore for something and the timing seems good to require C++20 support. The internets suggest: * GCC >= 10 is adequate, >= 11 preferred * Clang >= 10 is needed * Visual Studio >= 2019 is adquate And popular linux distributions look like this: * CentOS Stream 9 -> GCC 11.2 (CentOS 8 is EOL) * Ubuntu 22.04 LTS -> GCC 11.x (Ubuntu 20 just ended standard support) * Debian 12 (oldstable) -> GCC 12.2 * (Debian 11 has ended security updates, uses GCC 10.2) This required generating a new docker image based on Ubuntu 22 for CI using gcc. The existing Ubuntu 20 image works for covering appropriate clang versions (though we should maybe add a much later version as well, in the next increment of our Ubuntu 22 image; however the minimum available clang build from apt.llvm.org for Ubuntu 22 is clang 13). Update to SetDumpFilter is to quiet a mysterious gcc-13 warning-as-error. Removed --compile-no-warning-as-error from a cmake command line because cmake in the new docker image is too old for this option. Pull Request resolved: https://github.com/facebook/rocksdb/pull/13904 Test Plan: CI, one minor unit test added to verify std::counting_semaphor works Reviewed By: xingbowang Differential Revision: D81266435 Pulled By: pdillinger fbshipit-source-id: 26040eeccca7004416e29a6ff4f6ea93f2052684 --- .github/workflows/nightly.yml | 25 ++---- .github/workflows/pr-jobs.yml | 70 ++++++---------- CMakeLists.txt | 5 +- INSTALL.md | 10 +-- Makefile | 6 +- build_tools/build_detect_platform | 4 +- build_tools/ubuntu22_image/Dockerfile | 80 +++++++++++++++++++ db/db_impl/db_impl.cc | 2 - examples/Makefile | 18 ++--- include/rocksdb/advanced_options.h | 4 - include/rocksdb/compression_type.h | 2 - include/rocksdb/slice.h | 2 +- include/rocksdb/universal_compaction.h | 2 - include/rocksdb/utilities/cache_dump_load.h | 2 +- options/cf_options.h | 2 - .../public_api_changes/cplusplus20.md | 1 + util/slice_test.cc | 20 +++++ util/string_util.cc | 18 +---- utilities/cache_dump_load_impl.cc | 2 +- utilities/cache_dump_load_impl.h | 2 +- 20 files changed, 158 insertions(+), 119 deletions(-) create mode 100644 build_tools/ubuntu22_image/Dockerfile create mode 100644 unreleased_history/public_api_changes/cplusplus20.md diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 6d3139e799..937e668372 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -10,7 +10,7 @@ jobs: runs-on: labels: 16-core-ubuntu container: - image: zjay437/rocksdb:0.6 + image: ghcr.io/facebook/rocksdb_ubuntu:22.0 options: --shm-size=16gb steps: - uses: actions/checkout@v4.1.0 @@ -32,7 +32,7 @@ jobs: runs-on: labels: 16-core-ubuntu container: - image: zjay437/rocksdb:0.6 + image: ghcr.io/facebook/rocksdb_ubuntu:22.0 options: --shm-size=16gb env: TEST_TMPDIR: "/tmp/rocksdb_test_tmp" @@ -63,7 +63,7 @@ jobs: runs-on: labels: 16-core-ubuntu container: - image: zjay437/rocksdb:0.6 + image: ghcr.io/facebook/rocksdb_ubuntu:22.0 options: --shm-size=16gb steps: - uses: actions/checkout@v4.1.0 @@ -94,7 +94,7 @@ jobs: runs-on: labels: 4-core-ubuntu container: - image: zjay437/rocksdb:0.6 + image: ghcr.io/facebook/rocksdb_ubuntu:22.0 options: --shm-size=16gb steps: - uses: actions/checkout@v4.1.0 @@ -117,28 +117,13 @@ jobs: - name: Build fuzzers run: cd fuzz && make sst_file_writer_fuzzer db_fuzzer db_map_fuzzer - uses: "./.github/actions/post-steps" - build-linux-gcc-11-no_test_run: - if: ${{ github.repository_owner == 'facebook' }} - runs-on: - labels: 16-core-ubuntu - container: - image: zjay437/rocksdb:0.6 - options: --shm-size=16gb - steps: - - uses: actions/checkout@v4.1.0 - - uses: "./.github/actions/pre-steps" - - run: LIB_MODE=static CC=gcc-11 CXX=g++-11 V=1 make -j32 all microbench - - uses: "./.github/actions/post-steps" build-linux-cmake-with-folly-lite-no-test: if: ${{ github.repository_owner == 'facebook' }} runs-on: labels: 16-core-ubuntu container: - image: zjay437/rocksdb:0.6 + image: ghcr.io/facebook/rocksdb_ubuntu:22.0 options: --shm-size=16gb - env: - CC: gcc-10 - CXX: g++-10 steps: - uses: actions/checkout@v4.1.0 - uses: "./.github/actions/pre-steps" diff --git a/.github/workflows/pr-jobs.yml b/.github/workflows/pr-jobs.yml index 8d423c240c..a828991ca9 100644 --- a/.github/workflows/pr-jobs.yml +++ b/.github/workflows/pr-jobs.yml @@ -66,7 +66,7 @@ jobs: runs-on: labels: 16-core-ubuntu container: - image: zjay437/rocksdb:0.6 + image: ghcr.io/facebook/rocksdb_ubuntu:22.0 options: --shm-size=16gb steps: - uses: actions/checkout@v4.1.0 @@ -78,7 +78,7 @@ jobs: runs-on: labels: 4-core-ubuntu container: - image: zjay437/rocksdb:0.6 + image: ghcr.io/facebook/rocksdb_ubuntu:22.0 options: --shm-size=16gb steps: - uses: actions/checkout@v4.1.0 @@ -97,11 +97,8 @@ jobs: runs-on: labels: 16-core-ubuntu container: - image: zjay437/rocksdb:0.6 + image: ghcr.io/facebook/rocksdb_ubuntu:22.0 options: --shm-size=16gb - env: - CC: gcc-10 - CXX: g++-10 steps: - uses: actions/checkout@v4.1.0 - uses: "./.github/actions/pre-steps" @@ -114,11 +111,8 @@ jobs: runs-on: labels: 16-core-ubuntu container: - image: zjay437/rocksdb:0.6 + image: ghcr.io/facebook/rocksdb_ubuntu:22.0 options: --shm-size=16gb - env: - CC: gcc-10 - CXX: g++-10 steps: - uses: actions/checkout@v4.1.0 - uses: "./.github/actions/pre-steps" @@ -131,11 +125,8 @@ jobs: runs-on: labels: 16-core-ubuntu container: - image: zjay437/rocksdb:0.6 + image: ghcr.io/facebook/rocksdb_ubuntu:22.0 options: --shm-size=16gb - env: - CC: gcc-10 - CXX: g++-10 steps: - uses: actions/checkout@v4.1.0 - uses: "./.github/actions/pre-steps" @@ -147,11 +138,8 @@ jobs: runs-on: labels: 16-core-ubuntu container: - image: zjay437/rocksdb:0.6 + image: ghcr.io/facebook/rocksdb_ubuntu:22.0 options: --shm-size=16gb - env: - CC: gcc-10 - CXX: g++-10 steps: - uses: actions/checkout@v4.1.0 - uses: "./.github/actions/pre-steps" @@ -164,7 +152,7 @@ jobs: runs-on: labels: 16-core-ubuntu container: - image: zjay437/rocksdb:0.6 + image: ghcr.io/facebook/rocksdb_ubuntu:22.0 options: --shm-size=16gb steps: - uses: actions/checkout@v4.1.0 @@ -176,7 +164,7 @@ jobs: runs-on: labels: 16-core-ubuntu container: - image: zjay437/rocksdb:0.6 + image: ghcr.io/facebook/rocksdb_ubuntu:22.0 options: --shm-size=16gb steps: - uses: actions/checkout@v4.1.0 @@ -190,7 +178,7 @@ jobs: runs-on: labels: 16-core-ubuntu container: - image: zjay437/rocksdb:0.6 + image: ghcr.io/facebook/rocksdb_ubuntu:22.0 options: --shm-size=16gb steps: - uses: actions/checkout@v4.1.0 @@ -236,29 +224,17 @@ jobs: - run: make clean - run: CC=clang-13 CXX=clang++-13 USE_CLANG=1 DEBUG_LEVEL=0 make -j32 release - uses: "./.github/actions/post-steps" - build-linux-gcc-8-no_test_run: + build-linux-gcc-13-no_test_run: if: ${{ github.repository_owner == 'facebook' }} runs-on: labels: 16-core-ubuntu container: - image: zjay437/rocksdb:0.6 + image: ghcr.io/facebook/rocksdb_ubuntu:22.0 options: --shm-size=16gb steps: - uses: actions/checkout@v4.1.0 - uses: "./.github/actions/pre-steps" - - run: CC=gcc-8 CXX=g++-8 V=1 make -j32 all - - uses: "./.github/actions/post-steps" - build-linux-gcc-10-cxx20-no_test_run: - if: ${{ github.repository_owner == 'facebook' }} - runs-on: - labels: 16-core-ubuntu - container: - image: zjay437/rocksdb:0.6 - options: --shm-size=16gb - steps: - - uses: actions/checkout@v4.1.0 - - uses: "./.github/actions/pre-steps" - - run: CC=gcc-10 CXX=g++-10 V=1 ROCKSDB_CXX_STANDARD=c++20 make -j32 all + - run: CC=gcc-13 CXX=g++-13 V=1 make -j32 all microbench - uses: "./.github/actions/post-steps" # ======================== Linux Other Checks ======================= # @@ -300,7 +276,7 @@ jobs: runs-on: labels: 4-core-ubuntu container: - image: zjay437/rocksdb:0.6 + image: ghcr.io/facebook/rocksdb_ubuntu:22.0 options: --shm-size=16gb steps: - uses: actions/checkout@v4.1.0 @@ -337,7 +313,7 @@ jobs: runs-on: labels: 16-core-ubuntu container: - image: zjay437/rocksdb:0.6 + image: ghcr.io/facebook/rocksdb_ubuntu:22.0 options: --shm-size=16gb steps: - uses: actions/checkout@v4.1.0 @@ -404,11 +380,13 @@ jobs: runs-on: labels: 4-core-ubuntu container: - image: evolvedbinary/rocksjava:centos7_x64-be + image: ghcr.io/facebook/rocksdb_ubuntu:22.0 options: --shm-size=16gb steps: # The docker image is intentionally based on an OS that has an older GLIBC version. # That GLIBC is incompatibile with GitHub's actions/checkout. Thus we implement a manual checkout step. + # NOTE: replaced evolvedbinary/rocksjava:centos7_x64-be with ghcr.io/facebook/rocksdb_ubuntu:22.0 + # until a more appropriate docker image with C++20 support is made. - name: Checkout env: GH_TOKEN: ${{ github.token }} @@ -425,18 +403,21 @@ jobs: which java && java -version which javac && javac -version - name: Test RocksDBJava - run: scl enable devtoolset-7 'make V=1 J=8 -j8 jtest' - # NOTE: post-steps skipped because of compatibility issues with docker image + # NOTE: replaced scl enable devtoolset-7 'make V=1 J=8 -j8 jtest' + run: make V=1 J=8 -j8 jtest + # post-steps skipped because of compatibility issues with docker image build-linux-java-static: if: ${{ github.repository_owner == 'facebook' }} runs-on: labels: 4-core-ubuntu container: - image: evolvedbinary/rocksjava:centos7_x64-be + image: ghcr.io/facebook/rocksdb_ubuntu:22.0 options: --shm-size=16gb steps: # The docker image is intentionally based on an OS that has an older GLIBC version. # That GLIBC is incompatibile with GitHub's actions/checkout. Thus we implement a manual checkout step. + # NOTE: replaced evolvedbinary/rocksjava:centos7_x64-be with ghcr.io/facebook/rocksdb_ubuntu:22.0 + # until a more appropriate docker image with C++20 support is made. - name: Checkout env: GH_TOKEN: ${{ github.token }} @@ -453,8 +434,9 @@ jobs: which java && java -version which javac && javac -version - name: Build RocksDBJava Static Library - run: scl enable devtoolset-7 'make V=1 J=8 -j8 rocksdbjavastatic' - # NOTE: post-steps skipped because of compatibility issues with docker image + # NOTE: replaced scl enable devtoolset-7 'make V=1 J=8 -j8 rocksdbjavastatic' + run: make V=1 J=8 -j8 rocksdbjavastatic + # post-steps skipped because of compatibility issues with docker image build-macos-java: if: ${{ github.repository_owner == 'facebook' }} runs-on: macos-13 diff --git a/CMakeLists.txt b/CMakeLists.txt index ef93aa20d6..19a66a7b77 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,7 @@ # # Linux: # -# 1. Install a recent toolchain if you're on a older distro. C++17 required (GCC >= 7, Clang >= 5) +# 1. Install a recent toolchain if you're on a older distro. C++20 required (GCC >= 11, Clang >= 10) # 2. mkdir build; cd build # 3. cmake .. # 4. make -j @@ -100,7 +100,7 @@ endif() option(ROCKSDB_BUILD_SHARED "Build shared versions of the RocksDB libraries" ON) if( NOT DEFINED CMAKE_CXX_STANDARD ) - set(CMAKE_CXX_STANDARD 17) + set(CMAKE_CXX_STANDARD 20) endif() include(CMakeDependentOption) @@ -314,7 +314,6 @@ endif() # Check if -latomic is required or not if (NOT MSVC) - set(CMAKE_REQUIRED_FLAGS "--std=c++17") CHECK_CXX_SOURCE_COMPILES(" #include std::atomic x(0); diff --git a/INSTALL.md b/INSTALL.md index 5bc5bd7b29..1e739d485d 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -6,7 +6,7 @@ than release mode. RocksDB's library should be able to compile without any dependency installed, although we recommend installing some compression libraries (see below). -We do depend on newer gcc/clang with C++17 support (GCC >= 7, Clang >= 5). +We do depend on newer gcc/clang with C++20 support (GCC >= 11, Clang >= 10). There are few options when compiling RocksDB: @@ -60,7 +60,7 @@ most processors made since roughly 2013. ## Supported platforms * **Linux - Ubuntu** - * Upgrade your gcc to version at least 7 to get C++17 support. + * Upgrade your gcc to version at least 11 to get C++20 support. * Install gflags. First, try: `sudo apt-get install libgflags-dev` If this doesn't work and you're using Ubuntu, here's a nice tutorial: (http://askubuntu.com/questions/312173/installing-gflags-12-04) @@ -72,7 +72,7 @@ most processors made since roughly 2013. * Install zstandard: `sudo apt-get install libzstd-dev`. * **Linux - CentOS / RHEL** - * Upgrade your gcc to version at least 7 to get C++17 support + * Upgrade your gcc to version at least 11 to get C++20 support * Install gflags: git clone https://github.com/gflags/gflags.git @@ -122,7 +122,7 @@ most processors made since roughly 2013. make && sudo make install * **OS X**: - * Install latest C++ compiler that supports C++ 17: + * Install latest C++ compiler that supports C++20: * Update XCode: run `xcode-select --install` (or install it from XCode App's settting). * Install via [homebrew](http://brew.sh/). * If you're first time developer in MacOS, you still need to run: `xcode-select --install` in your command line. @@ -213,7 +213,7 @@ most processors made since roughly 2013. export PATH=/opt/freeware/bin:$PATH * **Solaris Sparc** - * Install GCC 7 and higher. + * Install GCC 11 and higher. * Use these environment variables: export CC=gcc diff --git a/Makefile b/Makefile index a766426b05..e0ec771153 100644 --- a/Makefile +++ b/Makefile @@ -148,10 +148,8 @@ ifeq ($(USE_COROUTINES), 1) USE_FOLLY = 1 # glog/logging.h requires HAVE_CXX11_ATOMIC OPT += -DUSE_COROUTINES -DHAVE_CXX11_ATOMIC - ROCKSDB_CXX_STANDARD = c++2a USE_RTTI = 1 ifneq ($(USE_CLANG), 1) - ROCKSDB_CXX_STANDARD = c++20 PLATFORM_CXXFLAGS += -fcoroutines endif endif @@ -683,7 +681,7 @@ am__v_CCH_1 = # user build settings %.h.pub: %.h # .h.pub not actually created, so re-checked on each invocation $(AM_V_CCH) cd include/ && echo '#include "$(patsubst include/%,%,$<)"' | \ - $(CXX) -I. -DROCKSDB_NAMESPACE=42 -x c++ -c - -o /dev/null + $(CXX) -std=$(or $(ROCKSDB_CXX_STANDARD),c++20) -I. -DROCKSDB_NAMESPACE=42 -x c++ -c - -o /dev/null check-headers: $(HEADER_OK_FILES) @@ -2251,7 +2249,7 @@ libsnappy.a: snappy-$(SNAPPY_VER).tar.gz -rm -rf snappy-$(SNAPPY_VER) tar xvzf snappy-$(SNAPPY_VER).tar.gz mkdir snappy-$(SNAPPY_VER)/build - cd snappy-$(SNAPPY_VER)/build && CFLAGS='$(ARCHFLAG) ${JAVA_STATIC_DEPS_CCFLAGS} ${EXTRA_CFLAGS}' CXXFLAGS='$(ARCHFLAG) ${JAVA_STATIC_DEPS_CXXFLAGS} ${EXTRA_CXXFLAGS}' LDFLAGS='${JAVA_STATIC_DEPS_LDFLAGS} ${EXTRA_LDFLAGS}' cmake -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DSNAPPY_BUILD_BENCHMARKS=OFF -DSNAPPY_BUILD_TESTS=OFF --compile-no-warning-as-error ${PLATFORM_CMAKE_FLAGS} .. && $(MAKE) ${SNAPPY_MAKE_TARGET} + cd snappy-$(SNAPPY_VER)/build && CFLAGS='$(ARCHFLAG) ${JAVA_STATIC_DEPS_CCFLAGS} ${EXTRA_CFLAGS}' CXXFLAGS='$(ARCHFLAG) ${JAVA_STATIC_DEPS_CXXFLAGS} ${EXTRA_CXXFLAGS}' LDFLAGS='${JAVA_STATIC_DEPS_LDFLAGS} ${EXTRA_LDFLAGS}' cmake -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DSNAPPY_BUILD_BENCHMARKS=OFF -DSNAPPY_BUILD_TESTS=OFF ${PLATFORM_CMAKE_FLAGS} .. && $(MAKE) ${SNAPPY_MAKE_TARGET} cp snappy-$(SNAPPY_VER)/build/libsnappy.a . lz4-$(LZ4_VER).tar.gz: diff --git a/build_tools/build_detect_platform b/build_tools/build_detect_platform index f0d4bb004c..93e0c0fa76 100755 --- a/build_tools/build_detect_platform +++ b/build_tools/build_detect_platform @@ -45,11 +45,11 @@ if test -z "$OUTPUT"; then exit 1 fi -# we depend on C++17, but should be compatible with newer standards +# we depend on C++20, but should be compatible with newer standards if [ "$ROCKSDB_CXX_STANDARD" ]; then PLATFORM_CXXFLAGS="-std=$ROCKSDB_CXX_STANDARD" else - PLATFORM_CXXFLAGS="-std=c++17" + PLATFORM_CXXFLAGS="-std=c++20" fi # we currently depend on POSIX platform diff --git a/build_tools/ubuntu22_image/Dockerfile b/build_tools/ubuntu22_image/Dockerfile new file mode 100644 index 0000000000..353b0651fa --- /dev/null +++ b/build_tools/ubuntu22_image/Dockerfile @@ -0,0 +1,80 @@ +# INSTRUCTIONS: +# I was not about to build docker images on an isolated devserver because of +# issues with proxy internet access. Use a public cloud or other Linux system. +# (I used a Debian system after installing docker features, adding my user to +# the docker and docker-registry groups, and logging out and back in to pick +# those up.) +# +# Follow https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry#authenticating-with-a-personal-access-token-classic +# to login with your GitHub credentials, as in +# +# $ docker login ghcr.io -u pdillinger +# +# and paste the limited-purpose GitHub token into the terminal. +# +# Then in the build_tools/ubuntu22_image directory, (bump minor version for +# random docker file updates, major version tracks Ubuntu release) +# +# $ docker build -t ghcr.io/facebook/rocksdb_ubuntu:22.0 +# $ docker push ghcr.io/facebook/rocksdb_ubuntu:22.0 +# +# Might need to change visibility to public through +# https://github.com/orgs/facebook/packages/container/rocksdb_ubuntu/settings +# or similar. + +# from official ubuntu 22.04 +FROM ubuntu:22.04 +# update system +RUN apt-get update +RUN apt-get upgrade -y +# install basic tools +RUN apt-get install -y vim wget curl +# install tzdata noninteractive +RUN DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get -y install tzdata +# install git and default compilers +RUN apt-get install -y git gcc g++ clang clang-tools +# install basic package +RUN apt-get install -y lsb-release software-properties-common gnupg +# install gflags, tbb +RUN apt-get install -y libgflags-dev libtbb-dev +# install compression libs +RUN apt-get install -y libsnappy-dev zlib1g-dev libbz2-dev liblz4-dev libzstd-dev +# install cmake +RUN apt-get install -y cmake +RUN apt-get install -y libssl-dev +# install clang-13 +WORKDIR /root +RUN wget https://apt.llvm.org/llvm.sh +RUN chmod +x llvm.sh +RUN ./llvm.sh 13 all +# install gcc-10 and more, default is 11 +RUN apt-get install -y gcc-10 g++-10 +RUN add-apt-repository -y ppa:ubuntu-toolchain-r/test +RUN apt-get install -y gcc-13 g++-13 +# install apt-get install -y valgrind +RUN apt-get install -y valgrind +# install folly depencencies +RUN apt-get install -y libunwind-dev libgoogle-glog-dev +# install openjdk 8 +RUN apt-get install -y openjdk-8-jdk +ENV JAVA_HOME /usr/lib/jvm/java-1.8.0-openjdk-amd64 +# install mingw +RUN apt-get install -y mingw-w64 + +# install gtest-parallel package +RUN git clone --single-branch --branch master --depth 1 https://github.com/google/gtest-parallel.git ~/gtest-parallel +ENV PATH $PATH:/root/gtest-parallel + +# install libprotobuf for fuzzers test +RUN apt-get install -y ninja-build binutils liblzma-dev libz-dev pkg-config autoconf libtool +RUN git clone --branch v1.0 https://github.com/google/libprotobuf-mutator.git ~/libprotobuf-mutator && cd ~/libprotobuf-mutator && git checkout ffd86a32874e5c08a143019aad1aaf0907294c9f && mkdir build && cd build && cmake .. -GNinja -DCMAKE_C_COMPILER=clang-13 -DCMAKE_CXX_COMPILER=clang++-13 -DCMAKE_BUILD_TYPE=Release -DLIB_PROTO_MUTATOR_DOWNLOAD_PROTOBUF=ON && ninja && ninja install +ENV PKG_CONFIG_PATH /usr/local/OFF/:/root/libprotobuf-mutator/build/external.protobuf/lib/pkgconfig/ +ENV PROTOC_BIN /root/libprotobuf-mutator/build/external.protobuf/bin/protoc + +# install the latest google benchmark +RUN git clone --depth 1 --branch v1.7.0 https://github.com/google/benchmark.git ~/benchmark +RUN cd ~/benchmark && mkdir build && cd build && cmake .. -GNinja -DCMAKE_BUILD_TYPE=Release -DBENCHMARK_ENABLE_GTEST_TESTS=0 && ninja && ninja install + +# clean up +RUN rm -rf /var/lib/apt/lists/* +RUN rm -rf /root/benchmark diff --git a/db/db_impl/db_impl.cc b/db/db_impl/db_impl.cc index 3acde3a39c..3bf0def153 100644 --- a/db/db_impl/db_impl.cc +++ b/db/db_impl/db_impl.cc @@ -1245,13 +1245,11 @@ Status DBImpl::SetOptions( WriteOptionsFile(write_options, true /*db_mutex_already_held*/); bg_cv_.SignalAll(); -#if __cplusplus >= 202002L assert(new_options_copy == cfd->GetLatestMutableCFOptions()); assert(cfd->GetLatestMutableCFOptions() == cfd->GetCurrentMutableCFOptions()); assert(cfd->GetCurrentMutableCFOptions() == cfd->current()->GetMutableCFOptions()); -#endif } } sv_context.Clean(); diff --git a/examples/Makefile b/examples/Makefile index b056508a6c..0970cfd400 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -19,16 +19,16 @@ CFLAGS += -Wstrict-prototypes all: simple_example column_families_example compact_files_example c_simple_example optimistic_transaction_example transaction_example compaction_filter_example options_file_example rocksdb_backup_restore_example simple_example: librocksdb simple_example.cc - $(CXX) $(CXXFLAGS) $@.cc -o$@ ../librocksdb.a -I../include -O2 -std=c++17 $(PLATFORM_LDFLAGS) $(PLATFORM_CXXFLAGS) $(EXEC_LDFLAGS) + $(CXX) $(CXXFLAGS) $@.cc -o$@ ../librocksdb.a -I../include -O2 -std=c++20 $(PLATFORM_LDFLAGS) $(PLATFORM_CXXFLAGS) $(EXEC_LDFLAGS) column_families_example: librocksdb column_families_example.cc - $(CXX) $(CXXFLAGS) $@.cc -o$@ ../librocksdb.a -I../include -O2 -std=c++17 $(PLATFORM_LDFLAGS) $(PLATFORM_CXXFLAGS) $(EXEC_LDFLAGS) + $(CXX) $(CXXFLAGS) $@.cc -o$@ ../librocksdb.a -I../include -O2 -std=c++20 $(PLATFORM_LDFLAGS) $(PLATFORM_CXXFLAGS) $(EXEC_LDFLAGS) compaction_filter_example: librocksdb compaction_filter_example.cc - $(CXX) $(CXXFLAGS) $@.cc -o$@ ../librocksdb.a -I../include -O2 -std=c++17 $(PLATFORM_LDFLAGS) $(PLATFORM_CXXFLAGS) $(EXEC_LDFLAGS) + $(CXX) $(CXXFLAGS) $@.cc -o$@ ../librocksdb.a -I../include -O2 -std=c++20 $(PLATFORM_LDFLAGS) $(PLATFORM_CXXFLAGS) $(EXEC_LDFLAGS) compact_files_example: librocksdb compact_files_example.cc - $(CXX) $(CXXFLAGS) $@.cc -o$@ ../librocksdb.a -I../include -O2 -std=c++17 $(PLATFORM_LDFLAGS) $(PLATFORM_CXXFLAGS) $(EXEC_LDFLAGS) + $(CXX) $(CXXFLAGS) $@.cc -o$@ ../librocksdb.a -I../include -O2 -std=c++20 $(PLATFORM_LDFLAGS) $(PLATFORM_CXXFLAGS) $(EXEC_LDFLAGS) .c.o: $(CC) $(CFLAGS) -c $< -o $@ -I../include @@ -37,19 +37,19 @@ c_simple_example: librocksdb c_simple_example.o $(CXX) $@.o -o$@ ../librocksdb.a $(PLATFORM_LDFLAGS) $(EXEC_LDFLAGS) optimistic_transaction_example: librocksdb optimistic_transaction_example.cc - $(CXX) $(CXXFLAGS) $@.cc -o$@ ../librocksdb.a -I../include -O2 -std=c++17 $(PLATFORM_LDFLAGS) $(PLATFORM_CXXFLAGS) $(EXEC_LDFLAGS) + $(CXX) $(CXXFLAGS) $@.cc -o$@ ../librocksdb.a -I../include -O2 -std=c++20 $(PLATFORM_LDFLAGS) $(PLATFORM_CXXFLAGS) $(EXEC_LDFLAGS) transaction_example: librocksdb transaction_example.cc - $(CXX) $(CXXFLAGS) $@.cc -o$@ ../librocksdb.a -I../include -O2 -std=c++17 $(PLATFORM_LDFLAGS) $(PLATFORM_CXXFLAGS) $(EXEC_LDFLAGS) + $(CXX) $(CXXFLAGS) $@.cc -o$@ ../librocksdb.a -I../include -O2 -std=c++20 $(PLATFORM_LDFLAGS) $(PLATFORM_CXXFLAGS) $(EXEC_LDFLAGS) options_file_example: librocksdb options_file_example.cc - $(CXX) $(CXXFLAGS) $@.cc -o$@ ../librocksdb.a -I../include -O2 -std=c++17 $(PLATFORM_LDFLAGS) $(PLATFORM_CXXFLAGS) $(EXEC_LDFLAGS) + $(CXX) $(CXXFLAGS) $@.cc -o$@ ../librocksdb.a -I../include -O2 -std=c++20 $(PLATFORM_LDFLAGS) $(PLATFORM_CXXFLAGS) $(EXEC_LDFLAGS) multi_processes_example: librocksdb multi_processes_example.cc - $(CXX) $(CXXFLAGS) $@.cc -o$@ ../librocksdb.a -I../include -O2 -std=c++17 $(PLATFORM_LDFLAGS) $(PLATFORM_CXXFLAGS) $(EXEC_LDFLAGS) + $(CXX) $(CXXFLAGS) $@.cc -o$@ ../librocksdb.a -I../include -O2 -std=c++20 $(PLATFORM_LDFLAGS) $(PLATFORM_CXXFLAGS) $(EXEC_LDFLAGS) rocksdb_backup_restore_example: librocksdb rocksdb_backup_restore_example.cc - $(CXX) $(CXXFLAGS) $@.cc -o$@ ../librocksdb.a -I../include -O2 -std=c++17 $(PLATFORM_LDFLAGS) $(PLATFORM_CXXFLAGS) $(EXEC_LDFLAGS) + $(CXX) $(CXXFLAGS) $@.cc -o$@ ../librocksdb.a -I../include -O2 -std=c++20 $(PLATFORM_LDFLAGS) $(PLATFORM_CXXFLAGS) $(EXEC_LDFLAGS) clean: rm -rf ./simple_example ./column_families_example ./compact_files_example ./compaction_filter_example ./c_simple_example c_simple_example.o ./optimistic_transaction_example ./transaction_example ./options_file_example ./multi_processes_example ./rocksdb_backup_restore_example diff --git a/include/rocksdb/advanced_options.h b/include/rocksdb/advanced_options.h index f78bb0c2c1..90767a06ec 100644 --- a/include/rocksdb/advanced_options.h +++ b/include/rocksdb/advanced_options.h @@ -64,9 +64,7 @@ enum CompactionPri : char { struct FileTemperatureAge { Temperature temperature = Temperature::kUnknown; uint64_t age = 0; -#if __cplusplus >= 202002L bool operator==(const FileTemperatureAge& rhs) const = default; -#endif }; struct CompactionOptionsFIFO { @@ -135,9 +133,7 @@ struct CompactionOptionsFIFO { : max_table_files_size(_max_table_files_size), allow_compaction(_allow_compaction) {} -#if __cplusplus >= 202002L bool operator==(const CompactionOptionsFIFO& rhs) const = default; -#endif }; // The control option of how the cache tiers will be used. Currently rocksdb diff --git a/include/rocksdb/compression_type.h b/include/rocksdb/compression_type.h index a05aa33078..2261a44439 100644 --- a/include/rocksdb/compression_type.h +++ b/include/rocksdb/compression_type.h @@ -313,9 +313,7 @@ struct CompressionOptions { max_compressed_bytes_per_kb = static_cast(1024.0 / min_ratio + 0.5); } -#if __cplusplus >= 202002L bool operator==(const CompressionOptions& rhs) const = default; -#endif }; // See advanced_compression.h diff --git a/include/rocksdb/slice.h b/include/rocksdb/slice.h index c914b1637b..dde34d709d 100644 --- a/include/rocksdb/slice.h +++ b/include/rocksdb/slice.h @@ -24,7 +24,7 @@ #include #include #include -#include // RocksDB now requires C++17 support +#include #include "rocksdb/cleanable.h" diff --git a/include/rocksdb/universal_compaction.h b/include/rocksdb/universal_compaction.h index 6d2579baae..d94e9653aa 100644 --- a/include/rocksdb/universal_compaction.h +++ b/include/rocksdb/universal_compaction.h @@ -144,9 +144,7 @@ class CompactionOptionsUniversal { incremental(false), reduce_file_locking(false) {} -#if __cplusplus >= 202002L bool operator==(const CompactionOptionsUniversal& rhs) const = default; -#endif }; } // namespace ROCKSDB_NAMESPACE diff --git a/include/rocksdb/utilities/cache_dump_load.h b/include/rocksdb/utilities/cache_dump_load.h index 8f41839cd9..ca2ce5ae11 100644 --- a/include/rocksdb/utilities/cache_dump_load.h +++ b/include/rocksdb/utilities/cache_dump_load.h @@ -90,7 +90,7 @@ class CacheDumper { public: virtual ~CacheDumper() = default; // Only dump the blocks in the block cache that belong to the DBs in this list - virtual Status SetDumpFilter(std::vector db_list) { + virtual Status SetDumpFilter(const std::vector& db_list) { (void)db_list; return Status::NotSupported("SetDumpFilter is not supported"); } diff --git a/options/cf_options.h b/options/cf_options.h index c481c0587d..6ac660854f 100644 --- a/options/cf_options.h +++ b/options/cf_options.h @@ -257,9 +257,7 @@ struct MutableCFOptions { void Dump(Logger* log) const; -#if __cplusplus >= 202002L bool operator==(const MutableCFOptions& rhs) const = default; -#endif // Memtable related options size_t write_buffer_size; diff --git a/unreleased_history/public_api_changes/cplusplus20.md b/unreleased_history/public_api_changes/cplusplus20.md new file mode 100644 index 0000000000..e2c7311fdf --- /dev/null +++ b/unreleased_history/public_api_changes/cplusplus20.md @@ -0,0 +1 @@ +* RocksDB now requires a C++20 compatible compiler (GCC >= 11, Clang >= 10, Visual Studio >= 2019), including for any code using RocksDB headers. diff --git a/util/slice_test.cc b/util/slice_test.cc index bc8925299a..c1a0c806b8 100644 --- a/util/slice_test.cc +++ b/util/slice_test.cc @@ -7,6 +7,8 @@ #include +#include + #include "port/port.h" #include "port/stack_trace.h" #include "rocksdb/data_structure.h" @@ -422,6 +424,24 @@ TEST(ToBaseCharsStringTest, Tests) { ASSERT_EQ(ToBaseCharsString<32>(2, 255, false), "7v"); } +TEST(SemaphoreTest, BasicStdCountingSemaphore) { + // Verify the C++20 API is available and apparently working + std::counting_semaphore sem{0}; + int kCount = 5; + std::vector threads; + for (int i = 0; i < kCount; ++i) { + threads.emplace_back([&sem] { sem.release(); }); + } + for (int i = 0; i < kCount; ++i) { + threads.emplace_back([&sem] { sem.acquire(); }); + } + for (auto& t : threads) { + t.join(); + } + // Nothing left on the semaphore + ASSERT_FALSE(sem.try_acquire()); +} + } // namespace ROCKSDB_NAMESPACE int main(int argc, char** argv) { diff --git a/util/string_util.cc b/util/string_util.cc index 2a45c3a0ee..0dc3e7158e 100644 --- a/util/string_util.cc +++ b/util/string_util.cc @@ -20,20 +20,6 @@ #include "port/sys_time.h" #include "rocksdb/slice.h" -#ifndef __has_cpp_attribute -#define ROCKSDB_HAS_CPP_ATTRIBUTE(x) 0 -#else -#define ROCKSDB_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x) -#endif - -#if ROCKSDB_HAS_CPP_ATTRIBUTE(maybe_unused) && __cplusplus >= 201703L -#define ROCKSDB_MAYBE_UNUSED [[maybe_unused]] -#elif ROCKSDB_HAS_CPP_ATTRIBUTE(gnu::unused) || __GNUC__ -#define ROCKSDB_MAYBE_UNUSED [[gnu::unused]] -#else -#define ROCKSDB_MAYBE_UNUSED -#endif - namespace ROCKSDB_NAMESPACE { const std::string kNullptrString = "nullptr"; @@ -501,7 +487,7 @@ bool TryParseTimeRangeString(const std::string& value, int& start_time, // selects proper function. #if !(defined(_WIN32) && (defined(__MINGW32__) || defined(_MSC_VER))) -ROCKSDB_MAYBE_UNUSED +[[maybe_unused]] static std::string invoke_strerror_r(int (*strerror_r)(int, char*, size_t), int err, char* buf, size_t buflen) { // Using XSI-compatible strerror_r @@ -515,7 +501,7 @@ static std::string invoke_strerror_r(int (*strerror_r)(int, char*, size_t), return buf; } -ROCKSDB_MAYBE_UNUSED +[[maybe_unused]] static std::string invoke_strerror_r(char* (*strerror_r)(int, char*, size_t), int err, char* buf, size_t buflen) { // Using GNU strerror_r diff --git a/utilities/cache_dump_load_impl.cc b/utilities/cache_dump_load_impl.cc index 042ed53411..40552ce120 100644 --- a/utilities/cache_dump_load_impl.cc +++ b/utilities/cache_dump_load_impl.cc @@ -24,7 +24,7 @@ namespace ROCKSDB_NAMESPACE { // DBs and we may only want to dump out the blocks belonging to certain DB(s). // Therefore, a filter is need to decide if the key of the block satisfy the // requirement. -Status CacheDumperImpl::SetDumpFilter(std::vector db_list) { +Status CacheDumperImpl::SetDumpFilter(const std::vector& db_list) { Status s = Status::OK(); dump_all_keys_ = false; for (size_t i = 0; i < db_list.size(); i++) { diff --git a/utilities/cache_dump_load_impl.h b/utilities/cache_dump_load_impl.h index ee892f4748..b9b62df2a4 100644 --- a/utilities/cache_dump_load_impl.h +++ b/utilities/cache_dump_load_impl.h @@ -100,7 +100,7 @@ class CacheDumperImpl : public CacheDumper { dumped_size_bytes_ = 0; } ~CacheDumperImpl() { writer_.reset(); } - Status SetDumpFilter(std::vector db_list) override; + Status SetDumpFilter(const std::vector& db_list) override; IOStatus DumpCacheEntriesToWriter() override; private: