-
Notifications
You must be signed in to change notification settings - Fork 28.5k
[devtools] Add a query parameter to restart endpoint to invalidate the persistent cache #79425
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
bgw
wants to merge
4
commits into
canary
Choose a base branch
from
bgw/dev-invalidate-cache
base: canary
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.
+222
−27
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2d47bf2
feat(dev-overlay): Add a query parameter to restart endpoint to inval…
bgw 6f89e63
Rename invalidate method, include invalidation in telemetry extras
bgw 0a70070
Move more responsibilities into the KeyValueDatabaseBackingStorage co…
bgw 46c9d20
Add comment about performing invalidation before prevent_write
bgw 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
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
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
69 changes: 69 additions & 0 deletions
69
turbopack/crates/turbo-tasks-backend/src/database/db_invalidation.rs
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use std::{ | ||
fs::{self, read_dir}, | ||
io, | ||
path::Path, | ||
}; | ||
|
||
use anyhow::Context; | ||
|
||
const INVALIDATION_MARKER: &str = "__turbo_tasks_invalidated_db"; | ||
|
||
/// Atomically write an invalidation marker. | ||
/// | ||
/// Because attempting to delete currently open database files could cause issues, actual deletion | ||
/// of files is deferred until the next start-up (in [`check_db_invalidation_and_cleanup`]). | ||
/// | ||
/// In the case that no database is currently open (e.g. via a separate CLI subcommand), you should | ||
/// call [`cleanup_db`] *after* this to eagerly remove the database files. | ||
/// | ||
/// This should be run with the base (non-versioned) path, as that likely aligns closest with user | ||
/// expectations (e.g. if they're clearing the cache for disk space reasons). | ||
pub fn invalidate_db(base_path: &Path) -> anyhow::Result<()> { | ||
fs::write(base_path.join(INVALIDATION_MARKER), [0u8; 0])?; | ||
Ok(()) | ||
} | ||
|
||
/// Called during startup. See if the db is in a partially-completed invalidation state. Find and | ||
/// delete any invalidated database files. | ||
/// | ||
/// This should be run with the base (non-versioned) path. | ||
pub fn check_db_invalidation_and_cleanup(base_path: &Path) -> anyhow::Result<()> { | ||
if fs::exists(base_path.join(INVALIDATION_MARKER))? { | ||
// if this cleanup fails, we might try to open an invalid database later, so it's best to | ||
// just propagate the error here. | ||
cleanup_db(base_path)?; | ||
}; | ||
Ok(()) | ||
} | ||
|
||
/// Helper for [`check_db_invalidation_and_cleanup`]. You can call this to explicitly clean up a | ||
/// database after running [`invalidate_db`] when turbo-tasks is not running. | ||
/// | ||
/// You should not run this if the database has not yet been invalidated, as this operation is not | ||
/// atomic and could result in a partially-deleted and corrupted database. | ||
pub fn cleanup_db(base_path: &Path) -> anyhow::Result<()> { | ||
cleanup_db_inner(base_path).with_context(|| { | ||
format!( | ||
"Unable to remove invalid database. If this issue persists you can work around by \ | ||
deleting {base_path:?}." | ||
) | ||
}) | ||
} | ||
|
||
fn cleanup_db_inner(base_path: &Path) -> io::Result<()> { | ||
let Ok(contents) = read_dir(base_path) else { | ||
return Ok(()); | ||
}; | ||
|
||
// delete everything except the invalidation marker | ||
for entry in contents { | ||
let entry = entry?; | ||
if entry.file_name() != INVALIDATION_MARKER { | ||
fs::remove_dir_all(entry.path())?; | ||
} | ||
} | ||
|
||
// delete the invalidation marker last, once we're sure everything is cleaned up | ||
fs::remove_file(base_path.join(INVALIDATION_MARKER))?; | ||
Ok(()) | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.