-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Add cache state to task summaries on real runs #4225
Merged
mehulkar
merged 6 commits into
main
from
mehulkar/turbo-872-add-cache-state-to-run-summary
Mar 28, 2023
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
88fdbf9
Add test case to ensure cacheState is correct on RunSummaries
mehulkar 3e78919
Set cacheStatus on real runs
mehulkar 79a6306
Fix unit tests
mehulkar 2d225d5
Fix lint
mehulkar 90eadb9
Add a sleep statement
mehulkar 1887d46
Merge branch 'main' into mehulkar/turbo-872-add-cache-state-to-run-su…
mehulkar 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 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 |
---|---|---|
|
@@ -20,7 +20,7 @@ import ( | |
type Cache interface { | ||
// Fetch returns true if there is a cache it. It is expected to move files | ||
// into their correct position as a side effect | ||
Fetch(anchor turbopath.AbsoluteSystemPath, hash string, files []string) (bool, []turbopath.AnchoredSystemPath, int, error) | ||
Fetch(anchor turbopath.AbsoluteSystemPath, hash string, files []string) (ItemStatus, []turbopath.AnchoredSystemPath, int, error) | ||
Exists(hash string) ItemStatus | ||
// Put caches files for a given hash | ||
Put(anchor turbopath.AbsoluteSystemPath, hash string, duration int, files []turbopath.AnchoredSystemPath) error | ||
|
@@ -232,17 +232,24 @@ func (mplex *cacheMultiplexer) removeCache(removal *cacheRemoval) { | |
} | ||
} | ||
|
||
func (mplex *cacheMultiplexer) Fetch(anchor turbopath.AbsoluteSystemPath, key string, files []string) (bool, []turbopath.AnchoredSystemPath, int, error) { | ||
func (mplex *cacheMultiplexer) Fetch(anchor turbopath.AbsoluteSystemPath, key string, files []string) (ItemStatus, []turbopath.AnchoredSystemPath, int, error) { | ||
// Make a shallow copy of the caches, since storeUntil can call removeCache | ||
mplex.mu.RLock() | ||
caches := make([]Cache, len(mplex.caches)) | ||
copy(caches, mplex.caches) | ||
mplex.mu.RUnlock() | ||
|
||
// We need to return a composite cache status from multiple caches | ||
// Initialize the empty struct so we can assign values to it. This is similar | ||
// to how the Exists() method works. | ||
combinedCacheState := ItemStatus{} | ||
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. This is modeled after how |
||
|
||
// Retrieve from caches sequentially; if we did them simultaneously we could | ||
// easily write the same file from two goroutines at once. | ||
for i, cache := range caches { | ||
ok, actualFiles, duration, err := cache.Fetch(anchor, key, files) | ||
itemStatus, actualFiles, duration, err := cache.Fetch(anchor, key, files) | ||
ok := itemStatus.Local || itemStatus.Remote | ||
|
||
if err != nil { | ||
cd := &util.CacheDisabledError{} | ||
if errors.As(err, &cd) { | ||
|
@@ -261,11 +268,15 @@ func (mplex *cacheMultiplexer) Fetch(anchor turbopath.AbsoluteSystemPath, key st | |
// we have previously successfully stored in a higher-priority cache, and so the overall | ||
// result is a success at fetching. Storing in lower-priority caches is an optimization. | ||
_ = mplex.storeUntil(anchor, key, duration, actualFiles, i) | ||
return ok, actualFiles, duration, err | ||
|
||
// If another cache had already set this to true, we don't need to set it again from this cache | ||
combinedCacheState.Local = combinedCacheState.Local || itemStatus.Local | ||
combinedCacheState.Remote = combinedCacheState.Remote || itemStatus.Remote | ||
return combinedCacheState, actualFiles, duration, err | ||
} | ||
} | ||
|
||
return false, nil, 0, nil | ||
return ItemStatus{Local: false, Remote: false}, nil, 0, nil | ||
} | ||
|
||
func (mplex *cacheMultiplexer) Exists(target string) ItemStatus { | ||
|
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
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.
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.
seems-good.gif