-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
feat(gc): record workspace manifest and target dir in global cache tracker #13846
base: master
Are you sure you want to change the base?
Conversation
5f32f71
to
15e2863
Compare
basic_migration( | ||
"CREATE TABLE workspace_manifest_index ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
name TEXT UNIQUE NOT NULL, | ||
timestamp INTEGER NOT NULL | ||
)", | ||
), | ||
basic_migration( | ||
"CREATE TABLE target_dir_index ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
name TEXT UNIQUE NOT NULL, | ||
timestamp INTEGER NOT NULL | ||
)", | ||
), | ||
basic_migration( | ||
"CREATE TABLE workspace_src ( | ||
workspace_id INTEGER NOT NULL, | ||
target_dir_id INTEGER NOT NULL, | ||
timestamp INTEGER NOT NULL, | ||
PRIMARY KEY (workspace_id, target_dir_id), | ||
FOREIGN KEY (workspace_id) REFERENCES workspace_manifest_index (id) ON DELETE CASCADE, | ||
FOREIGN KEY (target_dir_id) REFERENCES target_dir_index (id) ON DELETE CASCADE | ||
)", |
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.
Whats the motivation for
- Tracking this as 3 separate tables
- Having timestamps for workspace dir, target dir, and workspace dir + target dir
/// New workspace manifest entries to insert. | ||
workspace_db_timestamps: HashMap<WorkspaceManifestIndex, Timestamp>, | ||
/// New target dir entries to insert. | ||
target_dir_db_timestamps: HashMap<TargetDirIndex, Timestamp>, | ||
/// New workspace src entries to insert. | ||
workspace_src_timestamps: HashMap<WorkspaceSrc, Timestamp>, |
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.
What does db
mean in this context?
I think for git
git_db
is the.git
git_checkout
is a work dir of a shared.git
pub encoded_workspace_manifest_name: InternedString, | ||
pub encoded_target_dir_name: InternedString, |
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.
When the others refer to "encoded" they are referring to how we translate package names to file names.
That doesn't quite make sense here and just naming these target_dir
and workspace_manifest_path
should work
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'll rename it with target_dir_path
and workspace_manifest_path
for these naming.
Thanks.
/// Indicates the given [`WorkspaceManifest`] has been used right now. | ||
/// | ||
/// Also implicitly marks the workspace manifest used, too. | ||
pub fn mark_workspace_src_used(&mut self, workspace_src: WorkspaceSrc) { |
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.
Huh, I wonder why we exposed these in the API, rather than taking parameters. Seems like it creates more boilerplate for the callers
src/cargo/ops/cargo_compile/mod.rs
Outdated
@@ -264,6 +264,16 @@ pub fn create_bcx<'a, 'gctx>( | |||
HasDevUnits::No | |||
} | |||
}; | |||
let _ = &gctx.deferred_global_last_use()?.mark_workspace_src_used( |
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.
Why let _ = &
?
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.
If we remove let _ = &
, rustc would be warning as follow
rustc: unused borrow that must be used (unused_must_use)
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 removed it locally and didn't get any message...
gctx.deferred_global_last_use()?
.mark_workspace_src_used(global_cache_tracker::WorkspaceSrc {
workspace_manifest_name: InternedString::new(ws.root_manifest().to_str().unwrap()),
target_dir_name: InternedString::new(
ws.target_dir().as_path_unlocked().to_str().unwrap(),
),
});
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.
This is the error msg where runs on CI.
https://github.com/rust-lang/cargo/actions/runs/9055535414/job/24876799051#step:5:687
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.
That has a leading &
that can be removed
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 works. Thanks, I've updated.
@@ -1632,6 +1734,32 @@ impl DeferredGlobalLastUse { | |||
); | |||
} | |||
|
|||
// Flushes all of the `target_dir_db_timestamps` to the database, |
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.
Review note: I've not yet dug into all of the DB operations
9f069a9
to
d55dda7
Compare
7d4fbbe
to
481de08
Compare
☔ The latest upstream changes (presumably #13979) made this pull request unmergeable. Please resolve the merge conflicts. |
As this is marked as a draft, @baby230211 what do you see as the next steps before marking this ready for review? |
@epage , Sorry for pending this PR so long, the final step here is to record the manifest lock file in manifest table i think. |
You're ok. I just wanted to check if there was something waiting on me. |
Hello @epage , i would like to re-work on this PR recently. |
Lockfile tracking was mostly intended to prep for #13137. We'll likely need to database migrations anyways so probably fine to skip for now so long as we understand how we would support it in the future. |
What does this PR try to resolve?
Fix #13136
This PR aims to track of the following data in GC for further garbage collection use.
There will be three new table for this features.
How should we test and review this PR?