-
Notifications
You must be signed in to change notification settings - Fork 111
Add support for time-based snapshot intervals #3918
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
Open
pcholakov
wants to merge
1
commit into
main
Choose a base branch
from
pavel/vowpsqrwurmp
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
| use std::collections::HashMap; | ||
| use std::path::{Path, PathBuf}; | ||
| use std::sync::Arc; | ||
| use std::time::{Duration, SystemTime, SystemTimeError}; | ||
|
|
||
| use anyhow::{Context, anyhow, bail}; | ||
| use bytes::BytesMut; | ||
|
|
@@ -152,6 +153,54 @@ impl LatestSnapshot { | |
| } | ||
| } | ||
|
|
||
| #[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy)] | ||
| pub enum ArchivedLsn { | ||
| None, | ||
| Snapshot { | ||
| // Ordering is intentional: LSN takes priority over elapsed wall clock time for comparisons | ||
| min_applied_lsn: Lsn, | ||
| created_at: SystemTime, | ||
| }, | ||
| } | ||
|
|
||
| impl ArchivedLsn { | ||
| pub fn get_min_applied_lsn(&self) -> Lsn { | ||
| match self { | ||
| ArchivedLsn::None => Lsn::INVALID, | ||
| ArchivedLsn::Snapshot { | ||
| min_applied_lsn, .. | ||
| } => *min_applied_lsn, | ||
| } | ||
| } | ||
|
|
||
| pub fn get_age(&self) -> Result<Duration, SystemTimeError> { | ||
| match self { | ||
| ArchivedLsn::None => Ok(Duration::MAX), | ||
| ArchivedLsn::Snapshot { created_at, .. } => { | ||
| SystemTime::now().duration_since(*created_at) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl From<&LatestSnapshot> for ArchivedLsn { | ||
| fn from(latest: &LatestSnapshot) -> Self { | ||
| ArchivedLsn::Snapshot { | ||
| min_applied_lsn: latest.min_applied_lsn, | ||
| created_at: latest.created_at.into(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl From<&PartitionSnapshotMetadata> for ArchivedLsn { | ||
| fn from(metadata: &PartitionSnapshotMetadata) -> Self { | ||
| ArchivedLsn::Snapshot { | ||
| min_applied_lsn: metadata.min_applied_lsn, | ||
| created_at: metadata.created_at.into(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| struct UniqueSnapshotKey { | ||
| lsn: Lsn, | ||
| snapshot_id: SnapshotId, | ||
|
|
@@ -543,14 +592,17 @@ impl SnapshotRepository { | |
|
|
||
| /// Retrieve the latest known LSN to be archived to the snapshot repository. | ||
| /// Response of `Ok(Lsn::INVALID)` indicates no existing snapshot for the partition. | ||
|
Contributor
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. Maybe update the comment. |
||
| pub async fn get_latest_archived_lsn(&self, partition_id: PartitionId) -> anyhow::Result<Lsn> { | ||
| pub async fn get_latest_archived_lsn( | ||
| &self, | ||
| partition_id: PartitionId, | ||
| ) -> anyhow::Result<ArchivedLsn> { | ||
| let latest_path = self.get_latest_snapshot_pointer(partition_id); | ||
|
|
||
| let latest = match self.object_store.get(&latest_path).await { | ||
| Ok(result) => result, | ||
| Err(object_store::Error::NotFound { .. }) => { | ||
| debug!("Latest snapshot data not found in repository"); | ||
| return Ok(Lsn::INVALID); | ||
| return Ok(ArchivedLsn::None); | ||
| } | ||
| Err(e) => { | ||
| return Err(anyhow::Error::new(e).context(format!( | ||
|
|
@@ -562,7 +614,7 @@ impl SnapshotRepository { | |
| let latest: LatestSnapshot = serde_json::from_slice(&latest.bytes().await?)?; | ||
| debug!(partition_id = %partition_id, snapshot_id = %latest.snapshot_id, "Latest snapshot metadata: {:?}", latest); | ||
|
|
||
| Ok(latest.min_applied_lsn) | ||
| Ok(ArchivedLsn::from(&latest)) | ||
| } | ||
|
|
||
| async fn get_latest_snapshot_metadata_for_update( | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is it important that we distinguish between created_at > now and created_at == now? If not, then we might get rid fo the error case.