Skip to content

Commit c115eb6

Browse files
jaepilfacebook-github-bot
authored andcommitted
Fix compile errors in C++23 (#12106)
Summary: This PR fixes compile errors in C++23. Pull Request resolved: #12106 Reviewed By: cbi42 Differential Revision: D57826279 Pulled By: ajkr fbshipit-source-id: 594abfd8eceaf51eaf3bbabf7696c0bb5e0e9a68
1 parent 7c6c632 commit c115eb6

8 files changed

Lines changed: 53 additions & 19 deletions

File tree

db/range_tombstone_fragmenter.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,6 @@
1717
#include "table/internal_iterator.h"
1818

1919
namespace ROCKSDB_NAMESPACE {
20-
struct FragmentedRangeTombstoneList;
21-
22-
struct FragmentedRangeTombstoneListCache {
23-
// ensure only the first reader needs to initialize l
24-
std::mutex reader_mutex;
25-
std::unique_ptr<FragmentedRangeTombstoneList> tombstones = nullptr;
26-
// readers will first check this bool to avoid
27-
std::atomic<bool> initialized = false;
28-
};
29-
3020
struct FragmentedRangeTombstoneList {
3121
public:
3222
// A compact representation of a "stack" of range tombstone fragments, which
@@ -124,6 +114,14 @@ struct FragmentedRangeTombstoneList {
124114
uint64_t total_tombstone_payload_bytes_;
125115
};
126116

117+
struct FragmentedRangeTombstoneListCache {
118+
// ensure only the first reader needs to initialize l
119+
std::mutex reader_mutex;
120+
std::unique_ptr<FragmentedRangeTombstoneList> tombstones = nullptr;
121+
// readers will first check this bool to avoid
122+
std::atomic<bool> initialized = false;
123+
};
124+
127125
// FragmentedRangeTombstoneIterator converts an InternalIterator of a range-del
128126
// meta block into an iterator over non-overlapping tombstone fragments. The
129127
// tombstone fragmentation process should be more efficient than the range

db/write_batch.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#include "port/lang.h"
6666
#include "rocksdb/merge_operator.h"
6767
#include "rocksdb/system_clock.h"
68+
#include "util/aligned_storage.h"
6869
#include "util/autovector.h"
6970
#include "util/cast_util.h"
7071
#include "util/coding.h"
@@ -1900,7 +1901,7 @@ class MemTableInserter : public WriteBatch::Handler {
19001901
// Make creation optional but do not incur
19011902
// std::unique_ptr additional allocation
19021903
using MemPostInfoMap = std::map<MemTable*, MemTablePostProcessInfo>;
1903-
using PostMapType = std::aligned_storage<sizeof(MemPostInfoMap)>::type;
1904+
using PostMapType = aligned_storage<MemPostInfoMap>::type;
19041905
PostMapType mem_post_info_map_;
19051906
// current recovered transaction we are rebuilding (recovery)
19061907
WriteBatch* rebuilding_trx_;
@@ -1914,15 +1915,15 @@ class MemTableInserter : public WriteBatch::Handler {
19141915
bool write_before_prepare_;
19151916
// Whether this batch was unprepared or not
19161917
bool unprepared_batch_;
1917-
using DupDetector = std::aligned_storage<sizeof(DuplicateDetector)>::type;
1918+
using DupDetector = aligned_storage<DuplicateDetector>::type;
19181919
DupDetector duplicate_detector_;
19191920
bool dup_dectector_on_;
19201921

19211922
bool hint_per_batch_;
19221923
bool hint_created_;
19231924
// Hints for this batch
19241925
using HintMap = std::unordered_map<MemTable*, void*>;
1925-
using HintMapType = std::aligned_storage<sizeof(HintMap)>::type;
1926+
using HintMapType = aligned_storage<HintMap>::type;
19261927
HintMapType hint_;
19271928

19281929
HintMap& GetHintMap() {

db/write_thread.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "rocksdb/status.h"
2424
#include "rocksdb/types.h"
2525
#include "rocksdb/write_batch.h"
26+
#include "util/aligned_storage.h"
2627
#include "util/autovector.h"
2728

2829
namespace ROCKSDB_NAMESPACE {
@@ -134,8 +135,8 @@ class WriteThread {
134135
Status status;
135136
Status callback_status; // status returned by callback->Callback()
136137

137-
std::aligned_storage<sizeof(std::mutex)>::type state_mutex_bytes;
138-
std::aligned_storage<sizeof(std::condition_variable)>::type state_cv_bytes;
138+
aligned_storage<std::mutex>::type state_mutex_bytes;
139+
aligned_storage<std::condition_variable>::type state_cv_bytes;
139140
Writer* link_older; // read/write only before linking, or as leader
140141
Writer* link_newer; // lazy, read/write only before linking, or as leader
141142

util/aligned_storage.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2+
// This source code is licensed under both the GPLv2 (found in the
3+
// COPYING file in the root directory) and Apache 2.0 License
4+
// (found in the LICENSE.Apache file in the root directory).
5+
//
6+
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
7+
// Use of this source code is governed by a BSD-style license that can be
8+
// found in the LICENSE file. See the AUTHORS file for names of contributors.
9+
#pragma once
10+
11+
#include <cstddef>
12+
13+
#include "rocksdb/rocksdb_namespace.h"
14+
15+
namespace ROCKSDB_NAMESPACE {
16+
17+
template <typename T, std::size_t Align = alignof(T)>
18+
struct aligned_storage {
19+
struct type {
20+
alignas(Align) unsigned char data[sizeof(T)];
21+
};
22+
};
23+
24+
} // namespace ROCKSDB_NAMESPACE

util/random.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <utility>
1414

1515
#include "port/likely.h"
16+
#include "util/aligned_storage.h"
1617
#include "util/thread_local.h"
1718

1819
#define STORAGE_DECL static thread_local
@@ -21,7 +22,7 @@ namespace ROCKSDB_NAMESPACE {
2122

2223
Random* Random::GetTLSInstance() {
2324
STORAGE_DECL Random* tls_instance;
24-
STORAGE_DECL std::aligned_storage<sizeof(Random)>::type tls_instance_bytes;
25+
STORAGE_DECL aligned_storage<Random>::type tls_instance_bytes;
2526

2627
auto rv = tls_instance;
2728
if (UNLIKELY(rv == nullptr)) {

util/xxhash.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@
1111
#ifndef XXH_NAMESPACE
1212
#define XXH_NAMESPACE ROCKSDB_
1313
#endif // !defined(XXH_NAMESPACE)
14+
15+
#if (defined(XXH_INLINE_ALL) || defined(XXH_PRIVATE_API) || \
16+
defined(XXH_IMPLEMENTATION)) && \
17+
!defined(XXH_IMPLEM_13a8737387)
18+
#if defined(__cplusplus) && (__cplusplus > 202002L)
19+
/* C++23 and future versions have std::unreachable() */
20+
#include <utility> /* std::unreachable() */
21+
#endif
22+
#endif
1423
/* END RocksDB customizations */
1524

1625
// clang-format off
@@ -2064,8 +2073,6 @@ static int XXH_isLittleEndian(void)
20642073
# define XXH_UNREACHABLE() unreachable()
20652074

20662075
#elif defined(__cplusplus) && (__cplusplus > 202002L)
2067-
/* C++23 and future versions have std::unreachable() */
2068-
# include <utility> /* std::unreachable() */
20692076
# define XXH_UNREACHABLE() std::unreachable()
20702077

20712078
#elif XXH_HAS_BUILTIN(__builtin_unreachable)

utilities/write_batch_with_index/write_batch_with_index_internal.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ BaseDeltaIterator::BaseDeltaIterator(ColumnFamilyHandle* column_family,
3636
assert(comparator_);
3737
}
3838

39+
BaseDeltaIterator::~BaseDeltaIterator() = default;
40+
3941
bool BaseDeltaIterator::Valid() const {
4042
return status_.ok() ? (current_at_base_ ? BaseValid() : DeltaValid()) : false;
4143
}

utilities/write_batch_with_index/write_batch_with_index_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class BaseDeltaIterator : public Iterator {
3838
WBWIIteratorImpl* delta_iterator,
3939
const Comparator* comparator);
4040

41-
~BaseDeltaIterator() override {}
41+
~BaseDeltaIterator() override;
4242

4343
bool Valid() const override;
4444
void SeekToFirst() override;

0 commit comments

Comments
 (0)