Skip to content

Prefetch the targets of symlinked .bzl files in the RRCC - #30517

Closed
fmeum wants to merge 3 commits into
bazelbuild:masterfrom
fmeum:rrcc-prefetch-symlink-targets
Closed

fmeum wants to merge 3 commits into
bazelbuild:masterfrom
fmeum:rrcc-prefetch-symlink-targets

Conversation

@fmeum

@fmeum fmeum commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Description

When a repo is injected from the remote repo contents cache, .bzl and REPO.bazel files are prefetched to the native file system and reads of such paths are redirected there. Symlinks are only injected into the in-memory overlay, so #30031 made the read side resolve symbolic links first, which serves a symlinked .bzl file from the regular file it points at.

That only helps if the target's own name happens to make it eligible for prefetching, e.g. helper.bzl -> real_helper.bzl. A symlink such as helper.bzl -> real_helper.txt resolves to a path that was never prefetched and thus falls back to a lazy blob download while the package that loads it is being evaluated.

This PR collects symlinks whose name makes them eligible for prefetching during injection and, once the repo has been injected in full and their targets can be resolved, adds those targets to the set of files to prefetch. The read side now also considers the path before symlink resolution, so the prefetched target is used no matter which end of the chain is named like a loaded file.

Motivation

Loading a .bzl file that is a symlink to a differently named file costs a sequential round-trip to the remote cache in the middle of the loading phase, which is exactly what prefetching .bzl files during injection is meant to avoid: the loads between .bzl files form a DAG that can only be discovered layer by layer, so each such read serializes with the next.

Follow-up to #30031.

Build API Changes

No

Checklist

  • I have added tests for the new use cases (if any).
  • I have updated the documentation (if applicable).

Release Notes

RELNOTES: None

When a repo is injected from the remote repo contents cache, `.bzl` and
`REPO.bazel` files are prefetched to the native file system and all reads
of such paths are redirected there. Symlinks are only injected into the
in-memory overlay, so a symlinked `.bzl` file is served through its target,
which bazelbuild#30031 achieved by resolving
symbolic links before the redirect.

That only works if the target's own name happens to make it eligible for
prefetching. A symlink `helper.bzl -> helper.txt` resolves to a path that
isn't prefetched and thus falls back to a lazy blob download during
loading, which is exactly the sequential round-trip the prefetching is
meant to avoid.

Collect symlinks whose name makes them eligible during injection and, once
the repo has been injected in full and their targets can be resolved, add
those targets to the set of files to prefetch. The read side now considers
the path before symlink resolution as well, so that the prefetched target
is used no matter which end of the chain is named like a loaded file.
@fmeum

fmeum commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator Author

@bazel-io fork 9.3.0

@fmeum
fmeum marked this pull request as ready for review July 29, 2026 12:24
@fmeum
fmeum requested review from a team, Wyverald and meteorcloudy as code owners July 29, 2026 12:24
@fmeum
fmeum requested review from coeuvre and removed request for a team, Wyverald and meteorcloudy July 29, 2026 12:24
@github-actions github-actions Bot added team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. team-Remote-Exec Issues and PRs for the Execution (Remote) team awaiting-review PR is awaiting review from an assigned reviewer labels Jul 29, 2026
@coeuvre coeuvre added awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally and removed awaiting-review PR is awaiting review from an assigned reviewer labels Jul 29, 2026
@iancha1992

Copy link
Copy Markdown
Contributor

@fmeum Could you please resolve the merge conflict? Thanks!

…nk-targets

% Conflicts:
%	src/main/java/com/google/devtools/build/lib/remote/RemoteExternalOverlayFileSystem.java
@fmeum

fmeum commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator Author

@iancha1992 done

@copybara-service copybara-service Bot closed this in 61574a9 Aug 3, 2026
@github-actions github-actions Bot removed the awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally label Aug 3, 2026
iancha1992 added a commit to iancha1992/bazel that referenced this pull request Aug 4, 2026
…d#30517)

### Description

When a repo is injected from the remote repo contents cache, `.bzl` and `REPO.bazel` files are prefetched to the native file system and reads of such paths are redirected there. Symlinks are only injected into the in-memory overlay, so bazelbuild#30031 made the read side resolve symbolic links first, which serves a symlinked `.bzl` file from the regular file it points at.

That only helps if the target's own name happens to make it eligible for prefetching, e.g. `helper.bzl -> real_helper.bzl`. A symlink such as `helper.bzl -> real_helper.txt` resolves to a path that was never prefetched and thus falls back to a lazy blob download while the package that loads it is being evaluated.

This PR collects symlinks whose name makes them eligible for prefetching during injection and, once the repo has been injected in full and their targets can be resolved, adds those targets to the set of files to prefetch. The read side now also considers the path before symlink resolution, so the prefetched target is used no matter which end of the chain is named like a loaded file.

### Motivation

Loading a `.bzl` file that is a symlink to a differently named file costs a sequential round-trip to the remote cache in the middle of the loading phase, which is exactly what prefetching `.bzl` files during injection is meant to avoid: the loads between `.bzl` files form a DAG that can only be discovered layer by layer, so each such read serializes with the next.

Follow-up to bazelbuild#30031.

### Build API Changes

No

