-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Handle return code by io_uring_submit_and_wait() and io_uring_wait_cqe() #8311
Changes from all commits
08683ee
f50869d
93293e8
f3522a1
a8e92ad
99aa685
4219ed5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,11 @@ | |
#include <sys/ioctl.h> | ||
#endif | ||
|
||
#if defined(ROCKSDB_IOURING_PRESENT) | ||
#include <liburing.h> | ||
#include <sys/uio.h> | ||
#endif | ||
|
||
#include <sys/types.h> | ||
|
||
#include <iostream> | ||
|
@@ -1359,6 +1364,117 @@ TEST_F(EnvPosixTest, MultiReadNonAlignedLargeNum) { | |
} | ||
} | ||
|
||
#if defined(ROCKSDB_IOURING_PRESENT) | ||
void GenerateFilesAndRequest(Env* env, const std::string& fname, | ||
std::vector<ReadRequest>* ret_reqs, | ||
std::vector<std::string>* scratches) { | ||
const size_t kTotalSize = 81920; | ||
Random rnd(301); | ||
std::string expected_data = rnd.RandomString(kTotalSize); | ||
|
||
// Create file. | ||
{ | ||
std::unique_ptr<WritableFile> wfile; | ||
ASSERT_OK(env->NewWritableFile(fname, &wfile, EnvOptions())); | ||
ASSERT_OK(wfile->Append(expected_data)); | ||
ASSERT_OK(wfile->Close()); | ||
} | ||
|
||
// Right now kIoUringDepth is hard coded as 256, so we need very large | ||
// number of keys to cover the case of multiple rounds of submissions. | ||
// Right now the test latency is still acceptable. If it ends up with | ||
// too long, we can modify the io uring depth with SyncPoint here. | ||
const int num_reads = 3; | ||
std::vector<size_t> offsets = {10000, 20000, 30000}; | ||
std::vector<size_t> lens = {3000, 200, 100}; | ||
|
||
// Create requests | ||
scratches->reserve(num_reads); | ||
std::vector<ReadRequest>& reqs = *ret_reqs; | ||
reqs.resize(num_reads); | ||
for (int i = 0; i < num_reads; ++i) { | ||
reqs[i].offset = offsets[i]; | ||
reqs[i].len = lens[i]; | ||
scratches->emplace_back(reqs[i].len, ' '); | ||
reqs[i].scratch = const_cast<char*>(scratches->back().data()); | ||
} | ||
} | ||
|
||
TEST_F(EnvPosixTest, MultiReadIOUringError) { | ||
// In this test we don't do aligned read, wo it doesn't work for | ||
// direct I/O case. | ||
EnvOptions soptions; | ||
soptions.use_direct_reads = soptions.use_direct_writes = false; | ||
std::string fname = test::PerThreadDBPath(env_, "testfile"); | ||
|
||
std::vector<std::string> scratches; | ||
std::vector<ReadRequest> reqs; | ||
GenerateFilesAndRequest(env_, fname, &reqs, &scratches); | ||
// Query the data | ||
std::unique_ptr<RandomAccessFile> file; | ||
ASSERT_OK(env_->NewRandomAccessFile(fname, &file, soptions)); | ||
|
||
bool io_uring_wait_cqe_called = false; | ||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack( | ||
Comment on lines
+1417
to
+1418
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens on platforms that do not support io_uring? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. io_uring_wait_cqe_called will not be called and we won't check return value to be non-OK. |
||
"PosixRandomAccessFile::MultiRead:io_uring_wait_cqe:return", | ||
[&](void* arg) { | ||
if (!io_uring_wait_cqe_called) { | ||
io_uring_wait_cqe_called = true; | ||
ssize_t& ret = *(static_cast<ssize_t*>(arg)); | ||
ret = 1; | ||
} | ||
}); | ||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->EnableProcessing(); | ||
|
||
Status s = file->MultiRead(reqs.data(), reqs.size()); | ||
if (io_uring_wait_cqe_called) { | ||
ASSERT_NOK(s); | ||
} | ||
Comment on lines
+1429
to
+1432
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like it should fail the ASSERT_STATUS_CHECKED calls if the platform does not support io_uring. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does "fail the ASSERT_STATUS_CHECKED calls" mean? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you compile with ASSERT_STATUS_CHECKED=1, then a status code must be checked or it aborts with a stack trace. If the uring condition is false, then "s" is never checked. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh, good point. Since the tests are passing, I am going to do it as a follow up. |
||
|
||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing(); | ||
} | ||
|
||
TEST_F(EnvPosixTest, MultiReadIOUringError2) { | ||
// In this test we don't do aligned read, wo it doesn't work for | ||
// direct I/O case. | ||
EnvOptions soptions; | ||
soptions.use_direct_reads = soptions.use_direct_writes = false; | ||
std::string fname = test::PerThreadDBPath(env_, "testfile"); | ||
|
||
std::vector<std::string> scratches; | ||
std::vector<ReadRequest> reqs; | ||
GenerateFilesAndRequest(env_, fname, &reqs, &scratches); | ||
// Query the data | ||
std::unique_ptr<RandomAccessFile> file; | ||
ASSERT_OK(env_->NewRandomAccessFile(fname, &file, soptions)); | ||
|
||
bool io_uring_submit_and_wait_called = false; | ||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack( | ||
"PosixRandomAccessFile::MultiRead:io_uring_submit_and_wait:return1", | ||
[&](void* arg) { | ||
io_uring_submit_and_wait_called = true; | ||
ssize_t* ret = static_cast<ssize_t*>(arg); | ||
(*ret)--; | ||
}); | ||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack( | ||
"PosixRandomAccessFile::MultiRead:io_uring_submit_and_wait:return2", | ||
[&](void* arg) { | ||
struct io_uring* iu = static_cast<struct io_uring*>(arg); | ||
struct io_uring_cqe* cqe; | ||
assert(io_uring_wait_cqe(iu, &cqe) == 0); | ||
io_uring_cqe_seen(iu, cqe); | ||
}); | ||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->EnableProcessing(); | ||
|
||
Status s = file->MultiRead(reqs.data(), reqs.size()); | ||
if (io_uring_submit_and_wait_called) { | ||
ASSERT_NOK(s); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like it should fail the ASSERT_STATUS_CHECKED calls if the platform does not support io_uring. |
||
|
||
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing(); | ||
} | ||
#endif // ROCKSDB_IOURING_PRESENT | ||
|
||
// Only works in linux platforms | ||
#ifdef OS_WIN | ||
TEST_P(EnvPosixTestWithParam, DISABLED_InvalidateCache) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is copied from line 1276...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just was not know what "wo" means. Write only or is it a typo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know either...