Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++20 compatibility #6697

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
af91b57
Fix implicit capture of ‘this’ via ‘[=]’ is deprecated in C++20
syoliver-se Mar 22, 2020
880549c
Allow to choose C++ version in cmake command line
syoliver-se Mar 22, 2020
4a1df6e
Fix deprecated copy warning in gcc 9
syoliver-se Apr 5, 2020
2756589
Minimal Rebuild is deprecated in visual studio since 2015 and is forb…
syoliver-se Apr 5, 2020
cea96d0
random_shuffle is deprecated in C++14 and removed in C++17
syoliver-se Apr 5, 2020
4e46260
Fix implicit this lambda capture deprecation
syoliver-se Apr 5, 2020
96f7359
Add implicit lambda capture in raw makefile
syoliver-se Apr 6, 2020
5962870
Add MSVC2019 to AppVeyor
syoliver-se Apr 6, 2020
d31e395
Add gcc-9 with c++11 and c++20 to travis
syoliver-se Apr 6, 2020
43eee91
Merge remote-tracking branch 'origin/master' into pr/6648
pdillinger Apr 10, 2020
87f3151
Reduce cmake variants built on each PR
pdillinger Apr 10, 2020
831fb29
Fix whitespace / noeol in CMakeLists.txt
pdillinger Apr 10, 2020
3de7ca9
Tweak so that no configuration change is needed
pdillinger Apr 10, 2020
c9e951e
Unified RandomShuffle
pdillinger Apr 13, 2020
756ea7f
Remove 'this' capture from folly import
pdillinger Apr 14, 2020
1b7b028
Remove an unnecessary capture spec
pdillinger Apr 14, 2020
dda5107
make format
pdillinger Apr 14, 2020
427a33d
Merge remote-tracking branch 'origin/master' into cxx20
pdillinger Apr 14, 2020
882a9d5
Fixup after merge
pdillinger Apr 14, 2020
c19c8ac
Better capture solution for Baton.h
pdillinger Apr 14, 2020
da5b61e
Actually, just use explicit capture
pdillinger Apr 14, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Unified RandomShuffle
  • Loading branch information