### Checklist

- [x] I have added tests for the new use cases (if any).
- [ ] I have updated the documentation (if applicable).

### Release Notes

RELNOTES: None

Closes bazelbuild#30517.

PiperOrigin-RevId: 958506915
Change-Id: Ic9e740883683a626aebc17d5686f7c3e3426878c
fmeum pushed a commit to fmeum/bazel that referenced this pull request Aug 25, 2026
…d#30517)

### Description

When a repo is injected from the remote repo contents cache, `.bzl` and `REPO.bazel` files are prefetched to the native file system and reads of such paths are redirected there. Symlinks are only injected into the in-memory overlay, so bazelbuild#30031 made the read side resolve symbolic links first, which serves a symlinked `.bzl` file from the regular file it points at.

That only helps if the target's own name happens to make it eligible for prefetching, e.g. `helper.bzl -> real_helper.bzl`. A symlink such as `helper.bzl -> real_helper.txt` resolves to a path that was never prefetched and thus falls back to a lazy blob download while the package that loads it is being evaluated.

This PR collects symlinks whose name makes them eligible for prefetching during injection and, once the repo has been injected in full and their targets can be resolved, adds those targets to the set of files to prefetch. The read side now also considers the path before symlink resolution, so the prefetched target is used no matter which end of the chain is named like a loaded file.

### Motivation

Loading a `.bzl` file that is a symlink to a differently named file costs a sequential round-trip to the remote cache in the middle of the loading phase, which is exactly what prefetching `.bzl` files during injection is meant to avoid: the loads between `.bzl` files form a DAG that can only be discovered layer by layer, so each such read serializes with the next.

Follow-up to bazelbuild#30031.

### Build API Changes

No

### Checklist

- [x] I have added tests for the new use cases (if any).
- [ ] I have updated the documentation (if applicable).

### Release Notes

RELNOTES: None

Closes bazelbuild#30517.

PiperOrigin-RevId: 958506915
Change-Id: Ic9e740883683a626aebc17d5686f7c3e3426878c
(cherry picked from commit 61574a9)
bazel-io pushed a commit to bazel-io/bazel that referenced this pull request Sep 2, 2026
…azelbuild#30713)

### Description

When a repo is injected from the remote repo contents cache, `.bzl` and
`REPO.bazel` files are prefetched to the native file system and reads of
such paths are redirected there. Symlinks are only injected into the
in-memory overlay, so bazelbuild#30031 made the read side resolve symbolic links
first, which serves a symlinked `.bzl` file from the regular file it
points at.

That only helps if the target's own name happens to make it eligible for
prefetching, e.g. `helper.bzl -> real_helper.bzl`. A symlink such as
`helper.bzl -> real_helper.txt` resolves to a path that was never
prefetched and thus falls back to a lazy blob download while the package
that loads it is being evaluated.

This PR collects symlinks whose name makes them eligible for prefetching
during injection and, once the repo has been injected in full and their
targets can be resolved, adds those targets to the set of files to
prefetch. The read side now also considers the path before symlink
resolution, so the prefetched target is used no matter which end of the
chain is named like a loaded file.

### Motivation

Loading a `.bzl` file that is a symlink to a differently named file
costs a sequential round-trip to the remote cache in the middle of the
loading phase, which is exactly what prefetching `.bzl` files during
injection is meant to avoid: the loads between `.bzl` files form a DAG
that can only be discovered layer by layer, so each such read serializes
with the next.

Follow-up to bazelbuild#30031.

### Build API Changes

No

### Checklist

- [x] I have added tests for the new use cases (if any).
- [ ] I have updated the documentation (if applicable).

### Release Notes

RELNOTES: None

Closes bazelbuild#30517.

PiperOrigin-RevId: 958506915
Change-Id: Ic9e740883683a626aebc17d5686f7c3e3426878c
(cherry picked from commit 61574a9)


This PR also carries the prerequisite commit
bazelbuild@c37a6a1
("Improve path validation in remote repository contents cache."), which
touches the same injection code path and landed on master first.

Replaces bazelbuild#30579, which bundles the same two commits but does not build
on this branch: it hand-authors a new
`remote_external_overlay_file_system` target in
`src/main/java/com/google/devtools/build/lib/remote/BUILD` that depends
on `//src/main/proto:failure_details_java_proto` (the branch uses
`//src/main/protobuf`), so the target does not even analyze, and its
test uses `EventBusEventHandler`, which does not exist on this branch.

9.3.0 adaptation: The
`src/main/java/com/google/devtools/build/lib/remote/BUILD` split is not
needed because that package still has a single monolithic `remote`
target here, which already covers
`RemoteExternalOverlayFileSystem.java`; the same goes for the
`remote_external_overlay_file_system` entry in
`src/test/java/com/google/devtools/build/lib/remote/BUILD`, where only
the new `//src/main/java/com/google/devtools/build/lib/cmdline` dep is
required. The new test constructs the `Reporter` as `new Reporter(new
EventBus())` since `EventBusEventHandler` was introduced by a
master-only refactoring.

Closes bazelbuild#30520

---------

Co-authored-by: twerth <[email protected]>
Co-authored-by: Ian (Hee) Cha <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. team-Remote-Exec Issues and PRs for the Execution (Remote) team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants