Fix RandomAccessFileReaderTest failures on Travis (#7173)
Summary: On Travis, the old `alignment()` returned by `RandomAccessFileReaderTest` is inconsistent with the `GetRequiredBufferAlignment` returned in `RandomAccessFileReader`. This PR removes `alignment()` and consistently use `GetRequiredBufferAlignment` as page size. Pull Request resolved: https://github.com/facebook/rocksdb/pull/7173 Test Plan: make random_access_file_reader_test && ./random_access_file_reader_test Watch Travis Reviewed By: siying Differential Revision: D22741606 Pulled By: cheng-chang fbshipit-source-id: f28f29a7c993bbc3594ae70ecd186fa8bab9c4f2
This commit is contained in:
parent
1adfd729e9
commit
69a6d0b411
@ -26,7 +26,6 @@ class RandomAccessFileReaderTest : public testing::Test {
|
|||||||
fs_ = FileSystem::Default();
|
fs_ = FileSystem::Default();
|
||||||
test_dir_ = test::PerThreadDBPath("random_access_file_reader_test");
|
test_dir_ = test::PerThreadDBPath("random_access_file_reader_test");
|
||||||
ASSERT_OK(fs_->CreateDir(test_dir_, IOOptions(), nullptr));
|
ASSERT_OK(fs_->CreateDir(test_dir_, IOOptions(), nullptr));
|
||||||
ComputeAndSetAlignment();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TearDown() override { EXPECT_OK(DestroyDir(env_, test_dir_)); }
|
void TearDown() override { EXPECT_OK(DestroyDir(env_, test_dir_)); }
|
||||||
@ -55,26 +54,14 @@ class RandomAccessFileReaderTest : public testing::Test {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t alignment() const { return alignment_; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Env* env_;
|
Env* env_;
|
||||||
std::shared_ptr<FileSystem> fs_;
|
std::shared_ptr<FileSystem> fs_;
|
||||||
std::string test_dir_;
|
std::string test_dir_;
|
||||||
size_t alignment_;
|
|
||||||
|
|
||||||
std::string Path(const std::string& fname) {
|
std::string Path(const std::string& fname) {
|
||||||
return test_dir_ + "/" + fname;
|
return test_dir_ + "/" + fname;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ComputeAndSetAlignment() {
|
|
||||||
std::string f = "get_alignment";
|
|
||||||
Write(f, "");
|
|
||||||
std::unique_ptr<RandomAccessFileReader> r;
|
|
||||||
Read(f, FileOptions(), &r);
|
|
||||||
alignment_ = r->file()->GetRequiredBufferAlignment();
|
|
||||||
EXPECT_OK(fs_->DeleteFile(Path(f), IOOptions(), nullptr));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Skip the following tests in lite mode since direct I/O is unsupported.
|
// Skip the following tests in lite mode since direct I/O is unsupported.
|
||||||
@ -83,7 +70,7 @@ class RandomAccessFileReaderTest : public testing::Test {
|
|||||||
TEST_F(RandomAccessFileReaderTest, ReadDirectIO) {
|
TEST_F(RandomAccessFileReaderTest, ReadDirectIO) {
|
||||||
std::string fname = "read-direct-io";
|
std::string fname = "read-direct-io";
|
||||||
Random rand(0);
|
Random rand(0);
|
||||||
std::string content = rand.RandomString(static_cast<int>(alignment()));
|
std::string content = rand.RandomString(kDefaultPageSize);
|
||||||
Write(fname, content);
|
Write(fname, content);
|
||||||
|
|
||||||
FileOptions opts;
|
FileOptions opts;
|
||||||
@ -92,8 +79,9 @@ TEST_F(RandomAccessFileReaderTest, ReadDirectIO) {
|
|||||||
Read(fname, opts, &r);
|
Read(fname, opts, &r);
|
||||||
ASSERT_TRUE(r->use_direct_io());
|
ASSERT_TRUE(r->use_direct_io());
|
||||||
|
|
||||||
size_t offset = alignment() / 2;
|
const size_t page_size = r->file()->GetRequiredBufferAlignment();
|
||||||
size_t len = alignment() / 3;
|
size_t offset = page_size / 2;
|
||||||
|
size_t len = page_size / 3;
|
||||||
Slice result;
|
Slice result;
|
||||||
AlignedBuf buf;
|
AlignedBuf buf;
|
||||||
for (bool for_compaction : {true, false}) {
|
for (bool for_compaction : {true, false}) {
|
||||||
@ -116,7 +104,7 @@ TEST_F(RandomAccessFileReaderTest, MultiReadDirectIO) {
|
|||||||
// Creates a file with 3 pages.
|
// Creates a file with 3 pages.
|
||||||
std::string fname = "multi-read-direct-io";
|
std::string fname = "multi-read-direct-io";
|
||||||
Random rand(0);
|
Random rand(0);
|
||||||
std::string content = rand.RandomString(3 * static_cast<int>(alignment()));
|
std::string content = rand.RandomString(3 * kDefaultPageSize);
|
||||||
Write(fname, content);
|
Write(fname, content);
|
||||||
|
|
||||||
FileOptions opts;
|
FileOptions opts;
|
||||||
@ -125,6 +113,8 @@ TEST_F(RandomAccessFileReaderTest, MultiReadDirectIO) {
|
|||||||
Read(fname, opts, &r);
|
Read(fname, opts, &r);
|
||||||
ASSERT_TRUE(r->use_direct_io());
|
ASSERT_TRUE(r->use_direct_io());
|
||||||
|
|
||||||
|
const size_t page_size = r->file()->GetRequiredBufferAlignment();
|
||||||
|
|
||||||
{
|
{
|
||||||
// Reads 2 blocks in the 1st page.
|
// Reads 2 blocks in the 1st page.
|
||||||
// The results should be SharedSlices of the same underlying buffer.
|
// The results should be SharedSlices of the same underlying buffer.
|
||||||
@ -135,12 +125,12 @@ TEST_F(RandomAccessFileReaderTest, MultiReadDirectIO) {
|
|||||||
// 2nd block: xx
|
// 2nd block: xx
|
||||||
FSReadRequest r0;
|
FSReadRequest r0;
|
||||||
r0.offset = 0;
|
r0.offset = 0;
|
||||||
r0.len = alignment() / 4;
|
r0.len = page_size / 4;
|
||||||
r0.scratch = nullptr;
|
r0.scratch = nullptr;
|
||||||
|
|
||||||
FSReadRequest r1;
|
FSReadRequest r1;
|
||||||
r1.offset = alignment() / 2;
|
r1.offset = page_size / 2;
|
||||||
r1.len = alignment() / 2;
|
r1.len = page_size / 2;
|
||||||
r1.scratch = nullptr;
|
r1.scratch = nullptr;
|
||||||
|
|
||||||
std::vector<FSReadRequest> reqs;
|
std::vector<FSReadRequest> reqs;
|
||||||
@ -156,7 +146,7 @@ TEST_F(RandomAccessFileReaderTest, MultiReadDirectIO) {
|
|||||||
ASSERT_EQ(aligned_reqs.size(), 1);
|
ASSERT_EQ(aligned_reqs.size(), 1);
|
||||||
const FSReadRequest& aligned_r = aligned_reqs[0];
|
const FSReadRequest& aligned_r = aligned_reqs[0];
|
||||||
ASSERT_EQ(aligned_r.offset, 0);
|
ASSERT_EQ(aligned_r.offset, 0);
|
||||||
ASSERT_EQ(aligned_r.len, alignment());
|
ASSERT_EQ(aligned_r.len, page_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -173,17 +163,17 @@ TEST_F(RandomAccessFileReaderTest, MultiReadDirectIO) {
|
|||||||
// 3rd block: x
|
// 3rd block: x
|
||||||
FSReadRequest r0;
|
FSReadRequest r0;
|
||||||
r0.offset = 0;
|
r0.offset = 0;
|
||||||
r0.len = alignment() / 4;
|
r0.len = page_size / 4;
|
||||||
r0.scratch = nullptr;
|
r0.scratch = nullptr;
|
||||||
|
|
||||||
FSReadRequest r1;
|
FSReadRequest r1;
|
||||||
r1.offset = alignment() / 2;
|
r1.offset = page_size / 2;
|
||||||
r1.len = alignment();
|
r1.len = page_size;
|
||||||
r1.scratch = nullptr;
|
r1.scratch = nullptr;
|
||||||
|
|
||||||
FSReadRequest r2;
|
FSReadRequest r2;
|
||||||
r2.offset = 2 * alignment() - alignment() / 4;
|
r2.offset = 2 * page_size - page_size / 4;
|
||||||
r2.len = alignment() / 4;
|
r2.len = page_size / 4;
|
||||||
r2.scratch = nullptr;
|
r2.scratch = nullptr;
|
||||||
|
|
||||||
std::vector<FSReadRequest> reqs;
|
std::vector<FSReadRequest> reqs;
|
||||||
@ -200,7 +190,7 @@ TEST_F(RandomAccessFileReaderTest, MultiReadDirectIO) {
|
|||||||
ASSERT_EQ(aligned_reqs.size(), 1);
|
ASSERT_EQ(aligned_reqs.size(), 1);
|
||||||
const FSReadRequest& aligned_r = aligned_reqs[0];
|
const FSReadRequest& aligned_r = aligned_reqs[0];
|
||||||
ASSERT_EQ(aligned_r.offset, 0);
|
ASSERT_EQ(aligned_r.offset, 0);
|
||||||
ASSERT_EQ(aligned_r.len, 2 * alignment());
|
ASSERT_EQ(aligned_r.len, 2 * page_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -216,18 +206,18 @@ TEST_F(RandomAccessFileReaderTest, MultiReadDirectIO) {
|
|||||||
// 2nd block: xx
|
// 2nd block: xx
|
||||||
// 3rd block: xx
|
// 3rd block: xx
|
||||||
FSReadRequest r0;
|
FSReadRequest r0;
|
||||||
r0.offset = alignment() / 4;
|
r0.offset = page_size / 4;
|
||||||
r0.len = alignment() / 2;
|
r0.len = page_size / 2;
|
||||||
r0.scratch = nullptr;
|
r0.scratch = nullptr;
|
||||||
|
|
||||||
FSReadRequest r1;
|
FSReadRequest r1;
|
||||||
r1.offset = alignment() + alignment() / 4;
|
r1.offset = page_size + page_size / 4;
|
||||||
r1.len = alignment() / 2;
|
r1.len = page_size / 2;
|
||||||
r1.scratch = nullptr;
|
r1.scratch = nullptr;
|
||||||
|
|
||||||
FSReadRequest r2;
|
FSReadRequest r2;
|
||||||
r2.offset = 2 * alignment() + alignment() / 4;
|
r2.offset = 2 * page_size + page_size / 4;
|
||||||
r2.len = alignment() / 2;
|
r2.len = page_size / 2;
|
||||||
r2.scratch = nullptr;
|
r2.scratch = nullptr;
|
||||||
|
|
||||||
std::vector<FSReadRequest> reqs;
|
std::vector<FSReadRequest> reqs;
|
||||||
@ -244,7 +234,7 @@ TEST_F(RandomAccessFileReaderTest, MultiReadDirectIO) {
|
|||||||
ASSERT_EQ(aligned_reqs.size(), 1);
|
ASSERT_EQ(aligned_reqs.size(), 1);
|
||||||
const FSReadRequest& aligned_r = aligned_reqs[0];
|
const FSReadRequest& aligned_r = aligned_reqs[0];
|
||||||
ASSERT_EQ(aligned_r.offset, 0);
|
ASSERT_EQ(aligned_r.offset, 0);
|
||||||
ASSERT_EQ(aligned_r.len, 3 * alignment());
|
ASSERT_EQ(aligned_r.len, 3 * page_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -258,13 +248,13 @@ TEST_F(RandomAccessFileReaderTest, MultiReadDirectIO) {
|
|||||||
// 1st block: xx
|
// 1st block: xx
|
||||||
// 2nd block: xx
|
// 2nd block: xx
|
||||||
FSReadRequest r0;
|
FSReadRequest r0;
|
||||||
r0.offset = alignment() / 4;
|
r0.offset = page_size / 4;
|
||||||
r0.len = alignment() / 2;
|
r0.len = page_size / 2;
|
||||||
r0.scratch = nullptr;
|
r0.scratch = nullptr;
|
||||||
|
|
||||||
FSReadRequest r1;
|
FSReadRequest r1;
|
||||||
r1.offset = 2 * alignment() + alignment() / 4;
|
r1.offset = 2 * page_size + page_size / 4;
|
||||||
r1.len = alignment() / 2;
|
r1.len = page_size / 2;
|
||||||
r1.scratch = nullptr;
|
r1.scratch = nullptr;
|
||||||
|
|
||||||
std::vector<FSReadRequest> reqs;
|
std::vector<FSReadRequest> reqs;
|
||||||
@ -281,9 +271,9 @@ TEST_F(RandomAccessFileReaderTest, MultiReadDirectIO) {
|
|||||||
const FSReadRequest& aligned_r0 = aligned_reqs[0];
|
const FSReadRequest& aligned_r0 = aligned_reqs[0];
|
||||||
const FSReadRequest& aligned_r1 = aligned_reqs[1];
|
const FSReadRequest& aligned_r1 = aligned_reqs[1];
|
||||||
ASSERT_EQ(aligned_r0.offset, 0);
|
ASSERT_EQ(aligned_r0.offset, 0);
|
||||||
ASSERT_EQ(aligned_r0.len, alignment());
|
ASSERT_EQ(aligned_r0.len, page_size);
|
||||||
ASSERT_EQ(aligned_r1.offset, 2 * alignment());
|
ASSERT_EQ(aligned_r1.offset, 2 * page_size);
|
||||||
ASSERT_EQ(aligned_r1.len, alignment());
|
ASSERT_EQ(aligned_r1.len, page_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing();
|
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing();
|
||||||
|
Loading…
Reference in New Issue
Block a user