Commit Graph

39 Commits

Author SHA1 Message Date
Jonathan A. Sternberg
37b6f87915 solver: simplify edge-related functions in the solver
Many of the functions in the solver that operated on the edges were very
large which obscured their usage and the overall flow of the scheduler.
This change refactors those functions into separate smaller functions to
make it easier to follow the overall flow of the scheduler.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2024-10-07 12:58:09 -05:00
Jonathan A. Sternberg
2f18b835ce solver: move scheduler debug statements to their own functions
Move scheduler debug statements to their own functions and in their own
file so that scheduler debug statements don't make the scheduler logic
more complex to follow. Some of the scheduler logs can be quite long and
can make it difficult to follow the code logic. This changes these log
statements to `debugSchedulerXXX` where `XXX` is the message that would
be printed.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2024-09-18 15:49:34 -05:00
Jonathan A. Sternberg
ad64996f49 solver: pipe implementation utilizes generics for better typing
This updates the pipe library to use generics for the request payload
and the status value. This allows the solver to put in explicit types
rather than rely on type casting from interfaces which helps with type
safety and understandability.

The status value used by the solver uses the `any` type instead of an
explicit type because the `unpark` method takes a generic list of pipes
and the different pipes have different result types. We can likely
change this in the future or create a discriminated union for the
types that can be used in this package. That is left for future work
because at least the request payload is typed now.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2024-09-12 10:37:12 -05:00
Erik Sipsma
b2925c2e05 solver: add more debug logs to track down inconsistent graph state
Signed-off-by: Erik Sipsma <erik@sipsma.dev>
2024-04-03 06:12:33 -07:00
Tonis Tiigi
7b462d437f solver: allow debugging specific builder steps
This adds new environment variables for allowing
debugging scheduler for only specific steps. This
is useful because the scheduler debugging is quite
verbose so if you run it on production builds it can
generate lots of data that is hard to analyze. Old
behavior is unchanged.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2023-11-09 00:20:54 -08:00
Tõnis Tiigi
20847b7c83 Merge pull request #4285 from tonistiigi/double-merge-edge-fix
solver: fix issue with double merged edges
2023-10-23 15:02:00 -07:00
Jonathan A. Sternberg
015db441f8 solver: minor typo in one of the logging messages
Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2023-10-18 09:24:01 -05:00
Tonis Tiigi
100d3cb6b6 solver: fix issue with double merged edges
"Merged edges" is an optimization in the solve graph where two different active LLB edges can be combined into one after cache key computation finds that they generated equivalent cache chain.

In that case, one edge is released and is set to point to another. The reference count for the second one is increased.

An issue was discovered where an edge that was already pointing to another edge became a target to the third one. The current implementation did not handle the case where an edge that already had a different target itself became a target edge as well. This resulted in an inconsistent graph state where edges that were thought to be released could get scheduled again.

