Run clang-format on env/ folder (#10859)

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

Test Plan: CircleCI jobs

Reviewed By: anand1976

Differential Revision: D40653839

Pulled By: akankshamahajan15

fbshipit-source-id: ce75205ee34ee3896a77a807d5c556886de78b01
main
akankshamahajan 2 years ago committed by Facebook GitHub Bot
parent 0ed1a800ed
commit ee3dbdc083
  1. 27
      env/env.cc
  2. 6
      env/env_encryption.cc
  3. 2
      env/env_encryption_ctr.h
  4. 69
      env/env_test.cc
  5. 3
      env/file_system.cc
  6. 5
      env/io_posix.cc
  7. 3
      env/io_posix.h
  8. 1
      env/mock_env.h
  9. 8
      env/mock_env_test.cc

27
env/env.cc vendored

@ -633,8 +633,7 @@ Env::Env(const std::shared_ptr<FileSystem>& fs,
const std::shared_ptr<SystemClock>& clock)
: thread_status_updater_(nullptr), file_system_(fs), system_clock_(clock) {}
Env::~Env() {
}
Env::~Env() {}
Status Env::NewLogger(const std::string& fname,
std::shared_ptr<Logger>* result) {
@ -841,14 +840,11 @@ std::string Env::GenerateUniqueId() {
return result;
}
SequentialFile::~SequentialFile() {
}
SequentialFile::~SequentialFile() {}
RandomAccessFile::~RandomAccessFile() {
}
RandomAccessFile::~RandomAccessFile() {}
WritableFile::~WritableFile() {
}
WritableFile::~WritableFile() {}
MemoryMappedFileBuffer::~MemoryMappedFileBuffer() {}
@ -865,8 +861,7 @@ Status Logger::Close() {
Status Logger::CloseImpl() { return Status::NotSupported(); }
FileLock::~FileLock() {
}
FileLock::~FileLock() {}
void LogFlush(Logger* info_log) {
if (info_log) {
@ -887,9 +882,10 @@ void Log(Logger* info_log, const char* format, ...) {
va_end(ap);
}
void Logger::Logv(const InfoLogLevel log_level, const char* format, va_list ap) {
static const char* kInfoLogLevelNames[5] = { "DEBUG", "INFO", "WARN",
"ERROR", "FATAL" };
void Logger::Logv(const InfoLogLevel log_level, const char* format,
va_list ap) {
static const char* kInfoLogLevelNames[5] = {"DEBUG", "INFO", "WARN", "ERROR",
"FATAL"};
if (log_level < log_level_) {
return;
}
@ -919,7 +915,8 @@ void Logger::Logv(const InfoLogLevel log_level, const char* format, va_list ap)
}
}
static void Logv(const InfoLogLevel log_level, Logger *info_log, const char *format, va_list ap) {
static void Logv(const InfoLogLevel log_level, Logger* info_log,
const char* format, va_list ap) {
if (info_log && info_log->GetInfoLogLevel() <= log_level) {
if (log_level == InfoLogLevel::HEADER_LEVEL) {
info_log->LogHeader(format, ap);
@ -1106,7 +1103,7 @@ void AssignEnvOptions(EnvOptions* env_options, const DBOptions& options) {
options.env->SanitizeEnvOptions(env_options);
}
}
} // namespace
EnvOptions Env::OptimizeForLogWrite(const EnvOptions& env_options,
const DBOptions& db_options) const {

@ -953,7 +953,8 @@ Env* NewEncryptedEnv(Env* base_env,
// Encrypt one or more (partial) blocks of data at the file offset.
// Length of data is given in dataSize.
Status BlockAccessCipherStream::Encrypt(uint64_t fileOffset, char *data, size_t dataSize) {
Status BlockAccessCipherStream::Encrypt(uint64_t fileOffset, char* data,
size_t dataSize) {
// Calculate block index
auto blockSize = BlockSize();
uint64_t blockIndex = fileOffset / blockSize;
@ -998,7 +999,8 @@ Status BlockAccessCipherStream::Encrypt(uint64_t fileOffset, char *data, size_t
// Decrypt one or more (partial) blocks of data at the file offset.
// Length of data is given in dataSize.
Status BlockAccessCipherStream::Decrypt(uint64_t fileOffset, char *data, size_t dataSize) {
Status BlockAccessCipherStream::Decrypt(uint64_t fileOffset, char* data,
size_t dataSize) {
// Calculate block index
auto blockSize = BlockSize();
uint64_t blockIndex = fileOffset / blockSize;

@ -87,8 +87,8 @@ class CTREncryptionProvider : public EncryptionProvider {
Status AddCipher(const std::string& descriptor, const char* /*cipher*/,
size_t /*len*/, bool /*for_write*/) override;
protected:
protected:
// PopulateSecretPrefixPart initializes the data into a new prefix block
// that will be encrypted. This function will store the data in plain text.
// It will be encrypted later (before written to disk).

69
env/env_test.cc vendored

@ -91,7 +91,8 @@ extern "C" bool RocksDbIOUringEnable() { return true; }
std::unique_ptr<char, Deleter> NewAligned(const size_t size, const char ch) {
char* ptr = nullptr;
#ifdef OS_WIN
if (nullptr == (ptr = reinterpret_cast<char*>(_aligned_malloc(size, kPageSize)))) {
if (nullptr ==
(ptr = reinterpret_cast<char*>(_aligned_malloc(size, kPageSize)))) {
return std::unique_ptr<char, Deleter>(nullptr, Deleter(_aligned_free));
}
std::unique_ptr<char, Deleter> uptr(ptr, Deleter(_aligned_free));
@ -183,8 +184,7 @@ TEST_F(EnvPosixTest, AreFilesSame) {
std::string same_file_link_name = same_file_name + "_link";
std::unique_ptr<WritableFile> same_file;
ASSERT_OK(env->NewWritableFile(same_file_name,
&same_file, soptions));
ASSERT_OK(env->NewWritableFile(same_file_name, &same_file, soptions));
same_file->Append("random_data");
ASSERT_OK(same_file->Flush());
same_file.reset();
@ -988,7 +988,6 @@ bool IsUniqueIDValid(const std::string& s) {
const size_t MAX_ID_SIZE = 100;
char temp_id[MAX_ID_SIZE];
} // namespace
// Determine whether we can use the FS_IOC_GETVERSION ioctl
@ -1066,8 +1065,10 @@ class IoctlFriendlyTmpdir {
// Diagnose ioctl-related failure only if this is the
// directory specified via that envvar.
if (tmp && tmp == d) {
fprintf(stderr, "TEST_IOCTL_FRIENDLY_TMPDIR-specified directory is "
"not suitable: %s\n", d.c_str());
fprintf(stderr,
"TEST_IOCTL_FRIENDLY_TMPDIR-specified directory is "
"not suitable: %s\n",
d.c_str());
}
rmdir(dir_buf); // ignore failure
}
@ -1087,19 +1088,16 @@ class IoctlFriendlyTmpdir {
return;
}
fprintf(stderr, "failed to find an ioctl-friendly temporary directory;"
fprintf(stderr,
"failed to find an ioctl-friendly temporary directory;"
" specify one via the TEST_IOCTL_FRIENDLY_TMPDIR envvar\n");
std::abort();
#endif
}
~IoctlFriendlyTmpdir() {
rmdir(dir_.c_str());
}
~IoctlFriendlyTmpdir() { rmdir(dir_.c_str()); }
const std::string& name() const {
return dir_;
}
const std::string& name() const { return dir_; }
bool is_supported() const { return is_supported_; }
@ -1506,7 +1504,9 @@ TEST_F(EnvPosixTest, MultiReadNonAlignedLargeNum) {
for (int i = 0; i < num_reads; i++) {
int rnd_off;
// No repeat offsets.
while (start_offsets.find(rnd_off = rnd.Uniform(81920)) != start_offsets.end()) {}
while (start_offsets.find(rnd_off = rnd.Uniform(81920)) !=
start_offsets.end()) {
}
start_offsets.insert(rnd_off);
}
std::vector<size_t> offsets;
@ -1516,9 +1516,11 @@ TEST_F(EnvPosixTest, MultiReadNonAlignedLargeNum) {
offsets.push_back(so);
}
for (size_t i = 0; i + 1 < offsets.size(); i++) {
lens.push_back(static_cast<size_t>(rnd.Uniform(static_cast<int>(offsets[i + 1] - offsets[i])) + 1));
lens.push_back(static_cast<size_t>(
rnd.Uniform(static_cast<int>(offsets[i + 1] - offsets[i])) + 1));
}
lens.push_back(static_cast<size_t>(rnd.Uniform(static_cast<int>(kTotalSize - offsets.back())) + 1));
lens.push_back(static_cast<size_t>(
rnd.Uniform(static_cast<int>(kTotalSize - offsets.back())) + 1));
ASSERT_EQ(num_reads, lens.size());
// Create requests
@ -1540,7 +1542,8 @@ TEST_F(EnvPosixTest, MultiReadNonAlignedLargeNum) {
// Validate results
for (int i = 0; i < num_reads; ++i) {
ASSERT_OK(reqs[i].status);
ASSERT_EQ(Slice(expected_data.data() + offsets[i], lens[i]).ToString(true),
ASSERT_EQ(
Slice(expected_data.data() + offsets[i], lens[i]).ToString(true),
reqs[i].result.ToString(true));
}
@ -1754,7 +1757,8 @@ TEST_P(EnvPosixTestWithParam, InvalidateCache) {
// Create file.
{
std::unique_ptr<WritableFile> wfile;
#if !defined(OS_MACOSX) && !defined(OS_WIN) && !defined(OS_SOLARIS) && !defined(OS_AIX)
#if !defined(OS_MACOSX) && !defined(OS_WIN) && !defined(OS_SOLARIS) && \
!defined(OS_AIX)
if (soptions.use_direct_writes) {
soptions.use_direct_writes = false;
}
@ -1770,7 +1774,8 @@ TEST_P(EnvPosixTestWithParam, InvalidateCache) {
std::unique_ptr<RandomAccessFile> file;
auto scratch = NewAligned(kSectorSize, 0);
Slice result;
#if !defined(OS_MACOSX) && !defined(OS_WIN) && !defined(OS_SOLARIS) && !defined(OS_AIX)
#if !defined(OS_MACOSX) && !defined(OS_WIN) && !defined(OS_SOLARIS) && \
!defined(OS_AIX)
if (soptions.use_direct_reads) {
soptions.use_direct_reads = false;
}
@ -1787,7 +1792,8 @@ TEST_P(EnvPosixTestWithParam, InvalidateCache) {
std::unique_ptr<SequentialFile> file;
auto scratch = NewAligned(kSectorSize, 0);
Slice result;
#if !defined(OS_MACOSX) && !defined(OS_WIN) && !defined(OS_SOLARIS) && !defined(OS_AIX)
#if !defined(OS_MACOSX) && !defined(OS_WIN) && !defined(OS_SOLARIS) && \
!defined(OS_AIX)
if (soptions.use_direct_reads) {
soptions.use_direct_reads = false;
}
@ -1931,7 +1937,8 @@ TEST_P(EnvPosixTestWithParam, Preallocation) {
std::unique_ptr<WritableFile> srcfile;
EnvOptions soptions;
soptions.use_direct_reads = soptions.use_direct_writes = direct_io_;
#if !defined(OS_MACOSX) && !defined(OS_WIN) && !defined(OS_SOLARIS) && !defined(OS_AIX) && !defined(OS_OPENBSD) && !defined(OS_FREEBSD)
#if !defined(OS_MACOSX) && !defined(OS_WIN) && !defined(OS_SOLARIS) && \
!defined(OS_AIX) && !defined(OS_OPENBSD) && !defined(OS_FREEBSD)
if (soptions.use_direct_writes) {
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
"NewWritableFile:O_DIRECT", [&](void* arg) {
@ -1993,7 +2000,8 @@ TEST_P(EnvPosixTestWithParam, ConsistentChildrenAttributes) {
for (int i = 0; i < kNumChildren; ++i) {
const std::string path = test_base_dir + "/testfile_" + std::to_string(i);
std::unique_ptr<WritableFile> file;
#if !defined(OS_MACOSX) && !defined(OS_WIN) && !defined(OS_SOLARIS) && !defined(OS_AIX) && !defined(OS_OPENBSD) && !defined(OS_FREEBSD)
#if !defined(OS_MACOSX) && !defined(OS_WIN) && !defined(OS_SOLARIS) && \
!defined(OS_AIX) && !defined(OS_OPENBSD) && !defined(OS_FREEBSD)
if (soptions.use_direct_writes) {
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
"NewWritableFile:O_DIRECT", [&](void* arg) {
@ -2033,13 +2041,9 @@ TEST_P(EnvPosixTestWithParam, WritableFileWrapper) {
public:
mutable int* step_;
void inc(int x) const {
EXPECT_EQ(x, (*step_)++);
}
void inc(int x) const { EXPECT_EQ(x, (*step_)++); }
explicit Base(int* step) : step_(step) {
inc(0);
}
explicit Base(int* step) : step_(step) { inc(0); }
Status Append(const Slice& /*data*/) override {
inc(1);
@ -2373,8 +2377,7 @@ TEST_P(EnvPosixTestWithParam, PosixRandomRWFileRandomized) {
class TestEnv : public EnvWrapper {
public:
explicit TestEnv() : EnvWrapper(Env::Default()),
close_count(0) { }
explicit TestEnv() : EnvWrapper(Env::Default()), close_count(0) {}
const char* Name() const override { return "TestEnv"; }
class TestLogger : public Logger {
public:
@ -2504,7 +2507,8 @@ class EnvFSTestWithParam
env_ptr_ = NewCompositeEnv(fs_);
}
if (env_non_null && !env_default && fs_default) {
env_ptr_ = std::unique_ptr<Env>(new FaultInjectionTestEnv(Env::Default()));
env_ptr_ =
std::unique_ptr<Env>(new FaultInjectionTestEnv(Env::Default()));
fs_.reset();
}
if (env_non_null && !env_default && !fs_default) {
@ -2572,8 +2576,7 @@ TEST_P(EnvFSTestWithParam, OptionsTest) {
// 1. True means Options::env is non-null, false means null
// 2. True means use Env::Default, false means custom
// 3. True means use FileSystem::Default, false means custom
INSTANTIATE_TEST_CASE_P(
EnvFSTest, EnvFSTestWithParam,
INSTANTIATE_TEST_CASE_P(EnvFSTest, EnvFSTestWithParam,
::testing::Combine(::testing::Bool(), ::testing::Bool(),
::testing::Bool()));
// This test ensures that default Env and those allocated by

@ -220,8 +220,7 @@ IOStatus ReadFileToString(FileSystem* fs, const std::string& fname,
char* space = new char[kBufferSize];
while (true) {
Slice fragment;
s = file->Read(kBufferSize, IOOptions(), &fragment, space,
nullptr);
s = file->Read(kBufferSize, IOOptions(), &fragment, space, nullptr);
if (!s.ok()) {
break;
}

5
env/io_posix.cc vendored

@ -9,8 +9,10 @@
#ifdef ROCKSDB_LIB_IO_POSIX
#include "env/io_posix.h"
#include <errno.h>
#include <fcntl.h>
#include <algorithm>
#if defined(OS_LINUX)
#include <linux/fs.h>
@ -601,8 +603,7 @@ IOStatus PosixRandomAccessFile::Read(uint64_t offset, size_t n,
return s;
}
IOStatus PosixRandomAccessFile::MultiRead(FSReadRequest* reqs,
size_t num_reqs,
IOStatus PosixRandomAccessFile::MultiRead(FSReadRequest* reqs, size_t num_reqs,
const IOOptions& options,
IODebugContext* dbg) {
if (use_direct_io()) {

3
env/io_posix.h vendored

@ -284,8 +284,7 @@ class PosixRandomAccessFile : public FSRandomAccessFile {
public:
PosixRandomAccessFile(const std::string& fname, int fd,
size_t logical_block_size,
const EnvOptions& options
size_t logical_block_size, const EnvOptions& options
#if defined(ROCKSDB_IOURING_PRESENT)
,
ThreadLocalPtr* thread_local_io_urings

1
env/mock_env.h vendored

@ -135,6 +135,7 @@ class MockEnv : public CompositeEnvWrapper {
const char* Name() const override { return kClassName(); }
Status CorruptBuffer(const std::string& fname);
private:
MockEnv(Env* env, const std::shared_ptr<FileSystem>& fs,
const std::shared_ptr<SystemClock>& clock);

@ -51,14 +51,14 @@ TEST_F(MockEnvTest, Corrupt) {
ASSERT_OK(writable_file->Append(kCorrupted));
ASSERT_TRUE(writable_file->GetFileSize() == kGood.size() + kCorrupted.size());
result.clear();
ASSERT_OK(rand_file->Read(kGood.size(), kCorrupted.size(),
&result, &(scratch[0])));
ASSERT_OK(
rand_file->Read(kGood.size(), kCorrupted.size(), &result, &(scratch[0])));
ASSERT_EQ(result.compare(kCorrupted), 0);
// Corrupted
ASSERT_OK(dynamic_cast<MockEnv*>(env_)->CorruptBuffer(kFileName));
result.clear();
ASSERT_OK(rand_file->Read(kGood.size(), kCorrupted.size(),
&result, &(scratch[0])));
ASSERT_OK(
rand_file->Read(kGood.size(), kCorrupted.size(), &result, &(scratch[0])));
ASSERT_NE(result.compare(kCorrupted), 0);
}

Loading…
Cancel
Save