Skip to content

compute: introduce a CollectionState#20090

Merged
teskje merged 3 commits into
MaterializeInc:mainfrom
teskje:compute-collection-state
Jul 21, 2023
Merged

compute: introduce a CollectionState#20090
teskje merged 3 commits into
MaterializeInc:mainfrom
teskje:compute-collection-state

Conversation

@teskje

@teskje teskje commented Jun 22, 2023

Copy link
Copy Markdown
Contributor

Prior to this PR, the per-collection state tracked by compute was spread over several BTreeMaps in ComputeState:
* sink_tokens
* sink_write_frontiers
* flow_control_probes
* reported_frontiers

This made it hard to keep track of the collection state as a whole and invited bugs caused by inconsistencies (e.g. we might forget to drop all of the state for a collection).

This PR refactors the ComputeState by replacing the four per-collection fields mentioned above with a single collections map. Values in this map are CollectionState objects that each contain the entire state specific to a single collection. An exception is trace state, which is kept in the TraceManager and pulling that apart seemed too much of a hassle.

Motivation

  • This PR refactors existing code.

As part of implementing the proposed mz_dataflow_initial_output_duration_seconds compute metric (draft PR: #20126), I noticed that with the current code that would mean adding two new per-collection ComputeState fields, one for keeping the the delete-on-drop collection metrics and one for remembering the time at which the collection was installed. I figured it was worth to invest some time to clean up our collection tracking.

Tips for reviewer

This PR includes a minor cleanup commit that I already added in #18442. It would be nice if we could finally land that too.

Most of the changes are pretty mechanical, replacing a direct field access on ComputeState with an access to collections and then one of its fields. A notable exception if report_compute_frontiers where I replaced the previous logic of iterating over trace frontiers then sink frontiers by a single iteration over all collections. I then inlined the frontier update closure which was only needed to deduplicate code. I suggest you look at both implementations side-by-side to convince yourself that they do the same thing, rather than trying to decipher the diff.

Checklist

  • This PR has adequate test coverage / QA involvement has been duly considered.
  • This PR has an associated up-to-date design doc, is a design doc (template), or is sufficiently small to not require a design.
  • If this PR evolves an existing $T ⇔ Proto$T mapping (possibly in a backwards-incompatible way), then it is tagged with a T-proto label.
  • If this PR will require changes to cloud orchestration, there is a companion cloud PR to account for those changes that is tagged with the release-blocker label (example).
  • This PR includes the following user-facing behavior changes:
    • N/A

@vmarcos vmarcos left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is pushing the code in a healthy direction, so thanks for investing the time here! The first commit is pretty uncontroversial IMO, and I had a couple of smaller comments on the second.

Comment thread src/compute/src/compute_state.rs Outdated
Comment thread src/compute/src/compute_state.rs
@teskje teskje force-pushed the compute-collection-state branch 2 times, most recently from 6b5645e to 63604ee Compare July 20, 2023 13:13
@teskje teskje marked this pull request as ready for review July 20, 2023 13:42
@teskje teskje requested review from a team and vmarcos July 20, 2023 13:42
@teskje

teskje commented Jul 20, 2023

Copy link
Copy Markdown
Contributor Author

Alright, this is RFAL! The changes I made since you commented, @vmarcos:

  • Made CI pass by changing two returns into continues in report_compute_frontiers. You wouldn't believe how long it took me to find this bug...
  • Moved the dropped_collections field closer to collections.
  • Added a second commit improving the docs regarding collection frontiers.

This commit just moves some code around, to slightly improve
readability.

* Add a `ComputeState` constructor method. This allows us to make two
  of the `ComputeState` fields immediately private and we will likely be
  able to tighten the interface further in the future.
* Factor out collection dropping code from `handle_allow_compaction`
  into a `drop_collection` method.
@teskje teskje force-pushed the compute-collection-state branch from 74101ac to bcaf8a1 Compare July 20, 2023 13:52

@antiguru antiguru left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a sane thing to do! Thank you

Comment thread src/compute/src/compute_state.rs Outdated
Comment thread src/compute/src/compute_state.rs
teskje added 2 commits July 21, 2023 09:57
Prior to this commit, the per-collection state tracked by compute was
spread over several `BTreeMap`s in `ComputeState`:
 * `sink_tokens`
 * `sink_write_frontiers`
 * `flow_control_probes`
 * `reported_frontiers`

This makes it hard to keep track of the collection state as a whole and
invites bugs caused by inconsistencies (e.g. we might forget to drop all
of the state for a collection).

This commit refactors the `ComputeState` by replacing the four
per-collection fields mentioned above with a single `collections` map.
Values in this map are `CollectionState` objects that each contain the
entire state specific to a single collection. An exception is trace
state, which is kept in the `TraceManager` and pulling that apart seemed
too much of a hassle.
@teskje teskje force-pushed the compute-collection-state branch from bcaf8a1 to bae5597 Compare July 21, 2023 07:57

@vmarcos vmarcos left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@teskje teskje merged commit 134799f into MaterializeInc:main Jul 21, 2023
@teskje

teskje commented Jul 21, 2023

Copy link
Copy Markdown
Contributor Author

TFTRs!

@teskje teskje deleted the compute-collection-state branch July 21, 2023 09:25
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.

3 participants