-
Notifications
You must be signed in to change notification settings - Fork 394
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pageserver: add
InProgress
tenant map state, use a sync lock for th…
…e map (#5367) ## Problem Follows on from #5299 - We didn't have a generic way to protect a tenant undergoing changes: `Tenant` had states, but for our arbitrary transitions between secondary/attached, we need a general way to say "reserve this tenant ID, and don't allow any other ops on it, but don't try and report it as being in any particular state". - The TenantsMap structure was behind an async RwLock, but it was never correct to hold it across await points: that would block any other changes for all tenants. ## Summary of changes - Add the `TenantSlot::InProgress` value. This means: - Incoming administrative operations on the tenant should retry later - Anything trying to read the live state of the tenant (e.g. a page service reader) should retry later or block. - Store TenantsMap in `std::sync::RwLock` - Provide an extended `get_active_tenant_with_timeout` for page_service to use, which will wait on InProgress slots as well as non-active tenants. Closes: #5378 --------- Co-authored-by: Christian Schwarz <christian@neon.tech>
- Loading branch information
Showing
17 changed files
with
1,146 additions
and
593 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use std::time::Duration; | ||
|
||
use tokio_util::sync::CancellationToken; | ||
|
||
pub enum TimeoutCancellableError { | ||
Timeout, | ||
Cancelled, | ||
} | ||
|
||
/// Wrap [`tokio::time::timeout`] with a CancellationToken. | ||
/// | ||
/// This wrapper is appropriate for any long running operation in a task | ||
/// that ought to respect a CancellationToken (which means most tasks). | ||
/// | ||
/// The only time you should use a bare tokio::timeout is when the future `F` | ||
/// itself respects a CancellationToken: otherwise, always use this wrapper | ||
/// with your CancellationToken to ensure that your task does not hold up | ||
/// graceful shutdown. | ||
pub async fn timeout_cancellable<F>( | ||
duration: Duration, | ||
cancel: &CancellationToken, | ||
future: F, | ||
) -> Result<F::Output, TimeoutCancellableError> | ||
where | ||
F: std::future::Future, | ||
{ | ||
tokio::select!( | ||
r = tokio::time::timeout(duration, future) => { | ||
r.map_err(|_| TimeoutCancellableError::Timeout) | ||
|
||
}, | ||
_ = cancel.cancelled() => { | ||
Err(TimeoutCancellableError::Cancelled) | ||
|
||
} | ||
) | ||
} |
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
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
Oops, something went wrong.
85cd97a
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.
2426 tests run: 2304 passed, 0 failed, 122 skipped (full report)
Code coverage (full report)
functions
:54.6% (8885 of 16273 functions)
lines
:81.7% (51197 of 62655 lines)
85cd97a at 2023-11-06T14:56:35.566Z :recycle: