Fix compile errors in C++23 (#12106)

Summary:
This PR fixes compile errors in C++23.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/12106

Reviewed By: cbi42

Differential Revision: D57826279

Pulled By: ajkr

fbshipit-source-id: 594abfd8eceaf51eaf3bbabf7696c0bb5e0e9a68
This commit is contained in:
Jaepil Jeong 2024-05-28 15:33:57 -07:00 committed by Facebook GitHub Bot
parent 7c6c632ea9
commit c115eb6162
8 changed files with 53 additions and 19 deletions

View File

@ -17,16 +17,6 @@
#include "table/internal_iterator.h"
namespace ROCKSDB_NAMESPACE {
struct FragmentedRangeTombstoneList;
struct FragmentedRangeTombstoneListCache {
// ensure only the first reader needs to initialize l
std::mutex reader_mutex;
std::unique_ptr<FragmentedRangeTombstoneList> tombstones = nullptr;
// readers will first check this bool to avoid
std::atomic<bool> initialized = false;
};
struct FragmentedRangeTombstoneList {
public:
// A compact representation of a "stack" of range tombstone fragments, which
@ -124,6 +114,14 @@ struct FragmentedRangeTombstoneList {
uint64_t total_tombstone_payload_bytes_;
};
struct FragmentedRangeTombstoneListCache {
// ensure only the first reader needs to initialize l
std::mutex reader_mutex;
std::unique_ptr<FragmentedRangeTombstoneList> tombstones = nullptr;
// readers will first check this bool to avoid
std::atomic<bool> initialized = false;
};
// FragmentedRangeTombstoneIterator converts an InternalIterator of a range-del
// meta block into an iterator over non-overlapping tombstone fragments. The
// tombstone fragmentation process should be more efficient than the range

View File

@ -65,6 +65,7 @@
#include "port/lang.h"
#include "rocksdb/merge_operator.h"
#include "rocksdb/system_clock.h"
#include "util/aligned_storage.h"
#include "util/autovector.h"
#include "util/cast_util.h"
#include "util/coding.h"
@ -1900,7 +1901,7 @@ class MemTableInserter : public WriteBatch::Handler {
// Make creation optional but do not incur
// std::unique_ptr additional allocation
using MemPostInfoMap = std::map<MemTable*, MemTablePostProcessInfo>;
using PostMapType = std::aligned_storage<sizeof(MemPostInfoMap)>::type;
using PostMapType = aligned_storage<MemPostInfoMap>::type;
PostMapType mem_post_info_map_;
// current recovered transaction we are rebuilding (recovery)
WriteBatch* rebuilding_trx_;
@ -1914,7 +1915,7 @@ class MemTableInserter : public WriteBatch::Handler {
bool write_before_prepare_;
// Whether this batch was unprepared or not
bool unprepared_batch_;
using DupDetector = std::aligned_storage<sizeof(DuplicateDetector)>::type;
using DupDetector = aligned_storage<DuplicateDetector>::type;
DupDetector duplicate_detector_;
bool dup_dectector_on_;
@ -1922,7 +1923,7 @@ class MemTableInserter : public WriteBatch::Handler {
bool hint_created_;
// Hints for this batch
using HintMap = std::unordered_map<MemTable*, void*>;
using HintMapType = std::aligned_storage<sizeof(HintMap)>::type;
using HintMapType = aligned_storage<HintMap>::type;
HintMapType hint_;
HintMap& GetHintMap() {

View File

@ -23,6 +23,7 @@
#include "rocksdb/status.h"
#include "rocksdb/types.h"
#include "rocksdb/write_batch.h"
#include "util/aligned_storage.h"
#include "util/autovector.h"
namespace ROCKSDB_NAMESPACE {
@ -134,8 +135,8 @@ class WriteThread {
Status status;
Status callback_status; // status returned by callback->Callback()
std::aligned_storage<sizeof(std::mutex)>::type state_mutex_bytes;
std::aligned_storage<sizeof(std::condition_variable)>::type state_cv_bytes;
aligned_storage<std::mutex>::type state_mutex_bytes;
aligned_storage<std::condition_variable>::type state_cv_bytes;
Writer* link_older; // read/write only before linking, or as leader
Writer* link_newer; // lazy, read/write only before linking, or as leader

24
util/aligned_storage.h Normal file
View File

@ -0,0 +1,24 @@
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
// This source code is licensed under both the GPLv2 (found in the
// COPYING file in the root directory) and Apache 2.0 License
// (found in the LICENSE.Apache file in the root directory).
//
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. See the AUTHORS file for names of contributors.
#pragma once
#include <cstddef>
#include "rocksdb/rocksdb_namespace.h"
namespace ROCKSDB_NAMESPACE {
template <typename T, std::size_t Align = alignof(T)>
struct aligned_storage {
struct type {
alignas(Align) unsigned char data[sizeof(T)];
};
};
} // namespace ROCKSDB_NAMESPACE

View File

@ -13,6 +13,7 @@
#include <utility>
#include "port/likely.h"
#include "util/aligned_storage.h"
#include "util/thread_local.h"
#define STORAGE_DECL static thread_local
@ -21,7 +22,7 @@ namespace ROCKSDB_NAMESPACE {
Random* Random::GetTLSInstance() {
STORAGE_DECL Random* tls_instance;
STORAGE_DECL std::aligned_storage<sizeof(Random)>::type tls_instance_bytes;
STORAGE_DECL aligned_storage<Random>::type tls_instance_bytes;
auto rv = tls_instance;
if (UNLIKELY(rv == nullptr)) {

View File

@ -11,6 +11,15 @@
#ifndef XXH_NAMESPACE
#define XXH_NAMESPACE ROCKSDB_
#endif // !defined(XXH_NAMESPACE)
#if (defined(XXH_INLINE_ALL) || defined(XXH_PRIVATE_API) || \
defined(XXH_IMPLEMENTATION)) && \
!defined(XXH_IMPLEM_13a8737387)
#if defined(__cplusplus) && (__cplusplus > 202002L)
/* C++23 and future versions have std::unreachable() */
#include <utility> /* std::unreachable() */
#endif
#endif
/* END RocksDB customizations */
// clang-format off
@ -2064,8 +2073,6 @@ static int XXH_isLittleEndian(void)
# define XXH_UNREACHABLE() unreachable()
#elif defined(__cplusplus) && (__cplusplus > 202002L)
/* C++23 and future versions have std::unreachable() */
# include <utility> /* std::unreachable() */
# define XXH_UNREACHABLE() std::unreachable()
#elif XXH_HAS_BUILTIN(__builtin_unreachable)

View File

@ -36,6 +36,8 @@ BaseDeltaIterator::BaseDeltaIterator(ColumnFamilyHandle* column_family,
assert(comparator_);
}
BaseDeltaIterator::~BaseDeltaIterator() = default;
bool BaseDeltaIterator::Valid() const {
return status_.ok() ? (current_at_base_ ? BaseValid() : DeltaValid()) : false;
}

View File

@ -38,7 +38,7 @@ class BaseDeltaIterator : public Iterator {
WBWIIteratorImpl* delta_iterator,
const Comparator* comparator);
~BaseDeltaIterator() override {}
~BaseDeltaIterator() override;
bool Valid() const override;
void SeekToFirst() override;