-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test to exercise & document behavior when we exhaust slots (#61)
In #57 there were doubts about the behavior when we're waiting for slots, and when we return slots. This PR adds test cases that demonstrate the current behavior. The behavior demoed in `test_slot_exhaustion_behavior_when_op_completes_but_future_does_not_get_polled` might be surprising, but, is not a huge problem in Pageserver right now because generally we don't have that pattern in the codebase. Created an issue nonetheless, this can be improved: #60 closes #57
- Loading branch information
Showing
8 changed files
with
248 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,4 @@ tempfile = "3.6.0" | |
tracing-subscriber = "*" | ||
os_pipe = "1.1.4" | ||
assert-panic = "1.0.1" | ||
bytes = "*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
use std::time::Duration; | ||
|
||
pub(super) mod shared_system_handle; | ||
pub(crate) mod timerfd; | ||
|
||
pub(crate) const FOREVER: Duration = Duration::from_secs(365 * 24 * 60 * 60); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use bytes::Buf; | ||
use nix::sys::time::TimeSpec; | ||
use nix::sys::timerfd; | ||
use nix::sys::timerfd::ClockId; | ||
use uring_common::io_fd::IoFd; | ||
|
||
use nix::sys::timer::TimerSetTimeFlags; | ||
|
||
use nix::sys::timerfd::Expiration; | ||
|
||
use nix::sys::timerfd::TimerFlags; | ||
|
||
use std::time::Duration; | ||
|
||
use crate::SystemHandle; | ||
|
||
/// Abstraction for creating a timerfd. | ||
/// | ||
/// See [`oneshot`] for creating it, and [`read`] for using `tokio-epoll-uring` to read from it. | ||
pub struct TimerFd { | ||
pub(crate) timerfd: timerfd::TimerFd, | ||
} | ||
|
||
pub fn oneshot(duration: Duration) -> TimerFd { | ||
// setup a timerfd that will block readers forever | ||
let timerfd = timerfd::TimerFd::new(ClockId::CLOCK_MONOTONIC, TimerFlags::empty()) | ||
.expect("timerfd creation"); | ||
timerfd | ||
.set( | ||
Expiration::OneShot(TimeSpec::from_duration(duration)), | ||
TimerSetTimeFlags::empty(), | ||
) | ||
.unwrap(); | ||
TimerFd { timerfd } | ||
} | ||
|
||
impl TimerFd { | ||
pub fn set(&self, duration: Duration) { | ||
self.timerfd | ||
.set( | ||
Expiration::OneShot(TimeSpec::from_duration(duration)), | ||
TimerSetTimeFlags::empty(), | ||
) | ||
.unwrap() | ||
} | ||
} | ||
|
||
impl IoFd for TimerFd { | ||
// Safety: we own the timerfd, so, as per the trait definition, we're allowed to return the fd. | ||
unsafe fn as_fd(&self) -> i32 { | ||
use std::os::fd::AsRawFd; | ||
self.timerfd.as_raw_fd() | ||
} | ||
} | ||
|
||
pub async fn read<T>(fd: impl IoFd + Send, system: T) | ||
where | ||
T: AsRef<SystemHandle>, | ||
{ | ||
let value = vec![0u8; 8]; | ||
let ((_, value), res) = system.as_ref().read(fd, 0, value).await; | ||
let n: usize = res.unwrap(); | ||
assert_eq!(n, 8); | ||
let mut value = bytes::Bytes::from(value); | ||
assert_ne!(value.get_u64_ne(), 0); | ||
assert!(value.is_empty()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters