|
|
@ -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(); |
|
|
@ -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
|
|
|
@ -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_; } |
|
|
|
|
|
|
|
|
|
|
@ -1506,7 +1504,9 @@ 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; |
|
|
@ -1516,9 +1516,11 @@ TEST_F(EnvPosixTest, MultiReadNonAlignedLargeNum) { |
|
|
|
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,7 +1542,8 @@ 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( |
|
|
|
|
|
|
|
Slice(expected_data.data() + offsets[i], lens[i]).ToString(true), |
|
|
|
reqs[i].result.ToString(true)); |
|
|
|
reqs[i].result.ToString(true)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1754,7 +1757,8 @@ 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) && \ |
|
|
|
|
|
|
|
!defined(OS_AIX) |
|
|
|
if (soptions.use_direct_writes) { |
|
|
|
if (soptions.use_direct_writes) { |
|
|
|
soptions.use_direct_writes = false; |
|
|
|
soptions.use_direct_writes = false; |
|
|
|
} |
|
|
|
} |
|
|
@ -1770,7 +1774,8 @@ TEST_P(EnvPosixTestWithParam, InvalidateCache) { |
|
|
|
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) && \ |
|
|
|
|
|
|
|
!defined(OS_AIX) |
|
|
|
if (soptions.use_direct_reads) { |
|
|
|
if (soptions.use_direct_reads) { |
|
|
|
soptions.use_direct_reads = false; |
|
|
|
soptions.use_direct_reads = false; |
|
|
|
} |
|
|
|
} |
|
|
@ -1787,7 +1792,8 @@ TEST_P(EnvPosixTestWithParam, InvalidateCache) { |
|
|
|
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) && \ |
|
|
|
|
|
|
|
!defined(OS_AIX) |
|
|
|
if (soptions.use_direct_reads) { |
|
|
|
if (soptions.use_direct_reads) { |
|
|
|
soptions.use_direct_reads = false; |
|
|
|
soptions.use_direct_reads = false; |
|
|
|
} |
|
|
|
} |
|
|
@ -1931,7 +1937,8 @@ 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) && \ |
|
|
|
|
|
|
|
!defined(OS_AIX) && !defined(OS_OPENBSD) && !defined(OS_FREEBSD) |
|
|
|
if (soptions.use_direct_writes) { |
|
|
|
if (soptions.use_direct_writes) { |
|
|
|
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack( |
|
|
|
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack( |
|
|
|
"NewWritableFile:O_DIRECT", [&](void* arg) { |
|
|
|
"NewWritableFile:O_DIRECT", [&](void* arg) { |
|
|
@ -1993,7 +2000,8 @@ 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) && \ |
|
|
|
|
|
|
|
!defined(OS_AIX) && !defined(OS_OPENBSD) && !defined(OS_FREEBSD) |
|
|
|
if (soptions.use_direct_writes) { |
|
|
|
if (soptions.use_direct_writes) { |
|
|
|
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack( |
|
|
|
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack( |
|
|
|
"NewWritableFile:O_DIRECT", [&](void* arg) { |
|
|
|
"NewWritableFile:O_DIRECT", [&](void* arg) { |
|
|
@ -2033,13 +2041,9 @@ TEST_P(EnvPosixTestWithParam, WritableFileWrapper) { |
|
|
|
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); |
|
|
@ -2373,8 +2377,7 @@ 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: |
|
|
@ -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,8 +2576,7 @@ 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
|
|
|
|