internal_repo_rocksdb (435146444452818992) (#12115)

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

Reviewed By: jowlyzhang

Differential Revision: D51745742

Pulled By: ajkr

fbshipit-source-id: 67000d07783b413924798dd9c1751da27e119d53
This commit is contained in:
Andrew Kryczka 2023-12-01 11:15:17 -08:00 committed by Facebook GitHub Bot
parent be3bc36811
commit 06dc32ef25
35 changed files with 281 additions and 207 deletions

View File

@ -43,7 +43,7 @@ CuckooTableReader::CuckooTableReader(
identity_as_first_hash_(false),
use_module_hash_(false),
num_hash_func_(0),
unused_key_(""),
key_length_(0),
user_key_length_(0),
value_length_(0),
@ -182,7 +182,9 @@ Status CuckooTableReader::Get(const ReadOptions& /*readOptions*/,
ParsedInternalKey found_ikey;
Status s = ParseInternalKey(full_key, &found_ikey,
false /* log_err_key */); // TODO
if (!s.ok()) return s;
if (!s.ok()) {
return s;
}
bool dont_care __attribute__((__unused__));
get_context->SaveValue(found_ikey, value, &dont_care);
}
@ -213,7 +215,7 @@ class CuckooTableIterator : public InternalIterator {
// No copying allowed
CuckooTableIterator(const CuckooTableIterator&) = delete;
void operator=(const Iterator&) = delete;
~CuckooTableIterator() override {}
~CuckooTableIterator() override = default;
bool Valid() const override;
void SeekToFirst() override;
void SeekToLast() override;

View File

@ -249,7 +249,7 @@ TEST_F(CuckooReaderTest, WhenKeyExistsWithUint64Comparator) {
fname = test::PerThreadDBPath("CuckooReaderUint64_WhenKeyExists");
for (uint64_t i = 0; i < num_items; i++) {
user_keys[i].resize(8);
memcpy(&user_keys[i][0], static_cast<void*>(&i), 8);
memcpy(user_keys[i].data(), static_cast<void*>(&i), 8);
ParsedInternalKey ikey(user_keys[i], i + 1000, kTypeValue);
AppendInternalKey(&keys[i], ikey);
values[i] = "value" + NumToStr(i);
@ -296,7 +296,7 @@ TEST_F(CuckooReaderTest, CheckIteratorUint64) {
fname = test::PerThreadDBPath("CuckooReader_CheckIterator");
for (uint64_t i = 0; i < num_items; i++) {
user_keys[i].resize(8);
memcpy(&user_keys[i][0], static_cast<void*>(&i), 8);
memcpy(user_keys[i].data(), static_cast<void*>(&i), 8);
ParsedInternalKey ikey(user_keys[i], 1000, kTypeValue);
AppendInternalKey(&keys[i], ikey);
values[i] = "value" + NumToStr(i);
@ -425,7 +425,7 @@ void WriteFile(const std::vector<std::string>& keys, const uint64_t num,
ASSERT_OK(builder.status());
for (uint64_t key_idx = 0; key_idx < num; ++key_idx) {
// Value is just a part of key.
builder.Add(Slice(keys[key_idx]), Slice(&keys[key_idx][0], 4));
builder.Add(Slice(keys[key_idx]), Slice(keys[key_idx].data(), 4));
ASSERT_EQ(builder.NumEntries(), key_idx + 1);
ASSERT_OK(builder.status());
}
@ -454,7 +454,7 @@ void WriteFile(const std::vector<std::string>& keys, const uint64_t num,
value.Reset();
value.clear();
ASSERT_OK(reader.Get(r_options, Slice(keys[i]), &get_context, nullptr));
ASSERT_TRUE(Slice(keys[i]) == Slice(&keys[i][0], 4));
ASSERT_TRUE(Slice(keys[i]) == Slice(keys[i].data(), 4));
}
}

View File

@ -390,7 +390,7 @@ Status Footer::DecodeFrom(Slice input, uint64_t input_offset,
if (checksum_type_ != kNoChecksum && format_version_ >= 6) {
std::array<char, kNewVersionsEncodedLength> copy_without_checksum;
std::copy_n(input.data(), kNewVersionsEncodedLength,
&copy_without_checksum[0]);
copy_without_checksum.data());
EncodeFixed32(&copy_without_checksum[5], 0); // Clear embedded checksum
computed_checksum =
ComputeBuiltinChecksum(checksum_type(), copy_without_checksum.data(),
@ -518,9 +518,11 @@ Status ReadFooterFromFile(const IOOptions& opts, RandomAccessFileReader* file,
} else {
footer_buf.reserve(Footer::kMaxEncodedLength);
s = file->Read(opts, read_offset, Footer::kMaxEncodedLength,
&footer_input, &footer_buf[0], nullptr);
&footer_input, footer_buf.data(), nullptr);
}
if (!s.ok()) {
return s;
}
if (!s.ok()) return s;
}
// Check that we actually read the whole footer from the file. It may be

View File

@ -107,7 +107,7 @@ class MergerTest : public testing::Test {
}
merging_iterator_.reset(
NewMergingIterator(&icomp_, &small_iterators[0],
NewMergingIterator(&icomp_, small_iterators.data(),
static_cast<int>(small_iterators.size())));
single_iterator_.reset(new VectorIterator(all_keys_, all_keys_, &icomp_));
}

View File

@ -59,7 +59,7 @@ class MockTableReader : public TableReader {
std::shared_ptr<const TableProperties> GetTableProperties() const override;
~MockTableReader() {}
~MockTableReader() = default;
private:
const KVVector& table_;
@ -134,7 +134,7 @@ class MockTableBuilder : public TableBuilder {
}
// REQUIRES: Either Finish() or Abandon() has been called.
~MockTableBuilder() {}
~MockTableBuilder() = default;
// Add key,value to the table being constructed.
// REQUIRES: key is after any previously added key according to comparator.

View File

@ -5,8 +5,7 @@
#include "table/plain/plain_table_builder.h"
#include <assert.h>
#include <cassert>
#include <limits>
#include <map>
#include <string>

View File

@ -5,8 +5,7 @@
#include "table/plain/plain_table_factory.h"
#include <stdint.h>
#include <cstdint>
#include <memory>
#include "db/dbformat.h"
@ -157,7 +156,7 @@ static int RegisterBuiltinMemTableRepFactory(ObjectLibrary& library,
AsPattern(VectorRepFactory::kClassName(), VectorRepFactory::kNickName()),
[](const std::string& uri, std::unique_ptr<MemTableRepFactory>* guard,
std::string* /*errmsg*/) {
auto colon = uri.find(":");
auto colon = uri.find(':');
if (colon != std::string::npos) {
size_t count = ParseSizeT(uri.substr(colon + 1));
guard->reset(new VectorRepFactory(count));
@ -170,7 +169,7 @@ static int RegisterBuiltinMemTableRepFactory(ObjectLibrary& library,
AsPattern(SkipListFactory::kClassName(), SkipListFactory::kNickName()),
[](const std::string& uri, std::unique_ptr<MemTableRepFactory>* guard,
std::string* /*errmsg*/) {
auto colon = uri.find(":");
auto colon = uri.find(':');
if (colon != std::string::npos) {
size_t lookahead = ParseSizeT(uri.substr(colon + 1));
guard->reset(new SkipListFactory(lookahead));
@ -184,7 +183,7 @@ static int RegisterBuiltinMemTableRepFactory(ObjectLibrary& library,
[](const std::string& uri, std::unique_ptr<MemTableRepFactory>* guard,
std::string* /*errmsg*/) {
// Expecting format: hash_linkedlist:<hash_bucket_count>
auto colon = uri.find(":");
auto colon = uri.find(':');
if (colon != std::string::npos) {
size_t hash_bucket_count = ParseSizeT(uri.substr(colon + 1));
guard->reset(NewHashLinkListRepFactory(hash_bucket_count));
@ -198,7 +197,7 @@ static int RegisterBuiltinMemTableRepFactory(ObjectLibrary& library,
[](const std::string& uri, std::unique_ptr<MemTableRepFactory>* guard,
std::string* /*errmsg*/) {
// Expecting format: prefix_hash:<hash_bucket_count>
auto colon = uri.find(":");
auto colon = uri.find(':');
if (colon != std::string::npos) {
size_t hash_bucket_count = ParseSizeT(uri.substr(colon + 1));
guard->reset(NewHashSkipListRepFactory(hash_bucket_count));

View File

@ -454,7 +454,9 @@ Status PlainTableReader::GetOffset(PlainTableKeyDecoder* decoder,
ParsedInternalKey parsed_target;
Status s = ParseInternalKey(target, &parsed_target,
false /* log_err_key */); // TODO
if (!s.ok()) return s;
if (!s.ok()) {
return s;
}
// The key is between [low, high). Do a binary search between it.
while (high - low > 1) {
@ -591,7 +593,9 @@ Status PlainTableReader::Get(const ReadOptions& /*ro*/, const Slice& target,
ParsedInternalKey parsed_target;
s = ParseInternalKey(target, &parsed_target,
false /* log_err_key */); // TODO
if (!s.ok()) return s;
if (!s.ok()) {
return s;
}
Slice found_value;
while (offset < file_info_.data_end_offset) {
@ -642,7 +646,7 @@ PlainTableIterator::PlainTableIterator(PlainTableReader* table,
next_offset_ = offset_ = table_->file_info_.data_end_offset;
}
PlainTableIterator::~PlainTableIterator() {}
PlainTableIterator::~PlainTableIterator() = default;
bool PlainTableIterator::Valid() const {
return offset_ < table_->file_info_.data_end_offset &&

View File

@ -495,7 +495,9 @@ Status SstFileDumper::ReadSequential(bool print_kv, uint64_t read_num,
Slice key = iter->key();
Slice value = iter->value();
++i;
if (read_num > 0 && i > read_num) break;
if (read_num > 0 && i > read_num) {
break;
}
ParsedInternalKey ikey;
Status pik_status = ParseInternalKey(key, &ikey, true /* log_err_key */);

View File

@ -36,7 +36,7 @@ struct SstFileReader::Rep {
SstFileReader::SstFileReader(const Options& options) : rep_(new Rep(options)) {}
SstFileReader::~SstFileReader() {}
SstFileReader::~SstFileReader() = default;
Status SstFileReader::Open(const std::string& file_path) {
auto r = rep_.get();

View File

@ -10,10 +10,10 @@
#include "rocksdb/table.h"
#include <gtest/gtest.h>
#include <stddef.h>
#include <stdio.h>
#include <algorithm>
#include <cstddef>
#include <cstdio>
#include <iostream>
#include <map>
#include <memory>
@ -186,7 +186,7 @@ class Constructor {
public:
explicit Constructor(const Comparator* cmp)
: data_(stl_wrappers::LessOfComparator(cmp)) {}
virtual ~Constructor() {}
virtual ~Constructor() = default;
void Add(const std::string& key, const Slice& value) {
data_[key] = value.ToString();
@ -295,8 +295,8 @@ class KeyConvertingIterator : public InternalIterator {
bool arena_mode_;
// No copying allowed
KeyConvertingIterator(const KeyConvertingIterator&);
void operator=(const KeyConvertingIterator&);
KeyConvertingIterator(const KeyConvertingIterator&) = delete;
void operator=(const KeyConvertingIterator&) = delete;
};
// `BlockConstructor` APIs always accept/return user keys.
@ -345,7 +345,7 @@ class BlockConstructor : public Constructor {
std::string data_;
Block* block_;
BlockConstructor();
BlockConstructor() = delete;
};
class TableConstructor : public Constructor {
@ -487,7 +487,7 @@ class TableConstructor : public Constructor {
bool convert_to_internal_key_;
int level_;
TableConstructor();
TableConstructor() = delete;
static uint64_t cur_file_num_;
EnvOptions soptions;
@ -930,13 +930,17 @@ class HarnessTest : public testing::Test {
InternalIterator* iter = constructor_->NewIterator();
ASSERT_TRUE(!iter->Valid());
stl_wrappers::KVMap::const_iterator model_iter = data.begin();
if (kVerbose) fprintf(stderr, "---\n");
if (kVerbose) {
fprintf(stderr, "---\n");
}
for (int i = 0; i < 200; i++) {
const int toss = rnd->Uniform(support_prev_ ? 5 : 3);
switch (toss) {
case 0: {
if (iter->Valid()) {
if (kVerbose) fprintf(stderr, "Next\n");
if (kVerbose) {
fprintf(stderr, "Next\n");
}
iter->Next();
ASSERT_OK(iter->status());
++model_iter;
@ -946,7 +950,9 @@ class HarnessTest : public testing::Test {
}
case 1: {
if (kVerbose) fprintf(stderr, "SeekToFirst\n");
if (kVerbose) {
fprintf(stderr, "SeekToFirst\n");
}
iter->SeekToFirst();
ASSERT_OK(iter->status());
model_iter = data.begin();
@ -957,8 +963,9 @@ class HarnessTest : public testing::Test {
case 2: {
std::string key = PickRandomKey(rnd, keys);
model_iter = data.lower_bound(key);
if (kVerbose)
if (kVerbose) {
fprintf(stderr, "Seek '%s'\n", EscapeString(key).c_str());
}
iter->Seek(Slice(key));
ASSERT_OK(iter->status());
ASSERT_EQ(ToString(data, model_iter), ToString(iter));
@ -967,7 +974,9 @@ class HarnessTest : public testing::Test {
case 3: {
if (iter->Valid()) {
if (kVerbose) fprintf(stderr, "Prev\n");
if (kVerbose) {
fprintf(stderr, "Prev\n");
}
iter->Prev();
ASSERT_OK(iter->status());
if (model_iter == data.begin()) {
@ -981,7 +990,9 @@ class HarnessTest : public testing::Test {
}
case 4: {
if (kVerbose) fprintf(stderr, "SeekToLast\n");
if (kVerbose) {
fprintf(stderr, "SeekToLast\n");
}
iter->SeekToLast();
ASSERT_OK(iter->status());
if (keys.empty()) {
@ -1253,7 +1264,7 @@ class FileChecksumTestHelper {
public:
FileChecksumTestHelper(bool convert_to_internal_key = false)
: convert_to_internal_key_(convert_to_internal_key) {}
~FileChecksumTestHelper() {}
~FileChecksumTestHelper() = default;
void CreateWritableFile() {
sink_ = new test::StringSink();
@ -1437,7 +1448,7 @@ TestIds GetUniqueId(TableProperties* tp, std::unordered_set<uint64_t>* seen,
std::string euid;
EXPECT_OK(GetExtendedUniqueIdFromTableProperties(*tp, &euid));
EXPECT_EQ(euid.size(), 24U);
t.external_id[0] = DecodeFixed64(&euid[0]);
t.external_id[0] = DecodeFixed64(euid.data());
t.external_id[1] = DecodeFixed64(&euid[8]);
t.external_id[2] = DecodeFixed64(&euid[16]);
@ -1445,7 +1456,7 @@ TestIds GetUniqueId(TableProperties* tp, std::unordered_set<uint64_t>* seen,
EXPECT_OK(GetUniqueIdFromTableProperties(*tp, &uid));
EXPECT_EQ(uid.size(), 16U);
EXPECT_EQ(uid, euid.substr(0, 16));
EXPECT_EQ(t.external_id[0], DecodeFixed64(&uid[0]));
EXPECT_EQ(t.external_id[0], DecodeFixed64(uid.data()));
EXPECT_EQ(t.external_id[1], DecodeFixed64(&uid[8]));
}
// All these should be effectively random
@ -1930,19 +1941,19 @@ void AssertKeysInCache(BlockBasedTable* table_reader,
const std::vector<std::string>& keys_not_in_cache,
bool convert = false) {
if (convert) {
for (auto key : keys_in_cache) {
for (const auto& key : keys_in_cache) {
InternalKey ikey(key, kMaxSequenceNumber, kTypeValue);
ASSERT_TRUE(table_reader->TEST_KeyInCache(ReadOptions(), ikey.Encode()));
}
for (auto key : keys_not_in_cache) {
for (const auto& key : keys_not_in_cache) {
InternalKey ikey(key, kMaxSequenceNumber, kTypeValue);
ASSERT_TRUE(!table_reader->TEST_KeyInCache(ReadOptions(), ikey.Encode()));
}
} else {
for (auto key : keys_in_cache) {
for (const auto& key : keys_in_cache) {
ASSERT_TRUE(table_reader->TEST_KeyInCache(ReadOptions(), key));
}
for (auto key : keys_not_in_cache) {
for (const auto& key : keys_not_in_cache) {
ASSERT_TRUE(!table_reader->TEST_KeyInCache(ReadOptions(), key));
}
}
@ -3246,8 +3257,8 @@ TEST_P(BlockBasedTableTest, TracingMultiGetTest) {
std::vector<GetContext> get_contexts;
get_contexts.emplace_back(
options.comparator, nullptr, nullptr, nullptr, GetContext::kNotFound,
ukeys[0], &values[0], nullptr, nullptr, nullptr, true, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr, get_id_offset);
ukeys[0], values.data(), nullptr, nullptr, nullptr, true, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr, get_id_offset);
get_contexts.emplace_back(
options.comparator, nullptr, nullptr, nullptr, GetContext::kNotFound,
ukeys[1], &values[1], nullptr, nullptr, nullptr, true, nullptr, nullptr,
@ -3258,12 +3269,12 @@ TEST_P(BlockBasedTableTest, TracingMultiGetTest) {
std::array<Status, 2> statuses;
autovector<KeyContext, MultiGetContext::MAX_BATCH_SIZE> key_context;
key_context.emplace_back(/*ColumnFamilyHandle omitted*/ nullptr, ukeys[0],
&values[0],
values.data(),
/*PinnableWideColumns omitted*/ nullptr,
/*timestamp omitted*/ nullptr, &statuses[0]);
/*timestamp omitted*/ nullptr, statuses.data());
key_context[0].ukey_without_ts = ukeys[0];
key_context[0].ikey = encoded_keys[0];
key_context[0].get_context = &get_contexts[0];
key_context[0].get_context = get_contexts.data();
key_context.emplace_back(/*ColumnFamilyHandle omitted*/ nullptr, ukeys[1],
&values[1],
/*PinnableWideColumns omitted*/ nullptr,
@ -4660,14 +4671,15 @@ TEST_P(IndexBlockRestartIntervalTest, IndexBlockRestartInterval) {
class PrefixTest : public testing::Test {
public:
PrefixTest() : testing::Test() {}
~PrefixTest() override {}
~PrefixTest() override = default;
};
namespace {
// A simple PrefixExtractor that only works for test PrefixAndWholeKeyTest
class TestPrefixExtractor : public ROCKSDB_NAMESPACE::SliceTransform {
public:
~TestPrefixExtractor() override{};
~TestPrefixExtractor() override = default;
;
const char* Name() const override { return "TestPrefixExtractor"; }
ROCKSDB_NAMESPACE::Slice Transform(

View File

@ -70,7 +70,9 @@ class TwoLevelIndexIterator : public InternalIteratorBase<IndexValue> {
private:
void SaveError(const Status& s) {
if (status_.ok() && !s.ok()) status_ = s;
if (status_.ok() && !s.ok()) {
status_ = s;
}
}
void SkipEmptyDataBlocksForward();
void SkipEmptyDataBlocksBackward();

View File

@ -14,7 +14,7 @@ namespace ROCKSDB_NAMESPACE {
std::string EncodeSessionId(uint64_t upper, uint64_t lower) {
std::string db_session_id(20U, '\0');
char *buf = &db_session_id[0];
char *buf = db_session_id.data();
// Preserving `lower` is slightly tricky. 36^12 is slightly more than
// 62 bits, so we use 12 chars plus the bottom two bits of one more.
// (A tiny fraction of 20 digit strings go unused.)
@ -152,7 +152,7 @@ void ExternalUniqueIdToInternal(UniqueIdPtr in_out) {
std::string EncodeUniqueIdBytes(UniqueIdPtr in) {
std::string ret(in.extended ? 24U : 16U, '\0');
EncodeFixed64(&ret[0], in.ptr[0]);
EncodeFixed64(ret.data(), in.ptr[0]);
EncodeFixed64(&ret[8], in.ptr[1]);
if (in.extended) {
EncodeFixed64(&ret[16], in.ptr[2]);

View File

@ -94,7 +94,9 @@ bool ShouldPersistUDT(const UserDefinedTimestampTestMode& test_mode) {
extern Slice CompressibleString(Random* rnd, double compressed_fraction,
int len, std::string* dst) {
int raw = static_cast<int>(len * compressed_fraction);
if (raw < 1) raw = 1;
if (raw < 1) {
raw = 1;
}
std::string raw_data = rnd->RandomBinaryString(raw);
// Duplicate the random data until we have filled "len" bytes
@ -109,7 +111,7 @@ extern Slice CompressibleString(Random* rnd, double compressed_fraction,
namespace {
class Uint64ComparatorImpl : public Comparator {
public:
Uint64ComparatorImpl() {}
Uint64ComparatorImpl() = default;
const char* Name() const override { return "rocksdb.Uint64Comparator"; }
@ -131,11 +133,9 @@ class Uint64ComparatorImpl : public Comparator {
}
void FindShortestSeparator(std::string* /*start*/,
const Slice& /*limit*/) const override {
return;
}
const Slice& /*limit*/) const override {}
void FindShortSuccessor(std::string* /*key*/) const override { return; }
void FindShortSuccessor(std::string* /*key*/) const override {}
};
} // namespace
@ -632,7 +632,7 @@ class SpecialMemTableRep : public MemTableRep {
return memtable_->GetIterator(arena);
}
virtual ~SpecialMemTableRep() override {}
virtual ~SpecialMemTableRep() override = default;
private:
std::unique_ptr<MemTableRep> memtable_;
@ -647,7 +647,7 @@ class SpecialSkipListFactory : public MemTableRepFactory {
.AddNumber(":"),
[](const std::string& uri, std::unique_ptr<MemTableRepFactory>* guard,
std::string* /* errmsg */) {
auto colon = uri.find(":");
auto colon = uri.find(':');
if (colon != std::string::npos) {
auto count = ParseInt(uri.substr(colon + 1));
guard->reset(new SpecialSkipListFactory(count));

View File

@ -577,7 +577,7 @@ void BlockCacheTraceAnalyzer::WriteSkewness(
std::map<std::string, std::map<uint64_t, uint64_t>> label_bucket_naccesses;
std::vector<std::pair<std::string, uint64_t>> pairs;
for (auto const& itr : label_naccesses) {
pairs.push_back(itr);
pairs.emplace_back(itr);
}
// Sort in descending order.
sort(pairs.begin(), pairs.end(),

View File

@ -492,7 +492,7 @@ TEST_F(BlockCacheTracerTest, BlockCacheAnalyzer) {
ASSERT_EQ(20, ParseDouble(percent));
}
ASSERT_EQ(expected_callers.size(), callers.size());
for (auto caller : callers) {
for (const auto& caller : callers) {
ASSERT_TRUE(expected_callers.find(caller) != expected_callers.end());
}
ASSERT_OK(env_->DeleteFile(percent_access_summary_file));
@ -504,7 +504,7 @@ TEST_F(BlockCacheTracerTest, BlockCacheAnalyzer) {
std::string caller;
ASSERT_TRUE(getline(analyzing_callers, caller, ','));
std::vector<std::string> breakdowns{"level", "bt"};
for (auto breakdown : breakdowns) {
for (const auto& breakdown : breakdowns) {
const std::string file_name = test_path_ + "/" + caller + "_" +
breakdown +
"_percentage_of_accesses_summary";
@ -554,7 +554,7 @@ TEST_F(BlockCacheTracerTest, BlockCacheAnalyzer) {
}
for (auto const& access_type : access_types) {
std::vector<std::string> block_types{"Index", "Data", "Filter"};
for (auto block_type : block_types) {
for (const auto& block_type : block_types) {
// Validate reuse block timeline.
const std::string reuse_blocks_timeline = test_path_ + "/" + block_type +
"_" + access_type +

View File

@ -15,9 +15,10 @@
#include <unistd.h>
#endif
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <cstdio>
#include <cstdlib>
#ifdef __APPLE__
#include <mach/host_info.h>
#include <mach/mach_host.h>
@ -1258,23 +1259,23 @@ static enum ROCKSDB_NAMESPACE::CompressionType StringToCompressionType(
const char* ctype) {
assert(ctype);
if (!strcasecmp(ctype, "none"))
if (!strcasecmp(ctype, "none")) {
return ROCKSDB_NAMESPACE::kNoCompression;
else if (!strcasecmp(ctype, "snappy"))
} else if (!strcasecmp(ctype, "snappy")) {
return ROCKSDB_NAMESPACE::kSnappyCompression;
else if (!strcasecmp(ctype, "zlib"))
} else if (!strcasecmp(ctype, "zlib")) {
return ROCKSDB_NAMESPACE::kZlibCompression;
else if (!strcasecmp(ctype, "bzip2"))
} else if (!strcasecmp(ctype, "bzip2")) {
return ROCKSDB_NAMESPACE::kBZip2Compression;
else if (!strcasecmp(ctype, "lz4"))
} else if (!strcasecmp(ctype, "lz4")) {
return ROCKSDB_NAMESPACE::kLZ4Compression;
else if (!strcasecmp(ctype, "lz4hc"))
} else if (!strcasecmp(ctype, "lz4hc")) {
return ROCKSDB_NAMESPACE::kLZ4HCCompression;
else if (!strcasecmp(ctype, "xpress"))
} else if (!strcasecmp(ctype, "xpress")) {
return ROCKSDB_NAMESPACE::kXpressCompression;
else if (!strcasecmp(ctype, "zstd"))
} else if (!strcasecmp(ctype, "zstd")) {
return ROCKSDB_NAMESPACE::kZSTD;
else {
} else {
fprintf(stderr, "Cannot parse compression type '%s'\n", ctype);
exit(1);
}
@ -1284,15 +1285,15 @@ static enum ROCKSDB_NAMESPACE::TieredAdmissionPolicy StringToAdmissionPolicy(
const char* policy) {
assert(policy);
if (!strcasecmp(policy, "auto"))
if (!strcasecmp(policy, "auto")) {
return ROCKSDB_NAMESPACE::kAdmPolicyAuto;
else if (!strcasecmp(policy, "placeholder"))
} else if (!strcasecmp(policy, "placeholder")) {
return ROCKSDB_NAMESPACE::kAdmPolicyPlaceholder;
else if (!strcasecmp(policy, "allow_cache_hits"))
} else if (!strcasecmp(policy, "allow_cache_hits")) {
return ROCKSDB_NAMESPACE::kAdmPolicyAllowCacheHits;
else if (!strcasecmp(policy, "three_queue"))
} else if (!strcasecmp(policy, "three_queue")) {
return ROCKSDB_NAMESPACE::kAdmPolicyThreeQueue;
else {
} else {
fprintf(stderr, "Cannot parse admission policy %s\n", policy);
exit(1);
}
@ -1806,12 +1807,13 @@ static enum DistributionType FLAGS_value_size_distribution_type_e = kFixed;
static enum DistributionType StringToDistributionType(const char* ctype) {
assert(ctype);
if (!strcasecmp(ctype, "fixed"))
if (!strcasecmp(ctype, "fixed")) {
return kFixed;
else if (!strcasecmp(ctype, "uniform"))
} else if (!strcasecmp(ctype, "uniform")) {
return kUniform;
else if (!strcasecmp(ctype, "normal"))
} else if (!strcasecmp(ctype, "normal")) {
return kNormal;
}
fprintf(stdout, "Cannot parse distribution type '%s'\n", ctype);
exit(1);
@ -1821,7 +1823,7 @@ class BaseDistribution {
public:
BaseDistribution(unsigned int _min, unsigned int _max)
: min_value_size_(_min), max_value_size_(_max) {}
virtual ~BaseDistribution() {}
virtual ~BaseDistribution() = default;
unsigned int Generate() {
auto val = Get();
@ -1938,7 +1940,9 @@ class RandomGenerator {
};
static void AppendWithSpace(std::string* str, Slice msg) {
if (msg.empty()) return;
if (msg.empty()) {
return;
}
if (!str->empty()) {
str->push_back(' ');
}
@ -2192,7 +2196,9 @@ class Stats {
}
void Merge(const Stats& other) {
if (other.exclude_from_merge_) return;
if (other.exclude_from_merge_) {
return;
}
for (auto it = other.hist_.begin(); it != other.hist_.end(); ++it) {
auto this_it = hist_.find(it->first);
@ -2206,11 +2212,17 @@ class Stats {
done_ += other.done_;
bytes_ += other.bytes_;
seconds_ += other.seconds_;
if (other.start_ < start_) start_ = other.start_;
if (other.finish_ > finish_) finish_ = other.finish_;
if (other.start_ < start_) {
start_ = other.start_;
}
if (other.finish_ > finish_) {
finish_ = other.finish_;
}
// Just keep the messages from one thread.
if (message_.empty()) message_ = other.message_;
if (message_.empty()) {
message_ = other.message_;
}
}
void Stop() {
@ -2289,20 +2301,21 @@ class Stats {
done_ += num_ops;
if (done_ >= next_report_ && FLAGS_progress_reports) {
if (!FLAGS_stats_interval) {
if (next_report_ < 1000)
if (next_report_ < 1000) {
next_report_ += 100;
else if (next_report_ < 5000)
} else if (next_report_ < 5000) {
next_report_ += 500;
else if (next_report_ < 10000)
} else if (next_report_ < 10000) {
next_report_ += 1000;
else if (next_report_ < 50000)
} else if (next_report_ < 50000) {
next_report_ += 5000;
else if (next_report_ < 100000)
} else if (next_report_ < 100000) {
next_report_ += 10000;
else if (next_report_ < 500000)
} else if (next_report_ < 500000) {
next_report_ += 50000;
else
} else {
next_report_ += 100000;
}
fprintf(stderr, "... finished %" PRIu64 " ops%30s\r", done_, "");
} else {
uint64_t now = clock_->NowMicros();
@ -2334,8 +2347,9 @@ class Stats {
if (db_with_cfh && db_with_cfh->num_created.load()) {
for (size_t i = 0; i < db_with_cfh->num_created.load(); ++i) {
if (db->GetProperty(db_with_cfh->cfh[i], "rocksdb.cfstats",
&stats))
&stats)) {
fprintf(stderr, "%s\n", stats.c_str());
}
if (FLAGS_show_table_properties) {
for (int level = 0; level < FLAGS_num_levels; ++level) {
if (db->GetProperty(
@ -2393,7 +2407,9 @@ class Stats {
void Report(const Slice& name) {
// Pretend at least one op was done in case we are running a benchmark
// that does not call FinishedOps().
if (done_ < 1) done_ = 1;
if (done_ < 1) {
done_ = 1;
}
std::string extra;
double elapsed = (finish_ - start_) * 1e-6;
@ -2658,7 +2674,9 @@ class Duration {
int64_t GetStage() { return std::min(ops_, max_ops_ - 1) / ops_per_stage_; }
bool Done(int64_t increment) {
if (increment <= 0) increment = 1; // avoid Done(0) and infinite loops
if (increment <= 0) {
increment = 1; // avoid Done(0) and infinite loops
}
ops_ += increment;
if (max_seconds_) {
@ -2725,7 +2743,7 @@ class Benchmark {
no_auto_recovery_(false),
recovery_complete_(false) {}
~ErrorHandlerListener() override {}
~ErrorHandlerListener() override = default;
const char* Name() const override { return kClassName(); }
static const char* kClassName() { return "ErrorHandlerListener"; }
@ -4056,7 +4074,9 @@ class Benchmark {
count++;
thread->stats.FinishedOps(nullptr, nullptr, 1, kOthers);
}
if (ptr == nullptr) exit(1); // Disable unused variable warning.
if (ptr == nullptr) {
exit(1); // Disable unused variable warning.
}
}
void Compress(ThreadState* thread) {
@ -4836,8 +4856,8 @@ class Benchmark {
}
std::vector<ColumnFamilyDescriptor> column_families;
for (size_t i = 0; i < num_hot; i++) {
column_families.push_back(ColumnFamilyDescriptor(
ColumnFamilyName(i), ColumnFamilyOptions(options)));
column_families.emplace_back(ColumnFamilyName(i),
ColumnFamilyOptions(options));
}
std::vector<int> cfh_idx_to_prob;
if (!FLAGS_column_family_distribution.empty()) {
@ -5660,7 +5680,7 @@ class Benchmark {
auto total_size = meta.levels[0].size;
if (total_size >=
db->GetOptions().compaction_options_fifo.max_table_files_size) {
for (auto file_meta : meta.levels[0].files) {
for (const auto& file_meta : meta.levels[0].files) {
file_names.emplace_back(file_meta.name);
}
break;
@ -5711,7 +5731,7 @@ class Benchmark {
SequenceNumber sorted_run_largest_seqno = 0;
std::string sorted_run_smallest_key, sorted_run_largest_key;
bool first_key = true;
for (auto fileMeta : sorted_runs[k][i]) {
for (const auto& fileMeta : sorted_runs[k][i]) {
sorted_run_smallest_seqno =
std::min(sorted_run_smallest_seqno, fileMeta.smallest_seqno);
sorted_run_largest_seqno =
@ -5732,7 +5752,7 @@ class Benchmark {
(compaction_style == kCompactionStyleUniversal && level > 0)) {
SequenceNumber level_smallest_seqno = kMaxSequenceNumber;
SequenceNumber level_largest_seqno = 0;
for (auto fileMeta : meta.levels[level].files) {
for (const auto& fileMeta : meta.levels[level].files) {
level_smallest_seqno =
std::min(level_smallest_seqno, fileMeta.smallest_seqno);
level_largest_seqno =
@ -6254,8 +6274,8 @@ class Benchmark {
GenerateKeyFromInt(lkey, FLAGS_num, &lkeys[i]);
GenerateKeyFromInt(rkey, FLAGS_num, &rkeys[i]);
}
db->GetApproximateSizes(&ranges[0], static_cast<int>(entries_per_batch_),
&sizes[0]);
db->GetApproximateSizes(
ranges.data(), static_cast<int>(entries_per_batch_), sizes.data());
num_sizes += entries_per_batch_;
for (int64_t size : sizes) {
size_sum += size;
@ -6308,8 +6328,8 @@ class Benchmark {
std::vector<double> ratio_;
int range_;
QueryDecider() {}
~QueryDecider() {}
QueryDecider() = default;
~QueryDecider() = default;
Status Initiate(std::vector<double> ratio_input) {
int range_max = 1000;
@ -7652,7 +7672,9 @@ class Benchmark {
thread->stats.FinishedOps(nullptr, db, 1, kMerge);
} else {
Status s = db->Get(read_options_, key, &value);
if (value.length() > max_length) max_length = value.length();
if (value.length() > max_length) {
max_length = value.length();
}
if (!s.ok() && !s.IsNotFound()) {
fprintf(stderr, "get error: %s\n", s.ToString().c_str());
@ -7717,10 +7739,16 @@ class Benchmark {
}
bool binary_search(std::vector<int>& data, int start, int end, int key) {
if (data.empty()) return false;
if (start > end) return false;
if (data.empty()) {
return false;
}
if (start > end) {
return false;
}
int mid = start + (end - start) / 2;
if (mid > static_cast<int>(data.size()) - 1) return false;
if (mid > static_cast<int>(data.size()) - 1) {
return false;
}
if (data[mid] == key) {
return true;
} else if (data[mid] > key) {
@ -7793,7 +7821,9 @@ class Benchmark {
found =
binary_search(data, 0, static_cast<int>(data.size() - 1), lookup_key);
data.clear();
if (found) break;
if (found) {
break;
}
}
std::cout << "Found key? " << std::to_string(found) << "\n";
sp = FLAGS_env->NowNanos();
@ -7803,7 +7833,9 @@ class Benchmark {
std::cout << "Sample data from GetMergeOperands API call: ";
for (PinnableSlice& psl : a_slice) {
std::cout << "List: " << to_print << " : " << *psl.GetSelf() << "\n";
if (to_print++ > 2) break;
if (to_print++ > 2) {
break;
}
}
}
@ -8217,7 +8249,9 @@ class Benchmark {
real_from_level = std::numeric_limits<int>::max();
for (auto& f : files) {
if (f.level > 0 && f.level < real_from_level) real_from_level = f.level;
if (f.level > 0 && f.level < real_from_level) {
real_from_level = f.level;
}
}
if (real_from_level == std::numeric_limits<int>::max()) {
@ -8233,10 +8267,11 @@ class Benchmark {
std::vector<std::string> files_to_compact;
for (auto& f : files) {
if (f.level == real_from_level)
if (f.level == real_from_level) {
files_to_compact.push_back(f.name);
else if (f.level > real_from_level && f.level < next_level)
} else if (f.level > real_from_level && f.level < next_level) {
next_level = f.level;
}
}
if (files_to_compact.empty()) {
@ -8277,10 +8312,14 @@ class Benchmark {
void CompactLevel(int from_level) {
if (db_.db != nullptr) {
while (!CompactLevelHelper(db_, from_level)) WaitForCompaction();
while (!CompactLevelHelper(db_, from_level)) {
WaitForCompaction();
}
}
for (auto& db_with_cfh : multi_dbs_) {
while (!CompactLevelHelper(db_with_cfh, from_level)) WaitForCompaction();
while (!CompactLevelHelper(db_with_cfh, from_level)) {
WaitForCompaction();
}
}
}
@ -8614,15 +8653,15 @@ int db_bench_tool(int argc, char** argv) {
exit(1);
}
if (!strcasecmp(FLAGS_compaction_fadvice.c_str(), "NONE"))
if (!strcasecmp(FLAGS_compaction_fadvice.c_str(), "NONE")) {
FLAGS_compaction_fadvice_e = ROCKSDB_NAMESPACE::Options::NONE;
else if (!strcasecmp(FLAGS_compaction_fadvice.c_str(), "NORMAL"))
} else if (!strcasecmp(FLAGS_compaction_fadvice.c_str(), "NORMAL")) {
FLAGS_compaction_fadvice_e = ROCKSDB_NAMESPACE::Options::NORMAL;
else if (!strcasecmp(FLAGS_compaction_fadvice.c_str(), "SEQUENTIAL"))
} else if (!strcasecmp(FLAGS_compaction_fadvice.c_str(), "SEQUENTIAL")) {
FLAGS_compaction_fadvice_e = ROCKSDB_NAMESPACE::Options::SEQUENTIAL;
else if (!strcasecmp(FLAGS_compaction_fadvice.c_str(), "WILLNEED"))
} else if (!strcasecmp(FLAGS_compaction_fadvice.c_str(), "WILLNEED")) {
FLAGS_compaction_fadvice_e = ROCKSDB_NAMESPACE::Options::WILLNEED;
else {
} else {
fprintf(stdout, "Unknown compaction fadvice:%s\n",
FLAGS_compaction_fadvice.c_str());
exit(1);

View File

@ -195,16 +195,20 @@ bool DbUndumpTool::Run(const UndumpOptions& undump_options,
std::unique_ptr<char[]> keyscratch(new char[last_keysize]);
std::unique_ptr<char[]> valscratch(new char[last_valsize]);
while (1) {
while (true) {
uint32_t keysize, valsize;
ROCKSDB_NAMESPACE::Slice keyslice;
ROCKSDB_NAMESPACE::Slice valslice;
status = dumpfile->Read(4, &slice, scratch8);
if (!status.ok() || slice.size() != 4) break;
if (!status.ok() || slice.size() != 4) {
break;
}
keysize = ROCKSDB_NAMESPACE::DecodeFixed32(slice.data());
if (keysize > last_keysize) {
while (keysize > last_keysize) last_keysize *= 2;
while (keysize > last_keysize) {
last_keysize *= 2;
}
keyscratch = std::unique_ptr<char[]>(new char[last_keysize]);
}
@ -225,7 +229,9 @@ bool DbUndumpTool::Run(const UndumpOptions& undump_options,
}
valsize = ROCKSDB_NAMESPACE::DecodeFixed32(slice.data());
if (valsize > last_valsize) {
while (valsize > last_valsize) last_valsize *= 2;
while (valsize > last_valsize) {
last_valsize *= 2;
}
valscratch = std::unique_ptr<char[]>(new char[last_valsize]);
}

View File

@ -131,7 +131,7 @@ LDBCommand* LDBCommand::InitFromCmdLineArgs(
const std::vector<ColumnFamilyDescriptor>* column_families) {
std::vector<std::string> args;
for (int i = 1; i < argc; i++) {
args.push_back(argv[i]);
args.emplace_back(argv[i]);
}
return InitFromCmdLineArgs(args, options, ldb_options, column_families,
SelectCommand);
@ -984,7 +984,7 @@ void LDBCommand::PrepareOptions() {
// existing DB.
if (st.ok() && cf_list.size() > 1) {
// Ignore single column family DB.
for (auto cf_name : cf_list) {
for (const auto& cf_name : cf_list) {
column_families_.emplace_back(cf_name, options_);
}
}
@ -1397,8 +1397,7 @@ ManifestDumpCommand::ManifestDumpCommand(
options, flags, false,
BuildCmdLineOptions({ARG_VERBOSE, ARG_PATH, ARG_HEX, ARG_JSON})),
verbose_(false),
json_(false),
path_("") {
json_(false) {
verbose_ = IsFlagPresent(flags, ARG_VERBOSE);
json_ = IsFlagPresent(flags, ARG_JSON);
@ -1544,8 +1543,7 @@ FileChecksumDumpCommand::FileChecksumDumpCommand(
const std::map<std::string, std::string>& options,
const std::vector<std::string>& flags)
: LDBCommand(options, flags, false,
BuildCmdLineOptions({ARG_PATH, ARG_HEX})),
path_("") {
BuildCmdLineOptions({ARG_PATH, ARG_HEX})) {
auto itr = options.find(ARG_PATH);
if (itr != options.end()) {
path_ = itr->second;
@ -1671,7 +1669,7 @@ void ListColumnFamiliesCommand::DoCommand() {
} else {
fprintf(stdout, "Column families in %s: \n{", db_path_.c_str());
bool first = true;
for (auto cf : column_families) {
for (const auto& cf : column_families) {
if (!first) {
fprintf(stdout, ", ");
}
@ -1904,11 +1902,16 @@ void InternalDumpCommand::DoCommand() {
s1 = 0;
row = ikey.Encode().ToString();
val = key_version.value;
for (k = 0; row[k] != '\x01' && row[k] != '\0'; k++) s1++;
for (k = 0; val[k] != '\x01' && val[k] != '\0'; k++) s1++;
for (k = 0; row[k] != '\x01' && row[k] != '\0'; k++) {
s1++;
}
for (k = 0; val[k] != '\x01' && val[k] != '\0'; k++) {
s1++;
}
for (int j = 0; row[j] != delim_[0] && row[j] != '\0' && row[j] != '\x01';
j++)
j++) {
rtype1 += row[j];
}
if (rtype2.compare("") && rtype2.compare(rtype1) != 0) {
fprintf(stdout, "%s => count:%" PRIu64 "\tsize:%" PRIu64 "\n",
rtype2.c_str(), c, s2);
@ -1954,7 +1957,9 @@ void InternalDumpCommand::DoCommand() {
}
// Terminate if maximum number of keys have been dumped
if (max_keys_ > 0 && count >= max_keys_) break;
if (max_keys_ > 0 && count >= max_keys_) {
break;
}
}
if (count_delim_) {
fprintf(stdout, "%s => count:%" PRIu64 "\tsize:%" PRIu64 "\n",
@ -2193,9 +2198,13 @@ void DBDumperCommand::DoDumpCommand() {
for (; iter->Valid(); iter->Next()) {
int rawtime = 0;
// If end marker was specified, we stop before it
if (!null_to_ && (iter->key().ToString() >= to_)) break;
if (!null_to_ && (iter->key().ToString() >= to_)) {
break;
}
// Terminate if maximum number of keys have been dumped
if (max_keys == 0) break;
if (max_keys == 0) {
break;
}
if (is_db_ttl_) {
TtlIterator* it_ttl = static_cast_with_check<TtlIterator>(iter);
rawtime = it_ttl->ttl_timestamp();
@ -2216,8 +2225,9 @@ void DBDumperCommand::DoDumpCommand() {
row = iter->key().ToString();
val = iter->value().ToString();
s1 = row.size() + val.size();
for (int j = 0; row[j] != delim_[0] && row[j] != '\0'; j++)
for (int j = 0; row[j] != delim_[0] && row[j] != '\0'; j++) {
rtype1 += row[j];
}
if (rtype2.compare("") && rtype2.compare(rtype1) != 0) {
fprintf(stdout, "%s => count:%" PRIu64 "\tsize:%" PRIu64 "\n",
rtype2.c_str(), c, s2);
@ -2294,7 +2304,7 @@ ReduceDBLevelsCommand::ReduceDBLevelsCommand(
std::vector<std::string> ReduceDBLevelsCommand::PrepareArgs(
const std::string& db_path, int new_levels, bool print_old_level) {
std::vector<std::string> ret;
ret.push_back("reduce_levels");
ret.emplace_back("reduce_levels");
ret.push_back("--" + ARG_DB + "=" + db_path);
ret.push_back("--" + ARG_NEW_LEVELS + "=" + std::to_string(new_levels));
if (print_old_level) {
@ -2663,7 +2673,7 @@ class InMemoryHandler : public WriteBatch::Handler {
return Status::OK();
}
~InMemoryHandler() override {}
~InMemoryHandler() override = default;
protected:
Handler::OptionState WriteAfterCommit() const override {
@ -2702,8 +2712,9 @@ void DumpWalFile(Options options, std::string wal_file, bool print_header,
// we need the log number, but ParseFilename expects dbname/NNN.log.
std::string sanitized = wal_file;
size_t lastslash = sanitized.rfind('/');
if (lastslash != std::string::npos)
if (lastslash != std::string::npos) {
sanitized = sanitized.substr(lastslash + 1);
}
if (!ParseFileName(sanitized, &log_number, &type)) {
// bogus input, carry on as best we can
log_number = 0;
@ -2979,9 +2990,8 @@ BatchPutCommand::BatchPutCommand(
for (size_t i = 0; i < params.size(); i += 2) {
std::string key = params.at(i);
std::string value = params.at(i + 1);
key_values_.push_back(std::pair<std::string, std::string>(
is_key_hex_ ? HexToString(key) : key,
is_value_hex_ ? HexToString(value) : value));
key_values_.emplace_back(is_key_hex_ ? HexToString(key) : key,
is_value_hex_ ? HexToString(value) : value);
}
}
create_if_missing_ = IsFlagPresent(flags_, ARG_CREATE_IF_MISSING);

View File

@ -185,7 +185,7 @@ class FileChecksumTestHelper {
public:
FileChecksumTestHelper(Options& options, DB* db, std::string db_name)
: options_(options), db_(db), dbname_(db_name) {}
~FileChecksumTestHelper() {}
~FileChecksumTestHelper() = default;
// Verify the checksum information in Manifest.
Status VerifyChecksumInManifest(
@ -233,8 +233,8 @@ class FileChecksumTestHelper {
return Status::Corruption("The number of files does not match!");
}
for (size_t i = 0; i < live_files.size(); i++) {
std::string stored_checksum = "";
std::string stored_func_name = "";
std::string stored_checksum;
std::string stored_func_name;
s = checksum_list->SearchOneFileChecksum(
live_files[i].file_number, &stored_checksum, &stored_func_name);
if (s.IsNotFound()) {
@ -634,9 +634,9 @@ TEST_F(LdbCmdTest, OptionParsing) {
opts.env = TryLoadCustomOrDefaultEnv();
{
std::vector<std::string> args;
args.push_back("scan");
args.push_back("--ttl");
args.push_back("--timestamp");
args.emplace_back("scan");
args.emplace_back("--ttl");
args.emplace_back("--timestamp");
LDBCommand* command = ROCKSDB_NAMESPACE::LDBCommand::InitFromCmdLineArgs(
args, opts, LDBOptions(), nullptr);
const std::vector<std::string> flags = command->TEST_GetFlags();
@ -648,9 +648,9 @@ TEST_F(LdbCmdTest, OptionParsing) {
// test parsing options which contains equal sign in the option value
{
std::vector<std::string> args;
args.push_back("scan");
args.push_back("--db=/dev/shm/ldbtest/");
args.push_back(
args.emplace_back("scan");
args.emplace_back("--db=/dev/shm/ldbtest/");
args.emplace_back(
"--from='abcd/efg/hijk/lmn/"
"opq:__rst.uvw.xyz?a=3+4+bcd+efghi&jk=lm_no&pq=rst-0&uv=wx-8&yz=a&bcd_"
"ef=gh.ijk'");

View File

@ -10,7 +10,7 @@
namespace ROCKSDB_NAMESPACE {
LDBOptions::LDBOptions() {}
LDBOptions::LDBOptions() = default;
void LDBCommandRunner::PrintHelp(const LDBOptions& ldb_options,
const char* /*exec_name*/, bool to_stderr) {

View File

@ -7,7 +7,7 @@
// 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 <stdint.h>
#include <cstdint>
#include "db/wide/wide_column_serialization.h"
#include "file/random_access_file_reader.h"

View File

@ -400,7 +400,7 @@ int SSTDumpTool::Run(int argc, char const* const* argv, Options options) {
// that whether it is a valid sst or not
// (A directory "file" is not a valid sst)
filenames.clear();
filenames.push_back(dir_or_file);
filenames.emplace_back(dir_or_file);
dir = false;
}
@ -468,7 +468,7 @@ int SSTDumpTool::Run(int argc, char const* const* argv, Options options) {
fprintf(stderr, "%s: %s\n", filename.c_str(), st.ToString().c_str());
exit(1);
} else {
fprintf(stdout, "raw dump written to file %s\n", &out_filename[0]);
fprintf(stdout, "raw dump written to file %s\n", out_filename.data());
}
continue;
}

View File

@ -56,7 +56,7 @@ class TraceAnalyzerTest : public testing::Test {
dbname_ = test_path_ + "/db";
}
~TraceAnalyzerTest() override {}
~TraceAnalyzerTest() override = default;
void GenerateTrace(std::string trace_path) {
Options options;
@ -87,11 +87,11 @@ class TraceAnalyzerTest : public testing::Test {
ASSERT_OK(batch.DeleteRange("e", "f"));
ASSERT_OK(db_->Write(wo, &batch));
std::vector<Slice> keys;
keys.push_back("a");
keys.push_back("b");
keys.push_back("df");
keys.push_back("gege");
keys.push_back("hjhjhj");
keys.emplace_back("a");
keys.emplace_back("b");
keys.emplace_back("df");
keys.emplace_back("gege");
keys.emplace_back("hjhjhj");
std::vector<std::string> values;
std::vector<Status> ss = db_->MultiGet(ro, keys, &values);
ASSERT_GE(ss.size(), 0);
@ -176,8 +176,6 @@ class TraceAnalyzerTest : public testing::Test {
ASSERT_EQ(result[i][0], cnt[i][0]);
}
}
return;
}
void AnalyzeTrace(std::vector<std::string>& paras_diff,

View File

@ -201,7 +201,7 @@ uint64_t MultiplyCheckOverflow(uint64_t op1, uint64_t op2) {
AnalyzerOptions::AnalyzerOptions()
: correlation_map(kTaTypeNum, std::vector<int>(kTaTypeNum, -1)) {}
AnalyzerOptions::~AnalyzerOptions() {}
AnalyzerOptions::~AnalyzerOptions() = default;
void AnalyzerOptions::SparseCorrelationInput(const std::string& in_str) {
std::string cur = in_str;
@ -214,14 +214,14 @@ void AnalyzerOptions::SparseCorrelationInput(const std::string& in_str) {
exit(1);
}
std::string opt1, opt2;
std::size_t split = cur.find_first_of(",");
std::size_t split = cur.find_first_of(',');
if (split != std::string::npos) {
opt1 = cur.substr(1, split - 1);
} else {
fprintf(stderr, "Invalid correlation input: %s\n", in_str.c_str());
exit(1);
}
std::size_t end = cur.find_first_of("]");
std::size_t end = cur.find_first_of(']');
if (end != std::string::npos) {
opt2 = cur.substr(split + 1, end - split - 1);
} else {
@ -232,8 +232,7 @@ void AnalyzerOptions::SparseCorrelationInput(const std::string& in_str) {
if (taOptToIndex.find(opt1) != taOptToIndex.end() &&
taOptToIndex.find(opt2) != taOptToIndex.end()) {
correlation_list.push_back(
std::make_pair(taOptToIndex[opt1], taOptToIndex[opt2]));
correlation_list.emplace_back(taOptToIndex[opt1], taOptToIndex[opt2]);
} else {
fprintf(stderr, "Invalid correlation input: %s\n", in_str.c_str());
exit(1);
@ -245,7 +244,6 @@ void AnalyzerOptions::SparseCorrelationInput(const std::string& in_str) {
correlation_map[it.first][it.second] = sequence;
sequence++;
}
return;
}
// The trace statistic struct constructor
@ -264,7 +262,7 @@ TraceStats::TraceStats() {
a_ave_qps = 0.0;
}
TraceStats::~TraceStats() {}
TraceStats::~TraceStats() = default;
// The trace analyzer constructor
TraceAnalyzer::TraceAnalyzer(std::string& trace_path, std::string& output_path,
@ -354,7 +352,7 @@ TraceAnalyzer::TraceAnalyzer(std::string& trace_path, std::string& output_path,
}
}
TraceAnalyzer::~TraceAnalyzer() {}
TraceAnalyzer::~TraceAnalyzer() = default;
// Prepare the processing
// Initiate the global trace reader and writer here

View File

@ -97,7 +97,7 @@ IteratorQueryTraceRecord::IteratorQueryTraceRecord(
upper_.PinSelf(upper_bound);
}
IteratorQueryTraceRecord::~IteratorQueryTraceRecord() {}
IteratorQueryTraceRecord::~IteratorQueryTraceRecord() = default;
Slice IteratorQueryTraceRecord::GetLowerBound() const { return Slice(lower_); }

View File

@ -58,8 +58,8 @@ Status TracerHelper::ParseTraceHeader(const Trace& header, int* trace_version,
std::vector<std::string> s_vec;
int begin = 0, end;
for (int i = 0; i < 3; i++) {
assert(header.payload.find("\t", begin) != std::string::npos);
end = static_cast<int>(header.payload.find("\t", begin));
assert(header.payload.find('\t', begin) != std::string::npos);
end = static_cast<int>(header.payload.find('\t', begin));
s_vec.push_back(header.payload.substr(begin, end - begin));
begin = end + 1;
}

View File

@ -9,9 +9,8 @@
#include "rocksdb/comparator.h"
#include <stdint.h>
#include <algorithm>
#include <cstdint>
#include <memory>
#include <mutex>
#include <sstream>
@ -30,7 +29,7 @@ namespace ROCKSDB_NAMESPACE {
namespace {
class BytewiseComparatorImpl : public Comparator {
public:
BytewiseComparatorImpl() {}
BytewiseComparatorImpl() = default;
static const char* kClassName() { return "leveldb.BytewiseComparator"; }
const char* Name() const override { return kClassName(); }
@ -112,7 +111,9 @@ class BytewiseComparatorImpl : public Comparator {
}
size_t diff_ind = s.difference_offset(t);
// same slice
if (diff_ind >= s.size()) return false;
if (diff_ind >= s.size()) {
return false;
}
uint8_t byte_s = static_cast<uint8_t>(s[diff_ind]);
uint8_t byte_t = static_cast<uint8_t>(t[diff_ind]);
// first different byte must be consecutive, and remaining bytes must be
@ -148,7 +149,7 @@ class BytewiseComparatorImpl : public Comparator {
class ReverseBytewiseComparatorImpl : public BytewiseComparatorImpl {
public:
ReverseBytewiseComparatorImpl() {}
ReverseBytewiseComparatorImpl() = default;
static const char* kClassName() {
return "rocksdb.ReverseBytewiseComparator";

View File

@ -67,7 +67,7 @@ static_assert(sizeof(ZSTDCachedData) % CACHE_LINE_SIZE == 0,
class CompressionContextCache::Rep {
public:
Rep() {}
Rep() = default;
ZSTDUncompressCachedData GetZSTDUncompressData() {
auto p = per_core_uncompr_.AccessElementAndIndex();
int64_t idx = static_cast<int64_t>(p.second);

View File

@ -11,9 +11,8 @@
// four bytes at a time.
#include "util/crc32c.h"
#include <stdint.h>
#include <array>
#include <cstdint>
#include <utility>
#include "port/lang.h"

View File

@ -164,10 +164,11 @@ TEST_F(DynamicBloomTest, VaryingLengths) {
"%5.2f%% @ num = %6u, bloom_bits = %6u\n",
nonseq ? "nonseq" : "seq", rate * 100.0, num, bloom_bits);
if (rate > 0.0125)
if (rate > 0.0125) {
mediocre_filters++; // Allowed, but not too often
else
} else {
good_filters++;
}
}
}

View File

@ -31,7 +31,7 @@ Status FileChecksumListImpl::GetAllFileChecksums(
return Status::InvalidArgument("Pointer has not been initiated");
}
for (auto i : checksum_map_) {
for (const auto& i : checksum_map_) {
file_numbers->push_back(i.first);
checksums->push_back(i.second.first);
checksum_func_names->push_back(i.second.second);

View File

@ -31,7 +31,7 @@ TEST_F(WritableFileWriterTest, RangeSync) {
class FakeWF : public FSWritableFile {
public:
explicit FakeWF() : size_(0), last_synced_(0) {}
~FakeWF() override {}
~FakeWF() override = default;
using FSWritableFile::Append;
IOStatus Append(const Slice& data, const IOOptions& /*options*/,
@ -134,7 +134,7 @@ TEST_F(WritableFileWriterTest, IncrementalBuffer) {
: file_data_(_file_data),
use_direct_io_(_use_direct_io),
no_flush_(_no_flush) {}
~FakeWF() override {}
~FakeWF() override = default;
using FSWritableFile::Append;
IOStatus Append(const Slice& data, const IOOptions& /*options*/,
@ -588,7 +588,7 @@ class ReadaheadSequentialFileTest : public testing::Test,
scratch_.reset(new char[2 * readahead_size_]);
ResetSourceStr();
}
ReadaheadSequentialFileTest() {}
ReadaheadSequentialFileTest() = default;
std::string Read(size_t n) {
Slice result;
Status s = test_read_holder_->Read(
@ -919,7 +919,7 @@ class WritableFileWriterIOPriorityTest : public testing::Test {
class FakeWF : public FSWritableFile {
public:
explicit FakeWF(Env::IOPriority io_priority) { SetIOPriority(io_priority); }
~FakeWF() override {}
~FakeWF() override = default;
IOStatus Append(const Slice& /*data*/, const IOOptions& options,
IODebugContext* /*dbg*/) override {

View File

@ -34,7 +34,7 @@ class LockTest : public testing::Test {
current_ = this;
}
~LockTest() override {}
~LockTest() override = default;
Status LockFile(FileLock** db_lock) { return env_->LockFile(file_, db_lock); }
@ -94,8 +94,9 @@ class LockTest : public testing::Test {
} else if (pid > 0) {
// parent process
int status;
while (-1 == waitpid(pid, &status, 0))
while (-1 == waitpid(pid, &status, 0)) {
;
}
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
// child process exited with non success status
return false;

View File

@ -6,10 +6,9 @@
#include "util/random.h"
#include <limits.h>
#include <stdint.h>
#include <string.h>
#include <climits>
#include <cstdint>
#include <cstring>
#include <thread>
#include <utility>