Skip to content

Commit

Permalink
Fix compile errors in C++23 (facebook#12106)
Browse files Browse the repository at this point in the history
Summary:
This PR fixes compile errors in C++23.

Pull Request resolved: facebook#12106

Reviewed By: cbi42

Differential Revision: D57826279

Pulled By: ajkr

fbshipit-source-id: 594abfd8eceaf51eaf3bbabf7696c0bb5e0e9a68
  • Loading branch information
jaepil authored and facebook-github-bot committed May 28, 2024
1 parent 7c6c632 commit c115eb6
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 19 deletions.
18 changes: 8 additions & 10 deletions db/range_tombstone_fragmenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions db/write_batch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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_;
Expand All @@ -1914,15 +1915,15 @@ 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_;

bool hint_per_batch_;
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() {
Expand Down
5 changes: 3 additions & 2 deletions db/write_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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

Expand Down
24 changes: 24 additions & 0 deletions util/aligned_storage.h
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion util/random.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)) {
Expand Down
11 changes: 9 additions & 2 deletions util/xxhash.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c115eb6

Please sign in to comment.