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. 35
      env/env.cc
  2. 2
      env/env_basic_test.cc
  3. 40
      env/env_chroot.cc
  4. 122
      env/env_encryption.cc
  5. 2
      env/env_encryption_ctr.h
  6. 355
      env/env_test.cc
  7. 7
      env/file_system.cc
  8. 5
      env/io_posix.cc
  9. 3
      env/io_posix.h
  10. 1
      env/mock_env.h
  11. 8
      env/mock_env_test.cc

35
env/env.cc vendored

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

@ -305,7 +305,7 @@ TEST_P(EnvBasicTestWithParam, LargeWrite) {
read += result.size(); read += result.size();
} }
ASSERT_TRUE(write_data == read_data); ASSERT_TRUE(write_data == read_data);
delete [] scratch; delete[] scratch;
} }
TEST_P(EnvMoreTestWithParam, GetModTime) { TEST_P(EnvMoreTestWithParam, GetModTime) {

40
env/env_chroot.cc vendored

@ -66,9 +66,9 @@ IOStatus ChrootFileSystem::GetTestDirectory(const IOOptions& options,
return CreateDirIfMissing(*path, options, dbg); return CreateDirIfMissing(*path, options, dbg);
} }
// Returns status and expanded absolute path including the chroot directory. // Returns status and expanded absolute path including the chroot directory.
// Checks whether the provided path breaks out of the chroot. If it returns // Checks whether the provided path breaks out of the chroot. If it returns
// non-OK status, the returned path should not be used. // non-OK status, the returned path should not be used.
std::pair<IOStatus, std::string> ChrootFileSystem::EncodePath( std::pair<IOStatus, std::string> ChrootFileSystem::EncodePath(
const std::string& path) { const std::string& path) {
if (path.empty() || path[0] != '/') { if (path.empty() || path[0] != '/') {
@ -77,29 +77,29 @@ std::pair<IOStatus, std::string> ChrootFileSystem::EncodePath(
std::pair<IOStatus, std::string> res; std::pair<IOStatus, std::string> res;
res.second = chroot_dir_ + path; res.second = chroot_dir_ + path;
#if defined(OS_AIX) #if defined(OS_AIX)
char resolvedName[PATH_MAX]; char resolvedName[PATH_MAX];
char* normalized_path = realpath(res.second.c_str(), resolvedName); char* normalized_path = realpath(res.second.c_str(), resolvedName);
#else #else
char* normalized_path = realpath(res.second.c_str(), nullptr); char* normalized_path = realpath(res.second.c_str(), nullptr);
#endif #endif
if (normalized_path == nullptr) { if (normalized_path == nullptr) {
res.first = IOStatus::NotFound(res.second, errnoStr(errno).c_str()); res.first = IOStatus::NotFound(res.second, errnoStr(errno).c_str());
} else if (strlen(normalized_path) < chroot_dir_.size() || } else if (strlen(normalized_path) < chroot_dir_.size() ||
strncmp(normalized_path, chroot_dir_.c_str(), strncmp(normalized_path, chroot_dir_.c_str(),
chroot_dir_.size()) != 0) { chroot_dir_.size()) != 0) {
res.first = IOStatus::IOError(res.second, res.first = IOStatus::IOError(res.second,
"Attempted to access path outside chroot"); "Attempted to access path outside chroot");
} else { } else {
res.first = IOStatus::OK(); res.first = IOStatus::OK();
} }
#if !defined(OS_AIX) #if !defined(OS_AIX)
free(normalized_path); free(normalized_path);
#endif #endif
return res; return res;
} }
// Similar to EncodePath() except assumes the basename in the path hasn't been // Similar to EncodePath() except assumes the basename in the path hasn't been
// created yet. // created yet.
std::pair<IOStatus, std::string> ChrootFileSystem::EncodePathWithNewBasename( std::pair<IOStatus, std::string> ChrootFileSystem::EncodePathWithNewBasename(
const std::string& path) { const std::string& path) {
if (path.empty() || path[0] != '/') { if (path.empty() || path[0] != '/') {

@ -33,14 +33,14 @@ std::shared_ptr<EncryptionProvider> EncryptionProvider::NewCTRProvider(
return std::make_shared<CTREncryptionProvider>(cipher); return std::make_shared<CTREncryptionProvider>(cipher);
} }
// Read up to "n" bytes from the file. "scratch[0..n-1]" may be // Read up to "n" bytes from the file. "scratch[0..n-1]" may be
// written by this routine. Sets "*result" to the data that was // written by this routine. Sets "*result" to the data that was
// read (including if fewer than "n" bytes were successfully read). // read (including if fewer than "n" bytes were successfully read).
// May set "*result" to point at data in "scratch[0..n-1]", so // May set "*result" to point at data in "scratch[0..n-1]", so
// "scratch[0..n-1]" must be live when "*result" is used. // "scratch[0..n-1]" must be live when "*result" is used.
// If an error was encountered, returns a non-OK status. // If an error was encountered, returns a non-OK status.
// //
// REQUIRES: External synchronization // REQUIRES: External synchronization
IOStatus EncryptedSequentialFile::Read(size_t n, const IOOptions& options, IOStatus EncryptedSequentialFile::Read(size_t n, const IOOptions& options,
Slice* result, char* scratch, Slice* result, char* scratch,
IODebugContext* dbg) { IODebugContext* dbg) {
@ -89,16 +89,16 @@ size_t EncryptedSequentialFile::GetRequiredBufferAlignment() const {
return file_->GetRequiredBufferAlignment(); return file_->GetRequiredBufferAlignment();
} }
// Remove any kind of caching of data from the offset to offset+length // Remove any kind of caching of data from the offset to offset+length
// of this file. If the length is 0, then it refers to the end of file. // of this file. If the length is 0, then it refers to the end of file.
// If the system is not caching the file contents, then this is a noop. // If the system is not caching the file contents, then this is a noop.
IOStatus EncryptedSequentialFile::InvalidateCache(size_t offset, IOStatus EncryptedSequentialFile::InvalidateCache(size_t offset,
size_t length) { size_t length) {
return file_->InvalidateCache(offset + prefixLength_, length); return file_->InvalidateCache(offset + prefixLength_, length);
} }
// Positioned Read for direct I/O // Positioned Read for direct I/O
// If Direct I/O enabled, offset, n, and scratch should be properly aligned // If Direct I/O enabled, offset, n, and scratch should be properly aligned
IOStatus EncryptedSequentialFile::PositionedRead(uint64_t offset, size_t n, IOStatus EncryptedSequentialFile::PositionedRead(uint64_t offset, size_t n,
const IOOptions& options, const IOOptions& options,
Slice* result, char* scratch, Slice* result, char* scratch,
@ -118,16 +118,16 @@ IOStatus EncryptedSequentialFile::PositionedRead(uint64_t offset, size_t n,
return io_s; return io_s;
} }
// Read up to "n" bytes from the file starting at "offset". // Read up to "n" bytes from the file starting at "offset".
// "scratch[0..n-1]" may be written by this routine. Sets "*result" // "scratch[0..n-1]" may be written by this routine. Sets "*result"
// to the data that was read (including if fewer than "n" bytes were // to the data that was read (including if fewer than "n" bytes were
// successfully read). May set "*result" to point at data in // successfully read). May set "*result" to point at data in
// "scratch[0..n-1]", so "scratch[0..n-1]" must be live when // "scratch[0..n-1]", so "scratch[0..n-1]" must be live when
// "*result" is used. If an error was encountered, returns a non-OK // "*result" is used. If an error was encountered, returns a non-OK
// status. // status.
// //
// Safe for concurrent use by multiple threads. // Safe for concurrent use by multiple threads.
// If Direct I/O enabled, offset, n, and scratch should be aligned properly. // If Direct I/O enabled, offset, n, and scratch should be aligned properly.
IOStatus EncryptedRandomAccessFile::Read(uint64_t offset, size_t n, IOStatus EncryptedRandomAccessFile::Read(uint64_t offset, size_t n,
const IOOptions& options, const IOOptions& options,
Slice* result, char* scratch, Slice* result, char* scratch,
@ -146,7 +146,7 @@ IOStatus EncryptedRandomAccessFile::Read(uint64_t offset, size_t n,
return io_s; return io_s;
} }
// Readahead the file starting from offset by n bytes for caching. // Readahead the file starting from offset by n bytes for caching.
IOStatus EncryptedRandomAccessFile::Prefetch(uint64_t offset, size_t n, IOStatus EncryptedRandomAccessFile::Prefetch(uint64_t offset, size_t n,
const IOOptions& options, const IOOptions& options,
IODebugContext* dbg) { IODebugContext* dbg) {
@ -154,21 +154,21 @@ IOStatus EncryptedRandomAccessFile::Prefetch(uint64_t offset, size_t n,
return file_->Prefetch(offset + prefixLength_, n, options, dbg); return file_->Prefetch(offset + prefixLength_, n, options, dbg);
} }
// Tries to get an unique ID for this file that will be the same each time // Tries to get an unique ID for this file that will be the same each time
// the file is opened (and will stay the same while the file is open). // the file is opened (and will stay the same while the file is open).
// Furthermore, it tries to make this ID at most "max_size" bytes. If such an // Furthermore, it tries to make this ID at most "max_size" bytes. If such an
// ID can be created this function returns the length of the ID and places it // ID can be created this function returns the length of the ID and places it
// in "id"; otherwise, this function returns 0, in which case "id" // in "id"; otherwise, this function returns 0, in which case "id"
// may not have been modified. // may not have been modified.
// //
// This function guarantees, for IDs from a given environment, two unique ids // This function guarantees, for IDs from a given environment, two unique ids
// cannot be made equal to each other by adding arbitrary bytes to one of // cannot be made equal to each other by adding arbitrary bytes to one of
// them. That is, no unique ID is the prefix of another. // them. That is, no unique ID is the prefix of another.
// //
// This function guarantees that the returned ID will not be interpretable as // This function guarantees that the returned ID will not be interpretable as
// a single varint. // a single varint.
// //
// Note: these IDs are only valid for the duration of the process. // Note: these IDs are only valid for the duration of the process.
size_t EncryptedRandomAccessFile::GetUniqueId(char* id, size_t max_size) const { size_t EncryptedRandomAccessFile::GetUniqueId(char* id, size_t max_size) const {
return file_->GetUniqueId(id, max_size); return file_->GetUniqueId(id, max_size);
}; };
@ -177,21 +177,21 @@ void EncryptedRandomAccessFile::Hint(AccessPattern pattern) {
file_->Hint(pattern); file_->Hint(pattern);
} }
// Indicates the upper layers if the current RandomAccessFile implementation // Indicates the upper layers if the current RandomAccessFile implementation
// uses direct IO. // uses direct IO.
bool EncryptedRandomAccessFile::use_direct_io() const { bool EncryptedRandomAccessFile::use_direct_io() const {
return file_->use_direct_io(); return file_->use_direct_io();
} }
// Use the returned alignment value to allocate // Use the returned alignment value to allocate
// aligned buffer for Direct I/O // aligned buffer for Direct I/O
size_t EncryptedRandomAccessFile::GetRequiredBufferAlignment() const { size_t EncryptedRandomAccessFile::GetRequiredBufferAlignment() const {
return file_->GetRequiredBufferAlignment(); return file_->GetRequiredBufferAlignment();
} }
// Remove any kind of caching of data from the offset to offset+length // Remove any kind of caching of data from the offset to offset+length
// of this file. If the length is 0, then it refers to the end of file. // of this file. If the length is 0, then it refers to the end of file.
// If the system is not caching the file contents, then this is a noop. // If the system is not caching the file contents, then this is a noop.
IOStatus EncryptedRandomAccessFile::InvalidateCache(size_t offset, IOStatus EncryptedRandomAccessFile::InvalidateCache(size_t offset,
size_t length) { size_t length) {
return file_->InvalidateCache(offset + prefixLength_, length); return file_->InvalidateCache(offset + prefixLength_, length);
@ -267,8 +267,8 @@ bool EncryptedWritableFile::IsSyncThreadSafe() const {
return file_->IsSyncThreadSafe(); return file_->IsSyncThreadSafe();
} }
// Use the returned alignment value to allocate // Use the returned alignment value to allocate
// aligned buffer for Direct I/O // aligned buffer for Direct I/O
size_t EncryptedWritableFile::GetRequiredBufferAlignment() const { size_t EncryptedWritableFile::GetRequiredBufferAlignment() const {
return file_->GetRequiredBufferAlignment(); return file_->GetRequiredBufferAlignment();
} }
@ -363,14 +363,14 @@ bool EncryptedRandomRWFile::use_direct_io() const {
return file_->use_direct_io(); return file_->use_direct_io();
} }
// Use the returned alignment value to allocate // Use the returned alignment value to allocate
// aligned buffer for Direct I/O // aligned buffer for Direct I/O
size_t EncryptedRandomRWFile::GetRequiredBufferAlignment() const { size_t EncryptedRandomRWFile::GetRequiredBufferAlignment() const {
return file_->GetRequiredBufferAlignment(); return file_->GetRequiredBufferAlignment();
} }
// Write bytes in `data` at offset `offset`, Returns Status::OK() on success. // Write bytes in `data` at offset `offset`, Returns Status::OK() on success.
// Pass aligned buffer when use_direct_io() returns true. // Pass aligned buffer when use_direct_io() returns true.
IOStatus EncryptedRandomRWFile::Write(uint64_t offset, const Slice& data, IOStatus EncryptedRandomRWFile::Write(uint64_t offset, const Slice& data,
const IOOptions& options, const IOOptions& options,
IODebugContext* dbg) { IODebugContext* dbg) {
@ -397,9 +397,9 @@ IOStatus EncryptedRandomRWFile::Write(uint64_t offset, const Slice& data,
return file_->Write(offset, dataToWrite, options, dbg); return file_->Write(offset, dataToWrite, options, dbg);
} }
// Read up to `n` bytes starting from offset `offset` and store them in // Read up to `n` bytes starting from offset `offset` and store them in
// result, provided `scratch` size should be at least `n`. // result, provided `scratch` size should be at least `n`.
// Returns Status::OK() on success. // Returns Status::OK() on success.
IOStatus EncryptedRandomRWFile::Read(uint64_t offset, size_t n, IOStatus EncryptedRandomRWFile::Read(uint64_t offset, size_t n,
const IOOptions& options, Slice* result, const IOOptions& options, Slice* result,
char* scratch, IODebugContext* dbg) const { char* scratch, IODebugContext* dbg) const {
@ -953,7 +953,8 @@ Env* NewEncryptedEnv(Env* base_env,
// Encrypt one or more (partial) blocks of data at the file offset. // Encrypt one or more (partial) blocks of data at the file offset.
// Length of data is given in dataSize. // 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 // Calculate block index
auto blockSize = BlockSize(); auto blockSize = BlockSize();
uint64_t blockIndex = fileOffset / blockSize; uint64_t blockIndex = fileOffset / blockSize;
@ -965,7 +966,7 @@ Status BlockAccessCipherStream::Encrypt(uint64_t fileOffset, char *data, size_t
// Encrypt individual blocks. // Encrypt individual blocks.
while (1) { while (1) {
char *block = data; char* block = data;
size_t n = std::min(dataSize, blockSize - blockOffset); size_t n = std::min(dataSize, blockSize - blockOffset);
if (n != blockSize) { if (n != blockSize) {
// We're not encrypting a full block. // We're not encrypting a full block.
@ -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. // Decrypt one or more (partial) blocks of data at the file offset.
// Length of data is given in dataSize. // 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 // Calculate block index
auto blockSize = BlockSize(); auto blockSize = BlockSize();
uint64_t blockIndex = fileOffset / blockSize; uint64_t blockIndex = fileOffset / blockSize;
@ -1010,7 +1012,7 @@ Status BlockAccessCipherStream::Decrypt(uint64_t fileOffset, char *data, size_t
// Decrypt individual blocks. // Decrypt individual blocks.
while (1) { while (1) {
char *block = data; char* block = data;
size_t n = std::min(dataSize, blockSize - blockOffset); size_t n = std::min(dataSize, blockSize - blockOffset);
if (n != blockSize) { if (n != blockSize) {
// We're not decrypting a full block. // We're not decrypting a full block.
@ -1344,6 +1346,6 @@ Status EncryptionProvider::CreateFromString(
result); result);
} }
#endif // ROCKSDB_LITE #endif // ROCKSDB_LITE
} // namespace ROCKSDB_NAMESPACE } // namespace ROCKSDB_NAMESPACE

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

355
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) { std::unique_ptr<char, Deleter> NewAligned(const size_t size, const char ch) {
char* ptr = nullptr; char* ptr = nullptr;
#ifdef OS_WIN #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)); return std::unique_ptr<char, Deleter>(nullptr, Deleter(_aligned_free));
} }
std::unique_ptr<char, Deleter> uptr(ptr, 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::string same_file_link_name = same_file_name + "_link";
std::unique_ptr<WritableFile> same_file; std::unique_ptr<WritableFile> same_file;
ASSERT_OK(env->NewWritableFile(same_file_name, ASSERT_OK(env->NewWritableFile(same_file_name, &same_file, soptions));
&same_file, soptions));
same_file->Append("random_data"); same_file->Append("random_data");
ASSERT_OK(same_file->Flush()); ASSERT_OK(same_file->Flush());
same_file.reset(); same_file.reset();
@ -681,7 +681,7 @@ TEST_P(EnvPosixTestWithParam, TwoPools) {
} }
TEST_P(EnvPosixTestWithParam, DecreaseNumBgThreads) { TEST_P(EnvPosixTestWithParam, DecreaseNumBgThreads) {
constexpr int kWaitMicros = 60000000; // 1min constexpr int kWaitMicros = 60000000; // 1min
std::vector<test::SleepingBackgroundTask> tasks(10); std::vector<test::SleepingBackgroundTask> tasks(10);
@ -988,7 +988,6 @@ bool IsUniqueIDValid(const std::string& s) {
const size_t MAX_ID_SIZE = 100; const size_t MAX_ID_SIZE = 100;
char temp_id[MAX_ID_SIZE]; char temp_id[MAX_ID_SIZE];
} // namespace } // namespace
// Determine whether we can use the FS_IOC_GETVERSION ioctl // Determine whether we can use the FS_IOC_GETVERSION ioctl
@ -1030,12 +1029,12 @@ class IoctlFriendlyTmpdir {
explicit IoctlFriendlyTmpdir() { explicit IoctlFriendlyTmpdir() {
char dir_buf[100]; char dir_buf[100];
const char *fmt = "%s/rocksdb.XXXXXX"; const char* fmt = "%s/rocksdb.XXXXXX";
const char *tmp = getenv("TEST_IOCTL_FRIENDLY_TMPDIR"); const char* tmp = getenv("TEST_IOCTL_FRIENDLY_TMPDIR");
#ifdef OS_WIN #ifdef OS_WIN
#define rmdir _rmdir #define rmdir _rmdir
if(tmp == nullptr) { if (tmp == nullptr) {
tmp = getenv("TMP"); tmp = getenv("TMP");
} }
@ -1066,8 +1065,10 @@ class IoctlFriendlyTmpdir {
// Diagnose ioctl-related failure only if this is the // Diagnose ioctl-related failure only if this is the
// directory specified via that envvar. // directory specified via that envvar.
if (tmp && tmp == d) { if (tmp && tmp == d) {
fprintf(stderr, "TEST_IOCTL_FRIENDLY_TMPDIR-specified directory is " fprintf(stderr,
"not suitable: %s\n", d.c_str()); "TEST_IOCTL_FRIENDLY_TMPDIR-specified directory is "
"not suitable: %s\n",
d.c_str());
} }
rmdir(dir_buf); // ignore failure rmdir(dir_buf); // ignore failure
} }
@ -1087,19 +1088,16 @@ class IoctlFriendlyTmpdir {
return; 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"); " specify one via the TEST_IOCTL_FRIENDLY_TMPDIR envvar\n");
std::abort(); std::abort();
#endif #endif
} }
~IoctlFriendlyTmpdir() { ~IoctlFriendlyTmpdir() { rmdir(dir_.c_str()); }
rmdir(dir_.c_str());
}
const std::string& name() const { const std::string& name() const { return dir_; }
return dir_;
}
bool is_supported() const { return is_supported_; } bool is_supported() const { return is_supported_; }
@ -1273,7 +1271,7 @@ TEST_P(EnvPosixTestWithParam, AllocateTest) {
// Returns true if any of the strings in ss are the prefix of another string. // Returns true if any of the strings in ss are the prefix of another string.
bool HasPrefix(const std::unordered_set<std::string>& ss) { bool HasPrefix(const std::unordered_set<std::string>& ss) {
for (const std::string& s: ss) { for (const std::string& s : ss) {
if (s.empty()) { if (s.empty()) {
return true; return true;
} }
@ -1506,19 +1504,23 @@ TEST_F(EnvPosixTest, MultiReadNonAlignedLargeNum) {
for (int i = 0; i < num_reads; i++) { for (int i = 0; i < num_reads; i++) {
int rnd_off; int rnd_off;
// No repeat offsets. // 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); start_offsets.insert(rnd_off);
} }
std::vector<size_t> offsets; std::vector<size_t> offsets;
std::vector<size_t> lens; std::vector<size_t> lens;
// std::set already sorted the offsets. // std::set already sorted the offsets.
for (int so: start_offsets) { for (int so : start_offsets) {
offsets.push_back(so); offsets.push_back(so);
} }
for (size_t i = 0; i + 1 < offsets.size(); i++) { 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()); ASSERT_EQ(num_reads, lens.size());
// Create requests // Create requests
@ -1540,8 +1542,9 @@ TEST_F(EnvPosixTest, MultiReadNonAlignedLargeNum) {
// Validate results // Validate results
for (int i = 0; i < num_reads; ++i) { for (int i = 0; i < num_reads; ++i) {
ASSERT_OK(reqs[i].status); ASSERT_OK(reqs[i].status);
ASSERT_EQ(Slice(expected_data.data() + offsets[i], lens[i]).ToString(true), ASSERT_EQ(
reqs[i].result.ToString(true)); Slice(expected_data.data() + offsets[i], lens[i]).ToString(true),
reqs[i].result.ToString(true));
} }
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing(); ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing();
@ -1754,57 +1757,60 @@ TEST_P(EnvPosixTestWithParam, InvalidateCache) {
// Create file. // Create file.
{ {
std::unique_ptr<WritableFile> wfile; 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) && \
if (soptions.use_direct_writes) { !defined(OS_AIX)
soptions.use_direct_writes = false; if (soptions.use_direct_writes) {
} soptions.use_direct_writes = false;
}
#endif #endif
ASSERT_OK(env_->NewWritableFile(fname, &wfile, soptions)); ASSERT_OK(env_->NewWritableFile(fname, &wfile, soptions));
ASSERT_OK(wfile->Append(slice)); ASSERT_OK(wfile->Append(slice));
ASSERT_OK(wfile->InvalidateCache(0, 0)); ASSERT_OK(wfile->InvalidateCache(0, 0));
ASSERT_OK(wfile->Close()); ASSERT_OK(wfile->Close());
} }
// Random Read // Random Read
{ {
std::unique_ptr<RandomAccessFile> file; std::unique_ptr<RandomAccessFile> file;
auto scratch = NewAligned(kSectorSize, 0); auto scratch = NewAligned(kSectorSize, 0);
Slice result; 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) && \
if (soptions.use_direct_reads) { !defined(OS_AIX)
soptions.use_direct_reads = false; if (soptions.use_direct_reads) {
} soptions.use_direct_reads = false;
#endif
ASSERT_OK(env_->NewRandomAccessFile(fname, &file, soptions));
ASSERT_OK(file->Read(0, kSectorSize, &result, scratch.get()));
ASSERT_EQ(memcmp(scratch.get(), data.get(), kSectorSize), 0);
ASSERT_OK(file->InvalidateCache(0, 11));
ASSERT_OK(file->InvalidateCache(0, 0));
} }
#endif
ASSERT_OK(env_->NewRandomAccessFile(fname, &file, soptions));
ASSERT_OK(file->Read(0, kSectorSize, &result, scratch.get()));
ASSERT_EQ(memcmp(scratch.get(), data.get(), kSectorSize), 0);
ASSERT_OK(file->InvalidateCache(0, 11));
ASSERT_OK(file->InvalidateCache(0, 0));
}
// Sequential Read // Sequential Read
{ {
std::unique_ptr<SequentialFile> file; std::unique_ptr<SequentialFile> file;
auto scratch = NewAligned(kSectorSize, 0); auto scratch = NewAligned(kSectorSize, 0);
Slice result; 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) && \
if (soptions.use_direct_reads) { !defined(OS_AIX)
soptions.use_direct_reads = false; if (soptions.use_direct_reads) {
} soptions.use_direct_reads = false;
}
#endif #endif
ASSERT_OK(env_->NewSequentialFile(fname, &file, soptions)); ASSERT_OK(env_->NewSequentialFile(fname, &file, soptions));
if (file->use_direct_io()) { if (file->use_direct_io()) {
ASSERT_OK(file->PositionedRead(0, kSectorSize, &result, scratch.get())); ASSERT_OK(file->PositionedRead(0, kSectorSize, &result, scratch.get()));
} else { } else {
ASSERT_OK(file->Read(kSectorSize, &result, scratch.get())); ASSERT_OK(file->Read(kSectorSize, &result, scratch.get()));
}
ASSERT_EQ(memcmp(scratch.get(), data.get(), kSectorSize), 0);
ASSERT_OK(file->InvalidateCache(0, 11));
ASSERT_OK(file->InvalidateCache(0, 0));
} }
// Delete the file ASSERT_EQ(memcmp(scratch.get(), data.get(), kSectorSize), 0);
ASSERT_OK(env_->DeleteFile(fname)); ASSERT_OK(file->InvalidateCache(0, 11));
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->ClearTrace(); ASSERT_OK(file->InvalidateCache(0, 0));
}
// Delete the file
ASSERT_OK(env_->DeleteFile(fname));
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->ClearTrace();
} }
#endif // OS_LINUX || OS_WIN #endif // OS_LINUX || OS_WIN
@ -1931,52 +1937,53 @@ TEST_P(EnvPosixTestWithParam, Preallocation) {
std::unique_ptr<WritableFile> srcfile; std::unique_ptr<WritableFile> srcfile;
EnvOptions soptions; EnvOptions soptions;
soptions.use_direct_reads = soptions.use_direct_writes = direct_io_; 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) && \
if (soptions.use_direct_writes) { !defined(OS_AIX) && !defined(OS_OPENBSD) && !defined(OS_FREEBSD)
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack( if (soptions.use_direct_writes) {
"NewWritableFile:O_DIRECT", [&](void* arg) { ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
int* val = static_cast<int*>(arg); "NewWritableFile:O_DIRECT", [&](void* arg) {
*val &= ~O_DIRECT; int* val = static_cast<int*>(arg);
}); *val &= ~O_DIRECT;
} });
}
#endif #endif
ASSERT_OK(env_->NewWritableFile(src, &srcfile, soptions)); ASSERT_OK(env_->NewWritableFile(src, &srcfile, soptions));
srcfile->SetPreallocationBlockSize(1024 * 1024); srcfile->SetPreallocationBlockSize(1024 * 1024);
// No writes should mean no preallocation // No writes should mean no preallocation
size_t block_size, last_allocated_block; size_t block_size, last_allocated_block;
srcfile->GetPreallocationStatus(&block_size, &last_allocated_block); srcfile->GetPreallocationStatus(&block_size, &last_allocated_block);
ASSERT_EQ(last_allocated_block, 0UL); ASSERT_EQ(last_allocated_block, 0UL);
// Small write should preallocate one block // Small write should preallocate one block
size_t kStrSize = 4096; size_t kStrSize = 4096;
auto data = NewAligned(kStrSize, 'A'); auto data = NewAligned(kStrSize, 'A');
Slice str(data.get(), kStrSize); Slice str(data.get(), kStrSize);
srcfile->PrepareWrite(srcfile->GetFileSize(), kStrSize); srcfile->PrepareWrite(srcfile->GetFileSize(), kStrSize);
ASSERT_OK(srcfile->Append(str)); ASSERT_OK(srcfile->Append(str));
srcfile->GetPreallocationStatus(&block_size, &last_allocated_block);
ASSERT_EQ(last_allocated_block, 1UL);
// Write an entire preallocation block, make sure we increased by two.
{
auto buf_ptr = NewAligned(block_size, ' ');
Slice buf(buf_ptr.get(), block_size);
srcfile->PrepareWrite(srcfile->GetFileSize(), block_size);
ASSERT_OK(srcfile->Append(buf));
srcfile->GetPreallocationStatus(&block_size, &last_allocated_block); srcfile->GetPreallocationStatus(&block_size, &last_allocated_block);
ASSERT_EQ(last_allocated_block, 1UL); ASSERT_EQ(last_allocated_block, 2UL);
}
// Write an entire preallocation block, make sure we increased by two.
{
auto buf_ptr = NewAligned(block_size, ' ');
Slice buf(buf_ptr.get(), block_size);
srcfile->PrepareWrite(srcfile->GetFileSize(), block_size);
ASSERT_OK(srcfile->Append(buf));
srcfile->GetPreallocationStatus(&block_size, &last_allocated_block);
ASSERT_EQ(last_allocated_block, 2UL);
}
// Write five more blocks at once, ensure we're where we need to be. // Write five more blocks at once, ensure we're where we need to be.
{ {
auto buf_ptr = NewAligned(block_size * 5, ' '); auto buf_ptr = NewAligned(block_size * 5, ' ');
Slice buf = Slice(buf_ptr.get(), block_size * 5); Slice buf = Slice(buf_ptr.get(), block_size * 5);
srcfile->PrepareWrite(srcfile->GetFileSize(), buf.size()); srcfile->PrepareWrite(srcfile->GetFileSize(), buf.size());
ASSERT_OK(srcfile->Append(buf)); ASSERT_OK(srcfile->Append(buf));
srcfile->GetPreallocationStatus(&block_size, &last_allocated_block); srcfile->GetPreallocationStatus(&block_size, &last_allocated_block);
ASSERT_EQ(last_allocated_block, 7UL); ASSERT_EQ(last_allocated_block, 7UL);
} }
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->ClearTrace(); ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->ClearTrace();
} }
// Test that the two ways to get children file attributes (in bulk or // Test that the two ways to get children file attributes (in bulk or
@ -1993,53 +2000,50 @@ TEST_P(EnvPosixTestWithParam, ConsistentChildrenAttributes) {
for (int i = 0; i < kNumChildren; ++i) { for (int i = 0; i < kNumChildren; ++i) {
const std::string path = test_base_dir + "/testfile_" + std::to_string(i); const std::string path = test_base_dir + "/testfile_" + std::to_string(i);
std::unique_ptr<WritableFile> file; 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) && \
if (soptions.use_direct_writes) { !defined(OS_AIX) && !defined(OS_OPENBSD) && !defined(OS_FREEBSD)
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack( if (soptions.use_direct_writes) {
"NewWritableFile:O_DIRECT", [&](void* arg) { ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
int* val = static_cast<int*>(arg); "NewWritableFile:O_DIRECT", [&](void* arg) {
*val &= ~O_DIRECT; int* val = static_cast<int*>(arg);
}); *val &= ~O_DIRECT;
} });
}
#endif #endif
ASSERT_OK(env_->NewWritableFile(path, &file, soptions)); ASSERT_OK(env_->NewWritableFile(path, &file, soptions));
auto buf_ptr = NewAligned(data.size(), 'T'); auto buf_ptr = NewAligned(data.size(), 'T');
Slice buf(buf_ptr.get(), data.size()); Slice buf(buf_ptr.get(), data.size());
ASSERT_OK(file->Append(buf)); ASSERT_OK(file->Append(buf));
data.append(std::string(4096, 'T')); data.append(std::string(4096, 'T'));
} }
std::vector<Env::FileAttributes> file_attrs; std::vector<Env::FileAttributes> file_attrs;
ASSERT_OK(env_->GetChildrenFileAttributes(test_base_dir, &file_attrs)); ASSERT_OK(env_->GetChildrenFileAttributes(test_base_dir, &file_attrs));
for (int i = 0; i < kNumChildren; ++i) { for (int i = 0; i < kNumChildren; ++i) {
const std::string name = "testfile_" + std::to_string(i); const std::string name = "testfile_" + std::to_string(i);
const std::string path = test_base_dir + "/" + name; const std::string path = test_base_dir + "/" + name;
auto file_attrs_iter = std::find_if( auto file_attrs_iter = std::find_if(
file_attrs.begin(), file_attrs.end(), file_attrs.begin(), file_attrs.end(),
[&name](const Env::FileAttributes& fm) { return fm.name == name; }); [&name](const Env::FileAttributes& fm) { return fm.name == name; });
ASSERT_TRUE(file_attrs_iter != file_attrs.end()); ASSERT_TRUE(file_attrs_iter != file_attrs.end());
uint64_t size; uint64_t size;
ASSERT_OK(env_->GetFileSize(path, &size)); ASSERT_OK(env_->GetFileSize(path, &size));
ASSERT_EQ(size, 4096 * i); ASSERT_EQ(size, 4096 * i);
ASSERT_EQ(size, file_attrs_iter->size_bytes); ASSERT_EQ(size, file_attrs_iter->size_bytes);
} }
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->ClearTrace(); ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->ClearTrace();
} }
// Test that all WritableFileWrapper forwards all calls to WritableFile. // Test that all WritableFileWrapper forwards all calls to WritableFile.
TEST_P(EnvPosixTestWithParam, WritableFileWrapper) { TEST_P(EnvPosixTestWithParam, WritableFileWrapper) {
class Base : public WritableFile { class Base : public WritableFile {
public: public:
mutable int *step_; mutable int* step_;
void inc(int x) const { void inc(int x) const { EXPECT_EQ(x, (*step_)++); }
EXPECT_EQ(x, (*step_)++);
}
explicit Base(int* step) : step_(step) { explicit Base(int* step) : step_(step) { inc(0); }
inc(0);
}
Status Append(const Slice& /*data*/) override { Status Append(const Slice& /*data*/) override {
inc(1); inc(1);
@ -2372,32 +2376,31 @@ TEST_P(EnvPosixTestWithParam, PosixRandomRWFileRandomized) {
} }
class TestEnv : public EnvWrapper { class TestEnv : public EnvWrapper {
public: public:
explicit TestEnv() : EnvWrapper(Env::Default()), explicit TestEnv() : EnvWrapper(Env::Default()), close_count(0) {}
close_count(0) { } const char* Name() const override { return "TestEnv"; }
const char* Name() const override { return "TestEnv"; } class TestLogger : public Logger {
class TestLogger : public Logger { public:
public: using Logger::Logv;
using Logger::Logv; explicit TestLogger(TestEnv* env_ptr) : Logger() { env = env_ptr; }
explicit TestLogger(TestEnv* env_ptr) : Logger() { env = env_ptr; } ~TestLogger() override {
~TestLogger() override { if (!closed_) {
if (!closed_) { Status s = CloseHelper();
Status s = CloseHelper(); s.PermitUncheckedError();
s.PermitUncheckedError();
}
} }
void Logv(const char* /*format*/, va_list /*ap*/) override {} }
void Logv(const char* /*format*/, va_list /*ap*/) override {}
protected: protected:
Status CloseImpl() override { return CloseHelper(); } Status CloseImpl() override { return CloseHelper(); }
private: private:
Status CloseHelper() { Status CloseHelper() {
env->CloseCountInc(); env->CloseCountInc();
return Status::OK(); return Status::OK();
} }
TestEnv* env; TestEnv* env;
}; };
void CloseCountInc() { close_count++; } void CloseCountInc() { close_count++; }
@ -2504,7 +2507,8 @@ class EnvFSTestWithParam
env_ptr_ = NewCompositeEnv(fs_); env_ptr_ = NewCompositeEnv(fs_);
} }
if (env_non_null && !env_default && fs_default) { 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(); fs_.reset();
} }
if (env_non_null && !env_default && !fs_default) { if (env_non_null && !env_default && !fs_default) {
@ -2572,17 +2576,16 @@ TEST_P(EnvFSTestWithParam, OptionsTest) {
// 1. True means Options::env is non-null, false means null // 1. True means Options::env is non-null, false means null
// 2. True means use Env::Default, false means custom // 2. True means use Env::Default, false means custom
// 3. True means use FileSystem::Default, false means custom // 3. True means use FileSystem::Default, false means custom
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(EnvFSTest, EnvFSTestWithParam,
EnvFSTest, EnvFSTestWithParam, ::testing::Combine(::testing::Bool(), ::testing::Bool(),
::testing::Combine(::testing::Bool(), ::testing::Bool(), ::testing::Bool()));
::testing::Bool()));
// This test ensures that default Env and those allocated by // This test ensures that default Env and those allocated by
// NewCompositeEnv() all share the same threadpool // NewCompositeEnv() all share the same threadpool
TEST_F(EnvTest, MultipleCompositeEnv) { TEST_F(EnvTest, MultipleCompositeEnv) {
std::shared_ptr<FaultInjectionTestFS> fs1 = std::shared_ptr<FaultInjectionTestFS> fs1 =
std::make_shared<FaultInjectionTestFS>(FileSystem::Default()); std::make_shared<FaultInjectionTestFS>(FileSystem::Default());
std::shared_ptr<FaultInjectionTestFS> fs2 = std::shared_ptr<FaultInjectionTestFS> fs2 =
std::make_shared<FaultInjectionTestFS>(FileSystem::Default()); std::make_shared<FaultInjectionTestFS>(FileSystem::Default());
std::unique_ptr<Env> env1 = NewCompositeEnv(fs1); std::unique_ptr<Env> env1 = NewCompositeEnv(fs1);
std::unique_ptr<Env> env2 = NewCompositeEnv(fs2); std::unique_ptr<Env> env2 = NewCompositeEnv(fs2);
Env::Default()->SetBackgroundThreads(8, Env::HIGH); Env::Default()->SetBackgroundThreads(8, Env::HIGH);

@ -136,7 +136,7 @@ IOStatus FileSystem::NewLogger(const std::string& fname,
} }
FileOptions FileSystem::OptimizeForLogRead( FileOptions FileSystem::OptimizeForLogRead(
const FileOptions& file_options) const { const FileOptions& file_options) const {
FileOptions optimized_file_options(file_options); FileOptions optimized_file_options(file_options);
optimized_file_options.use_direct_reads = false; optimized_file_options.use_direct_reads = false;
return optimized_file_options; return optimized_file_options;
@ -150,7 +150,7 @@ FileOptions FileSystem::OptimizeForManifestRead(
} }
FileOptions FileSystem::OptimizeForLogWrite(const FileOptions& file_options, FileOptions FileSystem::OptimizeForLogWrite(const FileOptions& file_options,
const DBOptions& db_options) const { const DBOptions& db_options) const {
FileOptions optimized_file_options(file_options); FileOptions optimized_file_options(file_options);
optimized_file_options.bytes_per_sync = db_options.wal_bytes_per_sync; optimized_file_options.bytes_per_sync = db_options.wal_bytes_per_sync;
optimized_file_options.writable_file_max_buffer_size = optimized_file_options.writable_file_max_buffer_size =
@ -220,8 +220,7 @@ IOStatus ReadFileToString(FileSystem* fs, const std::string& fname,
char* space = new char[kBufferSize]; char* space = new char[kBufferSize];
while (true) { while (true) {
Slice fragment; Slice fragment;
s = file->Read(kBufferSize, IOOptions(), &fragment, space, s = file->Read(kBufferSize, IOOptions(), &fragment, space, nullptr);
nullptr);
if (!s.ok()) { if (!s.ok()) {
break; break;
} }

5
env/io_posix.cc vendored

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

3
env/io_posix.h vendored

@ -284,8 +284,7 @@ class PosixRandomAccessFile : public FSRandomAccessFile {
public: public:
PosixRandomAccessFile(const std::string& fname, int fd, PosixRandomAccessFile(const std::string& fname, int fd,
size_t logical_block_size, size_t logical_block_size, const EnvOptions& options
const EnvOptions& options
#if defined(ROCKSDB_IOURING_PRESENT) #if defined(ROCKSDB_IOURING_PRESENT)
, ,
ThreadLocalPtr* thread_local_io_urings 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(); } const char* Name() const override { return kClassName(); }
Status CorruptBuffer(const std::string& fname); Status CorruptBuffer(const std::string& fname);
private: private:
MockEnv(Env* env, const std::shared_ptr<FileSystem>& fs, MockEnv(Env* env, const std::shared_ptr<FileSystem>& fs,
const std::shared_ptr<SystemClock>& clock); const std::shared_ptr<SystemClock>& clock);

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

Loading…
Cancel
Save