Skip to content

Skip remote content upload when the remote cache is read-only - #178

Open
Pavlo Tubolets (tubolets) wants to merge 1 commit into
microsoft:mainfrom
tubolets:fix/skip-remote-content-upload-when-readonly
Open

Skip remote content upload when the remote cache is read-only#178
Pavlo Tubolets (tubolets) wants to merge 1 commit into
microsoft:mainfrom
tubolets:fix/skip-remote-content-upload-when-readonly

Conversation

@tubolets

Copy link
Copy Markdown

RemoteCacheIsReadOnly suppresses content hash list publication but not content upload, so a read-only client uploads content that no later build can ever retrieve — nothing references it. It costs egress, storage and build time for no benefit.

CasCacheClient holds both the raw _remoteCacheSession and the _twoLevelCacheSession built from TwoLevelCacheConfiguration. AddNodeAsync uploads content through the raw session without consulting the flag, while the content hash list goes through the two-level session, which honours it.

Changes

  • Capture RemoteCacheIsReadOnly from the passed TwoLevelCacheConfiguration and skip the remote upload block when it is set. This also elides the remote PinBulkAsync calls, which were made only to decide what to upload.
  • Read path is unchanged.

Validation

  • dotnet build MSBuildCache.sln -c Release: succeeded, 0 warnings, 0 errors
  • dotnet test MSBuildCache.sln -c Release --no-build: 547/550 passed. The 3 net472 failures are a pre-existing The tools version "Current" is unrecognized environment issue in MSBuildCachePluginBaseTests; an unmodified checkout fails the same 3.

No unit test added: there is no mock ICacheSession in Common.Tests to build an AddNodeAsync harness on, and CasCacheClientTests currently only covers the static GetAddNodeResult helper. Happy to add a mock session and a regression test if you'd like it in this PR.

Fixes: #177

CasCacheClient holds two sessions: the raw _remoteCacheSession and the
_twoLevelCacheSession built from TwoLevelCacheConfiguration. When adding a
node, content was uploaded directly through _remoteCacheSession without
consulting RemoteCacheIsReadOnly, while the content hash list that would
reference that content is published through _twoLevelCacheSession, which does
honor it.

The result is that a read-only client uploads content that can never be
retrieved: no content hash list ever points at it, so no subsequent build can
hit on it. The upload only costs egress, storage and build time, and leaves
unreferenced blobs behind for lifecycle policies to collect.

Guard the upload block on the read-only flag, which also elides the remote
pin calls that were only made to decide what to upload.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RemoteCacheIsReadOnly still uploads content to the remote cache

1 participant