Instead of setting the same edge value to two different maps, the new logic is to chain the edges into a linked list that should handle multiple levels of targets. This slightly increases the number of lookups, but "merged edges" case is very rare anyway, and a couple of extra pointer dereferences do not affect build speed.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2023-09-27 17:35:23 -07:00
Kohei Tokunaga
085bd8af7f Fix cache cannot reuse lazy layers
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
2023-01-24 16:23:56 +09:00
Tonis Tiigi
a20e48f36d provenance: add layers support
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2022-11-15 19:37:03 -08:00
CrazyMax
4a15e742d8 update golangci-lint to 1.48.0 (go 1.19 support) and fix linting issues
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2022-08-19 10:26:52 +02:00
Tonis Tiigi
dc21885891 hack: enable more linters
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2022-01-19 12:20:30 -08:00
Edgar Lee
465a30a31d Remove goto statements causing failed edges to never unpark
Signed-off-by: Edgar Lee <edgarhinshunlee@gmail.com>
2022-01-12 15:59:20 -08:00
Maxime Lagresle
e76cfcfa22 don't cast Value when pipe is errored
Signed-off-by: Maxime Lagresle <maxime@angel.co>
2021-10-02 11:08:27 +02:00
Morlay
18b49fd7dc refactor to use util/bklog instead of using logurs directly
Signed-off-by: Morlay <morlay.null@gmail.com>
2021-07-13 11:42:31 +08:00
Tonis Tiigi
bee77d81b9 solver: check for edge dependency before merging
In some cases edges that depend on each other
can have identical cache keys. This happens for
example when empty layers are optimized out by
the differ between identical commands. We need to
detect this case and avoid merge.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2021-03-18 19:55:35 -07:00
Tonis Tiigi
2f247f0340 solver: fix slow-cache status tracking with preprocess
Preprocess should not be taken into account when calculating
cache-slow state. But it should be used to detect if dep is complete
so preprocess runs before parent's exec function.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2020-12-10 22:57:30 -08:00
Tonis Tiigi
706129170d solver: remove scheduler fix
Asked in review.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2020-12-02 16:07:13 -08:00
Tonis Tiigi
6a321dc574 solver: improve slow cache detection and add logging
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2020-12-01 22:38:15 -08:00
Tonis Tiigi
e86356ddf8 solver: add input preprocess capability
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2020-11-03 14:49:44 -08:00
Erik Sipsma
55cbd19dec Add support for lazily-pulled blobs in cache manager.
This allows the layers of images to only be pulled if/once they are actually
required.

Signed-off-by: Erik Sipsma <erik@sipsma.dev>
2020-08-05 17:18:43 -07:00
Tonis Tiigi
c8190b1518 lint: enable golint
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2020-07-19 09:28:24 -07:00
Tonis Tiigi
57a88b0afb lint: add misspell and unused
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2020-07-18 08:13:57 -07:00
Tonis Tiigi
dd765674fb solver: gracefully handle cache loading errors
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2020-05-18 18:21:34 -07:00
Tonis Tiigi
eede0facb7 solver: fix pipe signaling on incoming updates
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2019-09-10 16:59:56 -07:00
Tonis Tiigi
e2dcafa5ca Removing wrapf for review
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2019-06-07 12:04:47 -07:00
Tonis Tiigi
61f1bc138b solver: add error tracing to edge connections
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2019-06-06 21:15:21 -07:00
Tonis Tiigi
fbb71123a7 solver: optimize early input resolve
Detect the cases where open input keys are not possible even
when computed keys are calculated to skip to cache lookup early.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2019-03-13 15:34:18 -07:00
Tonis Tiigi
b988403262 solver: fix early input resolve
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2019-03-12 17:49:54 -07:00
Tonis Tiigi
ac4037a1d9 solver: keep original cache creation date when copying between stores
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2019-01-18 11:19:34 -08:00
Tonis Tiigi
a711fbb8f3 solver: fix early resolution of cache-fast deps
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2018-09-26 18:25:33 -07:00
Tibor Vass
9d1b0e6b31 Merge pull request #597 from tonistiigi/graceful-scheduler-errors
solver: gracefully handle scheduler bugs
2018-08-30 10:56:39 -07:00
Tonis Tiigi
0d68543b1e solver: mark build failed instead of panicking on scheduler error
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2018-08-29 11:10:05 -07:00
Tonis Tiigi
c77b6d4759 solver: gracefully handle bugs leaving incoming requests open
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2018-08-28 17:07:50 -07:00
Tonis Tiigi
ee82ffe538 solver: correct dep key conditions
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2018-08-27 16:18:23 -07:00
Akihiro Suda
89eee2126e Merge pull request #535 from tonistiigi/merge-fix
solver: fix edge merge skipping issue
2018-07-24 11:25:09 +09:00
Tonis Tiigi
97ea41ee6a solver: improve multi-key root caching
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2018-07-23 14:27:35 -07:00
Tonis Tiigi
c575077cd6 solver: fix edge merge skipping issue
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2018-07-23 10:52:31 -07:00
Tonis Tiigi
71f5e6dd21 solver: rename solver-next to solver
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2018-05-14 09:53:34 -07:00