Skip to content
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

Bazel info -> cquery invalidate part of cache #22360

Open
SinimaWath opened this issue May 14, 2024 · 12 comments
Open

Bazel info -> cquery invalidate part of cache #22360

SinimaWath opened this issue May 14, 2024 · 12 comments
Labels
team-Core Skyframe, bazel query, BEP, options parsing, bazelrc type: bug untriaged

Comments

@SinimaWath
Copy link

SinimaWath commented May 14, 2024

Description of the bug:

Running:
1 - bazel info
2 - bazel cquery target
3 - bazel run/build target

Invalidate part of cache (for example, suddenly npm modules start extracting, but must be taken from cache). For more info see reproduction steps

Which category does this issue belong to?

Core

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Add to ~/.bazelrc:

common --experimental_check_output_files=false
common --noexperimental_check_external_repository_files

1 - git clone https://github.com/bazelbuild/examples.git - Clone examples repo
2 - cd frontend - go to frontend example.
3 - bazel build //next.js:next - build application
4 - bazel build //next.js:next - check build is from cache
5 - bazel info && bazel cquery //next.js:next && bazel build //next.js:next

After step 5, in logs (bazel info server_log) we see there were Extracting npm package (building without info and cquery doesn't have extracting npm package):

240514 09:51:17.209:I 6609 [com.google.devtools.build.lib.runtime.BuildSummaryStatsModule.buildComplete] Critical Path: 0.08s, Remote (0.00% of the time): [parse: 0.00%, queue: 0.00%, network: 0.00%, upload: 0.00%, setup: 0.00%, process: 0.00%, fetch: 0.00%, retry: 0.00%, processOutputs: 0.00%, other: 0.00%, input files: 0, input bytes: 0, memory bytes: 0]
  0.00s action 'JsRunBinary next.js/.next'
  0.00s action 'Transpiling & type-checking TypeScript project @@//next.js/pages:pages [tsc -p next.js/tsconfig.json]'
  0.00s action 'Transpiling & type-checking TypeScript project @@//next.js/pages/api:api [tsc -p next.js/tsconfig.json]'
  0.08s action 'Extracting npm package next@13.0.5_-1955910335'
240514 09:51:17.209:I 6609 [com.google.devtools.build.lib.runtime.BuildSummaryStatsModule.buildComplete] Slowest actions:
  0.08s action 'Extracting npm package next@13.0.5_-1955910335'
  0.04s action 'Extracting npm package next@13.0.5_-1955910335 [for tool]'
  0.04s action 'Copying directory packages/one/one'
  0.04s action 'Extracting npm package @babel/generator@7.23.5 [for tool]'
  0.02s action 'Extracting npm package scheduler@0.23.0 [for tool]'
  0.02s action 'Extracting npm package @babel/types@7.23.5 [for tool]'
  0.02s action 'Extracting npm package react-dom@18.2.0_react_18.2.0'
  0.02s action 'Extracting npm package styled-jsx@5.1.0_986221465 [for tool]'
  0.02s action 'Extracting npm package kind-of@3.2.2'
  0.02s action 'Extracting npm package @babel/helper-hoist-variables@7.22.5 [for tool]'
  0.02s action 'Extracting npm package @babel/helper-module-transforms@7.23.3_at_babel_core_7.23.5 [for tool]'
  0.02s action 'Extracting npm package supports-color@5.5.0 [for tool]'
  0.02s action 'Extracting npm package is-number@6.0.0'
  0.01s action 'Extracting npm package @babel/helper-validator-option@7.23.5 [for tool]'
  0.01s action 'Extracting npm package caniuse-lite@1.0.30001542'
  0.01s action 'Extracting npm package @babel/helper-environment-visitor@7.22.20 [for tool]'
  0.01s action 'Extracting npm package @babel/parser@7.23.5 [for tool]'
  0.01s action 'Extracting npm package @babel/generator@7.23.5'
  0.01s action 'Extracting npm package @babel/traverse@7.23.5 [for tool]'
  0.01s action 'Extracting npm package @jridgewell/trace-mapping@0.3.19 [for tool]'
  0.01s action 'Extracting npm package @babel/parser@7.23.5'
  0.01s action 'BazelWorkspaceStatusAction stable-status.txt'
  0.01s action 'Extracting npm package typescript@4.9.3'
  0.01s action 'Extracting npm package @babel/template@7.22.15'
  0.01s action 'Extracting npm package @babel/helper-function-name@7.23.0 [for tool]'
  0.01s action 'Extracting npm package @babel/core@7.23.5 [for tool]'
  0.01s action 'Extracting npm package @babel/template@7.22.15 [for tool]'
  0.01s action 'Extracting npm package postcss@8.4.14'
  0.01s action 'Extracting npm package @babel/helper-compilation-targets@7.22.15'
  0.01s action 'Extracting npm package semver@6.3.1 [for tool]'
240514 09:51:17.212:I 6609 [com.google.devtools.build.lib.sandbox.AsynchronousTreeDeleter.setThreads] Resizing async tree deletion pool to 4 threads
240514 09:51:17.212:I 6609 [com.google.devtools.build.lib.runtime.CacheFileDigestsModule.logStats] Accumulated cache stats after command: hit count=63355, miss count=17619, hit rate=0.782412, eviction count=0
240514 09:51:17.212:I 6609 [com.google.devtools.build.lib.runtime.CacheFileDigestsModule.logStats] Cache stats for finished command: hit count=12671, miss count=1, hit rate=0.999921, eviction count=0

Which operating system are you running Bazel on?

macos

What is the output of bazel info release?

release 7.1.0

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse HEAD ?

No response

Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.

No response

Have you found anything relevant by searching the web?

#17914

Any other information, logs, or outputs that you want to share?

GrpcServerImpl.executeCommand logs, without --client-env (removed it)



240515 12:10:24.009:I 8721 [com.google.devtools.build.lib.server.GrpcServerImpl.executeCommand] [info, --startup_time=32, --command_wait_time=0, --extract_data_time=0, --binary_path=/Users/user_name/Library/Caches/bazelisk/downloads/sha256/fb5e7bc62fc3c8f2511e3b64d795296444129b26f13d8dece4d4cee1845b758f/bin/bazel, --rc_source=client, --default_override=0:common=--isatty=1, --default_override=0:common=--terminal_columns=156, --rc_source=/Users/user_name/trash/examples/frontend/.bazelrc, --rc_source=/Users/user_name/.bazelrc, --default_override=1:common=--@aspect_rules_ts//ts:skipLibCheck=always]
240515 12:10:24.097:I 8721 [com.google.devtools.build.lib.server.GrpcServerImpl.executeCommand] [cquery, --startup_time=21, --command_wait_time=0, --extract_data_time=0, --binary_path=/Users/user_name/Library/Caches/bazelisk/downloads/sha256/fb5e7bc62fc3c8f2511e3b64d795296444129b26f13d8dece4d4cee1845b758f/bin/bazel, --rc_source=client, --default_override=0:common=--isatty=1, --default_override=0:common=--terminal_columns=156, --rc_source=/Users/user_name/trash/examples/frontend/.bazelrc, --rc_source=/Users/user_name/.bazelrc, --default_override=1:common=--@aspect_rules_ts//ts:skipLibCheck=always, //next.js:next]
240515 12:10:24.223:I 8721 [com.google.devtools.build.lib.server.GrpcServerImpl.executeCommand] [build, --startup_time=21, --command_wait_time=0, --extract_data_time=0, --binary_path=/Users/user_name/Library/Caches/bazelisk/downloads/sha256/fb5e7bc62fc3c8f2511e3b64d795296444129b26f13d8dece4d4cee1845b758f/bin/bazel, --rc_source=client, --default_override=0:common=--isatty=1, --default_override=0:common=--terminal_columns=156, --rc_source=/Users/user_name/trash/examples/frontend/.bazelrc, --rc_source=/Users/user_name/.bazelrc, --default_override=1:common=--@aspect_rules_ts//ts:skipLibCheck=always, //next.js:next]

@github-actions github-actions bot added the team-Core Skyframe, bazel query, BEP, options parsing, bazelrc label May 14, 2024
@tpasternak
Copy link

I'm not sure if this is related, but I also noticed that commands such as bazel info or bazel mod cause invalidaiton of large portions of skyframe. It can be easily verified with bazel build && bazel dump --skyframe=summary && bazel info && bazel dump --skyframe=summary

@SinimaWath
Copy link
Author

@tpasternak You are right.

Checked and even just bazel info invalidate part of cache, thanks!

@fmeum
Copy link
Collaborator

fmeum commented May 14, 2024

@tpasternak Are you using --disk_cache or --remote_cache when you reproduce this?

I'm seeing some weird Skyframe invalidation when using these flags, but not without them.

Changed keys without new values: [ActionLookupData0{actionLookupKey=ConfiguredTargetKey{label=@@rules_java~//toolchains:platformclasspath, config=BuildConfigurationKey[b85621dae172f731976165fe86631f99030f401e70ed2b02d58c69595e5ea36d]}, actionIndex=0}]

@fmeum
Copy link
Collaborator

fmeum commented May 14, 2024

Possibly related: #22367

@tpasternak Could you build Bazel with the patch I added to that issue and rerun on your reproducer?

@tjgq
Copy link
Contributor

tjgq commented May 14, 2024

Does this repro with --noexperimental_merged_skyframe_analysis_execution? I'm wondering if it's the limitation described in this commit description (and afaik not yet lifted since then): d94816a (although I would concur that bazel info at least ought not to invalidate anything).

@tpasternak
Copy link

@fmeum with your help I figured out what's wrong - I was using --override_repository when running build, but not when running bazel info. When I tried bazel info --override_repository it didn't trigger skyframe eviction

@tpasternak
Copy link

Probably my comments are unrelated to the original issue, sorry for messing

@SinimaWath
Copy link
Author

Does this repro with --noexperimental_merged_skyframe_analysis_execution? I'm wondering if it's the limitation described in this commit description (and afaik not yet lifted since then): d94816a (although I would concur that bazel info at least ought not to invalidate anything).

@tjgq

Repro without --noexperimental_merged_skyframe_analysis_execution

@SinimaWath
Copy link
Author

SinimaWath commented Oct 2, 2024

Can we up this? The bug is still reproduced.

@reimai
Copy link

reimai commented Oct 3, 2024

Might not be realated (it's rather a problem with my settings), but I had an issue with an invalidated action cache. It would drop between runs of bazel info and bazel query. I debugged this a bit, and the problem turned out to be incompatible_unambiguous_label_stringification flag set to false for build commands in .bazelrc:

build --incompatible_unambiguous_label_stringification=false

It affects semantics of bazel build and bazel info:

StarlarkSemantics{enable_bzlmod=false, incompatible_java_common_parameters=false, incompatible_unambiguous_label_stringification=false}

but not bazel query:

StarlarkSemantics{enable_bzlmod=false, incompatible_java_common_parameters=false}

Setting it to common helped to avoid cache eviction, the problem script saved about 30sec on that:

common --incompatible_unambiguous_label_stringification=false

So it might be feasible to look for flags distinct between commands.

@SinimaWath
Copy link
Author

@reimai

So it might be feasible to look for flags distinct between commands.

Reproducing even without flags (

@SinimaWath
Copy link
Author

Found out, that running bazel info output_base doesn't evict cache.

bazel info output_base && bazel cquery //next.js:next && bazel build //next.js:next works as expected, but running bazel info evict part of cache

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-Core Skyframe, bazel query, BEP, options parsing, bazelrc type: bug untriaged
Projects
None yet
Development

No branches or pull requests

8 participants