Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get block size only in direct IO mode #6522

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions db/db_logical_block_size_cache_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,15 @@ class DBLogicalBlockSizeCacheTest : public testing::Test {
data_path_1_(dbname_ + "/data_path_1"),
cf_path_0_(dbname_ + "/cf_path_0"),
cf_path_1_(dbname_ + "/cf_path_1") {
auto get_fd_block_size = [&](int fd) {
return fd;
};
auto get_fd_block_size = [&](int fd) { return fd; };
auto get_dir_block_size = [&](const std::string& /*dir*/, size_t* size) {
*size = 1024;
return Status::OK();
};
cache_.reset(new LogicalBlockSizeCache(
get_fd_block_size, get_dir_block_size));
env_.reset(new EnvWithCustomLogicalBlockSizeCache(
Env::Default(), cache_.get()));
cache_.reset(
new LogicalBlockSizeCache(get_fd_block_size, get_dir_block_size));
env_.reset(
new EnvWithCustomLogicalBlockSizeCache(Env::Default(), cache_.get()));
}

protected:
Expand Down Expand Up @@ -475,7 +473,7 @@ TEST_F(DBLogicalBlockSizeCacheTest, MultiDBWithSamePaths) {
}

} // namespace ROCKSDB_NAMESPACE
#endif // OS_LINUX
#endif // OS_LINUX

int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
Expand Down
31 changes: 24 additions & 7 deletions env/fs_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ class PosixFileSystem : public FileSystem {
}
}
result->reset(new PosixSequentialFile(
fname, file, fd, GetLogicalBlockSize(fname, fd), options));
fname, file, fd, GetLogicalBlockSizeIfNeeded(options, fname, fd),
options));
return IOStatus::OK();
}

Expand Down Expand Up @@ -244,7 +245,7 @@ class PosixFileSystem : public FileSystem {
#endif
}
result->reset(new PosixRandomAccessFile(
fname, fd, GetLogicalBlockSize(fname, fd), options
fname, fd, GetLogicalBlockSizeIfNeeded(options, fname, fd), options
#if defined(ROCKSDB_IOURING_PRESENT)
,
thread_local_io_urings_.get()
Expand Down Expand Up @@ -331,13 +332,15 @@ class PosixFileSystem : public FileSystem {
}
#endif
result->reset(new PosixWritableFile(
fname, fd, GetLogicalBlockSize(fname, fd), options));
fname, fd, GetLogicalBlockSizeIfNeeded(options, fname, fd), options));
} else {
// disable mmap writes
EnvOptions no_mmap_writes_options = options;
no_mmap_writes_options.use_mmap_writes = false;
result->reset(new PosixWritableFile(
fname, fd, GetLogicalBlockSize(fname, fd), no_mmap_writes_options));
fname, fd,
GetLogicalBlockSizeIfNeeded(no_mmap_writes_options, fname, fd),
no_mmap_writes_options));
}
return s;
}
Expand Down Expand Up @@ -433,13 +436,15 @@ class PosixFileSystem : public FileSystem {
}
#endif
result->reset(new PosixWritableFile(
fname, fd, GetLogicalBlockSize(fname, fd), options));
fname, fd, GetLogicalBlockSizeIfNeeded(options, fname, fd), options));
} else {
// disable mmap writes
FileOptions no_mmap_writes_options = options;
no_mmap_writes_options.use_mmap_writes = false;
result->reset(new PosixWritableFile(
fname, fd, GetLogicalBlockSize(fname, fd), no_mmap_writes_options));
fname, fd,
GetLogicalBlockSizeIfNeeded(no_mmap_writes_options, fname, fd),
no_mmap_writes_options));
}
return s;
}
Expand Down Expand Up @@ -918,6 +923,10 @@ class PosixFileSystem : public FileSystem {
static LogicalBlockSizeCache logical_block_size_cache_;
#endif
static size_t GetLogicalBlockSize(const std::string& fname, int fd);
// In non-direct IO mode, this directly returns kDefaultPageSize.
// Otherwise call GetLogicalBlockSize.
static size_t GetLogicalBlockSizeIfNeeded(const EnvOptions& options,
const std::string& fname, int fd);
};

#ifdef OS_LINUX
Expand All @@ -928,11 +937,19 @@ size_t PosixFileSystem::GetLogicalBlockSize(const std::string& fname, int fd) {
#ifdef OS_LINUX
return logical_block_size_cache_.GetLogicalBlockSize(fname, fd);
#else
(void) fname;
(void)fname;
return PosixHelper::GetLogicalBlockSizeOfFd(fd);
#endif
}

size_t PosixFileSystem::GetLogicalBlockSizeIfNeeded(const EnvOptions& options,
const std::string& fname,
int fd) {
return options.use_direct_reads
This conversation was marked as resolved.
Show resolved Hide resolved
? PosixFileSystem::GetLogicalBlockSize(fname, fd)
: kDefaultPageSize;
}

PosixFileSystem::PosixFileSystem()
: checkedDiskForMmap_(false),
forceMmapOff_(false),
Expand Down