-
Notifications
You must be signed in to change notification settings - Fork 286
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
Binary Cache: Add write-back support #1406
Open
sadroeck
wants to merge
1
commit into
microsoft:main
Choose a base branch
from
singlestore:binary-cache-write-back-support
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,18 +25,26 @@ | |
|
||
namespace vcpkg | ||
{ | ||
/// Unique identifier for a provider | ||
using ProviderId = size_t; | ||
|
||
struct CacheStatus | ||
{ | ||
using ReaderProviders = std::vector<const IReadBinaryProvider*>; | ||
|
||
bool should_attempt_precheck(const IReadBinaryProvider* sender) const noexcept; | ||
bool should_attempt_restore(const IReadBinaryProvider* sender) const noexcept; | ||
bool should_attempt_write_back(ProviderId provider_id) const noexcept; | ||
|
||
bool is_unavailable(const IReadBinaryProvider* sender) const noexcept; | ||
const IReadBinaryProvider* get_available_provider() const noexcept; | ||
ReaderProviders& get_unavailable_providers() noexcept; | ||
bool is_restored() const noexcept; | ||
|
||
void mark_unavailable(const IReadBinaryProvider* sender); | ||
void mark_available(const IReadBinaryProvider* sender) noexcept; | ||
void mark_restored() noexcept; | ||
void mark_written_back(ProviderId provider_id) noexcept; | ||
|
||
private: | ||
CacheStatusState m_status = CacheStatusState::unknown; | ||
|
@@ -75,10 +83,13 @@ namespace vcpkg | |
|
||
/// Called upon a successful build of `action` to store those contents in the binary cache. | ||
/// returns the number of successful uploads | ||
virtual size_t push_success(const BinaryPackageWriteInfo& request, MessageSink& msg_sink) = 0; | ||
virtual size_t push_success(const BinaryPackageWriteInfo& request, | ||
MessageSink& msg_sink, | ||
CacheStatus& cache_status) = 0; | ||
|
||
virtual bool needs_nuspec_data() const = 0; | ||
virtual bool needs_zip_file() const = 0; | ||
virtual std::vector<ProviderId> get_provider_ids() const = 0; | ||
}; | ||
|
||
struct IReadBinaryProvider | ||
|
@@ -93,6 +104,10 @@ namespace vcpkg | |
/// Prerequisites: actions[i].package_abi(), out_status.size() == actions.size() | ||
virtual void fetch(View<const InstallPlanAction*> actions, Span<RestoreResult> out_status) const = 0; | ||
|
||
/// Flag to indicate if the provider supports an efficient check to see if a certain set of packages are | ||
/// available. If not, packages will assumed to be present & will always be fetched. | ||
virtual bool can_precheck() const = 0; | ||
|
||
/// Checks whether the `actions` are present in the cache, without restoring them. | ||
/// | ||
/// Used by CI to determine missing packages. For each `i`, out_status[i] should be set to | ||
|
@@ -103,6 +118,11 @@ namespace vcpkg | |
|
||
virtual LocalizedString restored_message(size_t count, | ||
std::chrono::high_resolution_clock::duration elapsed) const = 0; | ||
|
||
/// Unique identifier for this provider. | ||
/// | ||
/// Used by the cache to exclude cache providers during the write-back phase. | ||
virtual ProviderId id() const = 0; | ||
}; | ||
|
||
struct UrlTemplate | ||
|
@@ -114,44 +134,62 @@ namespace vcpkg | |
std::string instantiate_variables(const BinaryPackageReadInfo& info) const; | ||
}; | ||
|
||
struct GithubActionsInfo | ||
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. Don't think this should be checked in :) |
||
{ | ||
}; | ||
|
||
struct NuGetRepoInfo | ||
{ | ||
std::string repo; | ||
std::string branch; | ||
std::string commit; | ||
}; | ||
|
||
enum class CacheType | ||
{ | ||
Read, | ||
Write, | ||
ReadWrite | ||
}; | ||
|
||
template<typename T> | ||
struct CacheProvider | ||
{ | ||
ProviderId id; | ||
T source; | ||
CacheType cache_type; | ||
|
||
[[nodiscard]] constexpr bool is_read() const noexcept | ||
{ | ||
return cache_type == CacheType::Read || cache_type == CacheType::ReadWrite; | ||
} | ||
|
||
[[nodiscard]] constexpr bool is_write() const noexcept | ||
{ | ||
return cache_type == CacheType::Write || cache_type == CacheType::ReadWrite; | ||
} | ||
}; | ||
|
||
template<typename T> | ||
using ProviderList = std::vector<CacheProvider<T>>; | ||
|
||
struct BinaryConfigParserState | ||
{ | ||
ProviderId provider_count = 0; | ||
bool nuget_interactive = false; | ||
std::set<StringLiteral> binary_cache_providers; | ||
|
||
std::string nugettimeout = "100"; | ||
|
||
std::vector<Path> archives_to_read; | ||
std::vector<Path> archives_to_write; | ||
|
||
std::vector<UrlTemplate> url_templates_to_get; | ||
std::vector<UrlTemplate> url_templates_to_put; | ||
|
||
std::vector<std::string> gcs_read_prefixes; | ||
std::vector<std::string> gcs_write_prefixes; | ||
|
||
std::vector<std::string> aws_read_prefixes; | ||
std::vector<std::string> aws_write_prefixes; | ||
ProviderList<Path> archives; | ||
ProviderList<UrlTemplate> url_templates; | ||
ProviderList<std::string> gcs_prefixes; | ||
ProviderList<std::string> aws_prefixes; | ||
bool aws_no_sign_request = false; | ||
|
||
std::vector<std::string> cos_read_prefixes; | ||
std::vector<std::string> cos_write_prefixes; | ||
|
||
bool gha_write = false; | ||
bool gha_read = false; | ||
|
||
std::vector<std::string> sources_to_read; | ||
std::vector<std::string> sources_to_write; | ||
|
||
std::vector<Path> configs_to_read; | ||
std::vector<Path> configs_to_write; | ||
ProviderList<std::string> cos_prefixes; | ||
Optional<CacheProvider<GithubActionsInfo>> gha; | ||
ProviderList<std::string> sources; | ||
ProviderList<Path> configs; | ||
|
||
std::vector<std::string> secrets; | ||
|
||
|
@@ -173,6 +211,8 @@ namespace vcpkg | |
NuGetRepoInfo nuget_repo; | ||
}; | ||
|
||
[[nodiscard]] bool HasWriteOnlyProviders(const BinaryProviders& providers); | ||
|
||
struct ReadOnlyBinaryCache | ||
{ | ||
ReadOnlyBinaryCache() = default; | ||
|
@@ -182,7 +222,7 @@ namespace vcpkg | |
/// executing `actions`. | ||
void fetch(View<InstallPlanAction> actions); | ||
|
||
bool is_restored(const InstallPlanAction& ipa) const; | ||
Optional<CacheStatus> cache_status(const InstallPlanAction& ipa) const; | ||
|
||
/// Checks whether the `actions` are present in the cache, without restoring them. Used by CI to determine | ||
/// missing packages. | ||
|
@@ -192,6 +232,10 @@ namespace vcpkg | |
protected: | ||
BinaryProviders m_config; | ||
|
||
/// Flag to indicate that at least one provider is write-only. This implies that the write-back phase should | ||
/// always take place for every Cache item. | ||
bool m_has_write_only_providers; | ||
|
||
std::unordered_map<std::string, CacheStatus> m_status; | ||
}; | ||
|
||
|
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.
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.
copy_if
so I think that should be in the name.key_equal
above)