zuul/zuul
James E. Blair 7741fc923c Refactor branch cache to support more queries
The current branch cache is hyper-optimized to support exactly two
types of branch queries: all branches for a project, or unprotected
branches for a project.  GitHub provides another axis: "locked"
branches.  Cconceivably, other code review systems could as well, and
there may be even more axes in the future.

In order to support locked branches in a future change, we must first
refactor the branch cache to support more than two queries.  This
change implements that with the following scheme:

The branch cache will be a dictionary of project_name -> ProjectInfo,
and ProjectInfo will hold general information about the project such
as supported merge modes and default branch, as well as another
dictionary branch_name -> BranchInfo.  The BranchInfo record will hold
boolean flags indicating whether the branch is protected or locked.

Additionally, the project_info record will hold a set of which queries
for these flags have been performed and whether they were successful
or not.  This allows us to determine whether the branch_info flags
are valid or not.  For example, if we have only performed a query to
get all the branches, and a caller requests a list of protected
branches, we know that the BranchInfo.protected bool is not valid,
so we return a LookupEerror to the caller which will trigger another
query to get the protected branch list which will then be used to
update the branch cache, setting the protected bool to true where
appropriate on existing BranchInfo objects and setting the protected
query flag on ProjectInfo.  The result matches the current behavior,
but is extensible to support more flags.

In order to minimize the size of the branch cache in ZooKeeper, the
BranchInfo object is serialized as a simple integer with a bitmap of
the associated booleans.  Likewise, the several queries are stored in
the serialized ProjectInfo as two bitmaps (one for success, and one
for failed).

This change stubs out the "locked" flag and query in some places, just
to demonstrate sufficiency for future use, but it does not implement
support for locked branches yet.  A future change will do that.
As long as we don't actually add any locked branches, we can still
serialize to the old branch cache data structure, so this change does
so to enable rolling upgrades.  Tests of the upgrade path and
continued operation on only the old data path are included.

Change-Id: I8841e675295f15e5d6dd004f9e34836b8bbbdb63
2024-04-11 18:12:58 -07:00
..
ansible Merge "Enable TCP keepalives in zuul_stream" 2024-02-27 18:14:12 +00:00
cmd Merge "Fix validate-tenants isolation" 2024-02-28 02:46:55 +00:00
connection Refactor branch cache to support more queries 2024-04-11 18:12:58 -07:00
driver Refactor branch cache to support more queries 2024-04-11 18:12:58 -07:00
execution_context List process ids in bwrap namespace 2023-06-28 13:31:06 -07:00
executor Merge "Add zuul_unreachable ansible host group" 2024-03-25 18:26:14 +00:00
lib Make ansible package check more robust 2024-03-25 11:25:35 -07:00
manager Merge "Emit per-branch queue stats separately" 2024-03-25 19:22:37 +00:00
merger Handle annotated and signed tags when packing refs 2024-04-05 13:12:59 -07:00
reporter Finish circular dependency refactor 2024-02-09 07:39:40 -08:00
source Fix bug with cached merge modes in TPC 2023-11-16 09:37:08 +01:00
sphinx docs: remove zuuldocs domain 2020-08-04 16:10:09 +10:00
trigger Refactor configuration error handling 2023-10-30 16:19:45 -07:00
vendor Add some pipeline processing stats 2022-01-25 08:16:52 -08:00
web Add script to generate openapi spec 2024-03-09 11:25:40 -08:00
zk Refactor branch cache to support more queries 2024-04-11 18:12:58 -07:00
__init__.py Initial commit. 2012-05-29 14:49:32 -07:00
_setup_hook.py Revert "Revert "Create zuul/web/static on demand"" 2020-07-07 19:53:33 +02:00
change_matcher.py Remove most model_api backwards-compat handling 2024-02-09 07:39:55 -08:00
configloader.py Use ProjectNotFoundError 2024-03-18 15:09:47 -07:00
exceptions.py Handle dependency limit errors more gracefully 2024-03-19 14:37:26 +01:00
model.py Merge "Add a zuul.buildset_refs variable" 2024-03-25 10:09:16 +00:00
model_api.py Refactor branch cache to support more queries 2024-04-11 18:12:58 -07:00
nodepool.py Add job name back to node request data 2024-03-07 08:02:30 +01:00
scheduler.py Use NodesetNotFoundError class 2024-03-18 15:03:58 -07:00
version.py Convert pkg_resources usage to importlib 2024-03-20 09:17:19 -07:00