pdillinger committed Apr 14, 2020
commit c9e951eee3bb57f48f8d4d8f3d9aa3ad5d686060
4 changes: 1 addition & 3 deletions db/db_bloom_filter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1344,9 +1344,7 @@ TEST_F(DBBloomFilterTest, OptimizeFiltersForHits) {
for (int i = 0; i < numkeys; i += 2) {
keys.push_back(i);
}
std::random_device rng;
std::mt19937 urng(rng());
std::shuffle(std::begin(keys), std::end(keys), urng);
RandomShuffle(std::begin(keys), std::end(keys));
int num_inserted = 0;
for (int key : keys) {
ASSERT_OK(Put(1, Key(key), "val"));
Expand Down
4 changes: 1 addition & 3 deletions db/db_compaction_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4762,9 +4762,7 @@ TEST_P(CompactionPriTest, Test) {
for (int i = 0; i < kNKeys; i++) {
keys[i] = i;
}
std::random_device rng;
std::mt19937 urng(rng());
std::shuffle(std::begin(keys), std::end(keys), urng);
RandomShuffle(std::begin(keys), std::end(keys), rnd.Next());

for (int i = 0; i < kNKeys; i++) {
ASSERT_OK(Put(Key(keys[i]), RandomString(&rnd, 102)));
Expand Down
4 changes: 1 addition & 3 deletions db/db_dynamic_level_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ TEST_F(DBTestDynamicLevel, DynamicLevelMaxBytesBase) {
keys[i] = i;
}
if (ordered_insert == 0) {
std::random_device rng;
std::mt19937 urng(rng());
std::shuffle(std::begin(keys), std::end(keys), urng);
RandomShuffle(std::begin(keys), std::end(keys), rnd.Next());
}
for (int max_background_compactions = 1; max_background_compactions < 4;
max_background_compactions += 2) {
Expand Down
12 changes: 3 additions & 9 deletions db/db_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1421,9 +1421,7 @@ TEST_F(DBTest, ApproximateSizesMemTable) {
keys[i * 3 + 1] = i * 5 + 1;
keys[i * 3 + 2] = i * 5 + 2;
}
std::random_device rng;
std::mt19937 urng(rng());
std::shuffle(std::begin(keys), std::end(keys), urng);
RandomShuffle(std::begin(keys), std::end(keys));

for (int i = 0; i < N * 3; i++) {
ASSERT_OK(Put(Key(keys[i] + 1000), RandomString(&rnd, 1024)));
Expand Down Expand Up @@ -4532,9 +4530,7 @@ TEST_F(DBTest, DynamicLevelCompressionPerLevel) {
for (int i = 0; i < kNKeys; i++) {
keys[i] = i;
}
std::random_device rng;
std::mt19937 urng(rng());
std::shuffle(std::begin(keys), std::end(keys), urng);
RandomShuffle(std::begin(keys), std::end(keys));

Random rnd(301);
Options options;
Expand Down Expand Up @@ -4617,9 +4613,7 @@ TEST_F(DBTest, DynamicLevelCompressionPerLevel2) {
for (int i = 0; i < kNKeys; i++) {
keys[i] = i;
}
std::random_device rng;
std::mt19937 urng(rng());
std::shuffle(std::begin(keys), std::end(keys), urng);
RandomShuffle(std::begin(keys), std::end(keys));

Random rnd(301);
Options options;
Expand Down
2 changes: 1 addition & 1 deletion db/log_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

#include <stdio.h>
#include "file/sequence_file_reader.h"
#include "port/lang.h"
#include "rocksdb/env.h"
#include "test_util/sync_point.h"
#include "util/coding.h"
#include "util/crc32c.h"
#include "port/lang.h"

namespace ROCKSDB_NAMESPACE {
namespace log {
Expand Down
2 changes: 1 addition & 1 deletion db/memtable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "memory/memory_usage.h"
#include "monitoring/perf_context_imp.h"
#include "monitoring/statistics.h"
#include "port/lang.h"
#include "port/port.h"
#include "rocksdb/comparator.h"
#include "rocksdb/env.h"
Expand All @@ -36,7 +37,6 @@
#include "util/autovector.h"
#include "util/coding.h"
#include "util/mutexlock.h"
#include "port/lang.h"

namespace ROCKSDB_NAMESPACE {

Expand Down
8 changes: 2 additions & 6 deletions db/perf_context_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,7 @@ void ProfileQueries(bool enabled_time = false) {
}

if (FLAGS_random_key) {
std::random_device rng;
std::mt19937 urng(rng());
std::shuffle(std::begin(keys), std::end(keys), urng);
RandomShuffle(std::begin(keys), std::end(keys));
}
#ifndef NDEBUG
ThreadStatusUtil::TEST_SetStateDelay(ThreadStatus::STATE_MUTEX_WAIT, 1U);
Expand Down Expand Up @@ -526,9 +524,7 @@ TEST_F(PerfContextTest, SeekKeyComparison) {
}

if (FLAGS_random_key) {
std::random_device rng;
std::mt19937 urng(rng());
std::shuffle(std::begin(keys), std::end(keys), urng);
RandomShuffle(std::begin(keys), std::end(keys));
}

HistogramImpl hist_put_time;
Expand Down
2 changes: 1 addition & 1 deletion db/write_batch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@
#include "db/write_batch_internal.h"
#include "monitoring/perf_context_imp.h"
#include "monitoring/statistics.h"
#include "port/lang.h"
#include "rocksdb/merge_operator.h"
#include "util/autovector.h"
#include "util/cast_util.h"
#include "util/coding.h"
#include "util/duplicate_detector.h"
#include "util/string_util.h"
#include "port/lang.h"

namespace ROCKSDB_NAMESPACE {

Expand Down
5 changes: 2 additions & 3 deletions memtable/memtablerep_bench.cc
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,8 @@ class KeyGenerator {
for (uint64_t i = 0; i < num_; ++i) {
values_[i] = i;
}
std::shuffle(
values_.begin(), values_.end(),
std::default_random_engine(static_cast<unsigned int>(FLAGS_seed)));
RandomShuffle(values_.begin(), values_.end(),
static_cast<uint32_t>(FLAGS_seed));
}
}

Expand Down
2 changes: 1 addition & 1 deletion table/block_based/block_based_table_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@
#include "table/two_level_iterator.h"

#include "monitoring/perf_context_imp.h"
#include "port/lang.h"
#include "test_util/sync_point.h"
#include "util/coding.h"
#include "util/crc32c.h"
#include "util/stop_watch.h"
#include "util/string_util.h"
#include "port/lang.h"
#include "util/xxhash.h"

namespace ROCKSDB_NAMESPACE {
Expand Down
4 changes: 2 additions & 2 deletions test_util/transaction_test_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ bool RandomTransactionInserter::DoInsert(DB* db, Transaction* txn,

std::vector<uint16_t> set_vec(num_sets_);
std::iota(set_vec.begin(), set_vec.end(), static_cast<uint16_t>(0));
std::shuffle(set_vec.begin(), set_vec.end(), std::random_device{});
RandomShuffle(set_vec.begin(), set_vec.end());

// For each set, pick a key at random and increment it
for (uint16_t set_i : set_vec) {
Expand Down Expand Up @@ -296,7 +296,7 @@ Status RandomTransactionInserter::Verify(DB* db, uint16_t num_sets,

std::vector<uint16_t> set_vec(num_sets);
std::iota(set_vec.begin(), set_vec.end(), static_cast<uint16_t>(0));
std::shuffle(set_vec.begin(), set_vec.end(), std::random_device{});
RandomShuffle(set_vec.begin(), set_vec.end());

// For each set of keys with the same prefix, sum all the values
for (uint16_t set_i : set_vec) {
Expand Down
2 changes: 1 addition & 1 deletion third-party/folly/folly/synchronization/Baton.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <folly/synchronization/detail/Spin.h>

#ifdef ROCKSDB_EXPLICIT_CAPTURE_THIS
#define ROCKSDB_THIS_LAMBDA_CAPTURE =,this
#define ROCKSDB_THIS_LAMBDA_CAPTURE =, this
#else
#define ROCKSDB_THIS_LAMBDA_CAPTURE =
#endif
Expand Down
3 changes: 1 addition & 2 deletions tools/block_cache_analyzer/block_cache_trace_analyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,6 @@ void BlockCacheTraceAnalyzer::WriteCorrelationFeaturesToFile(
const std::map<std::string, Features>& label_features,
const std::map<std::string, Predictions>& label_predictions,
uint32_t max_number_of_values) const {
std::default_random_engine rand_engine(static_cast<std::default_random_engine::result_type>(env_->NowMicros()));
for (auto const& label_feature_vectors : label_features) {
const Features& past = label_feature_vectors.second;
auto it = label_predictions.find(label_feature_vectors.first);
Expand All @@ -674,7 +673,7 @@ void BlockCacheTraceAnalyzer::WriteCorrelationFeaturesToFile(
for (uint32_t i = 0; i < past.num_accesses_since_last_access.size(); i++) {
indexes.push_back(i);
}
std::shuffle(indexes.begin(), indexes.end(), rand_engine);
RandomShuffle(indexes.begin(), indexes.end());
for (uint32_t i = 0; i < max_number_of_values && i < indexes.size(); i++) {
uint32_t rand_index = indexes[i];
out << std::to_string(past.num_accesses_since_last_access[rand_index])
Expand Down
5 changes: 2 additions & 3 deletions tools/db_bench_tool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4313,9 +4313,8 @@ class Benchmark {
for (uint64_t i = 0; i < num_; ++i) {
values_[i] = i;
}
std::shuffle(
values_.begin(), values_.end(),
std::default_random_engine(static_cast<unsigned int>(FLAGS_seed)));
RandomShuffle(values_.begin(), values_.end(),
static_cast<uint32_t>(FLAGS_seed));
}
}

Expand Down
2 changes: 1 addition & 1 deletion util/crc32c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#include <nmmintrin.h>
#include <wmmintrin.h>
#endif
#include "util/coding.h"
#include "port/lang.h"
#include "util/coding.h"

#include "util/crc32c_arm64.h"

Expand Down
4 changes: 2 additions & 2 deletions util/hash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
// 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.

#include <string.h>
#include "util/coding.h"
#include "util/hash.h"
#include <string.h>
#include "port/lang.h"
#include "util/coding.h"
#include "util/xxhash.h"

namespace ROCKSDB_NAMESPACE {
Expand Down
14 changes: 14 additions & 0 deletions util/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#pragma once
#include <stdint.h>
#include <algorithm>
#include <random>

#include "rocksdb/rocksdb_namespace.h"
Expand Down Expand Up @@ -163,4 +164,17 @@ class Random64 {
}
};

// A seeded replacement for removed std::random_shuffle
template <class RandomIt>
void RandomShuffle(RandomIt first, RandomIt last, uint32_t seed) {
std::mt19937 rng(seed);
std::shuffle(first, last, rng);
}

// A replacement for removed std::random_shuffle
template <class RandomIt>
void RandomShuffle(RandomIt first, RandomIt last) {
RandomShuffle(first, last, std::random_device{}());
}

} // namespace ROCKSDB_NAMESPACE
5 changes: 1 addition & 4 deletions utilities/transactions/write_unprepared_transaction_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,6 @@ TEST_P(WriteUnpreparedStressTest, ReadYourOwnWriteStress) {
const uint32_t kNumThreads = 10;
const uint32_t kNumKeys = 5;

std::default_random_engine rand(static_cast<uint32_t>(
std::hash<std::thread::id>()(std::this_thread::get_id())));

// Test with
// 1. no snapshots set
// 2. snapshot set on ReadOptions
Expand All @@ -164,7 +161,7 @@ TEST_P(WriteUnpreparedStressTest, ReadYourOwnWriteStress) {
for (uint32_t k = 0; k < kNumKeys * kNumThreads; k++) {
keys.push_back("k" + ToString(k));
}
std::shuffle(keys.begin(), keys.end(), rand);
RandomShuffle(keys.begin(), keys.end());

// This counter will act as a "sequence number" to help us validate
// visibility logic with snapshots. If we had direct access to the seqno of
Expand Down