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

compute_ctl: Break up main() #7577

Merged
merged 3 commits into from
May 7, 2024

Conversation

sharnoff
Copy link
Member

@sharnoff sharnoff commented May 1, 2024

Problem

compute_ctl's main() is "pretty gnarly". This makes changes to control flow quite difficult.

I hit this while working on #7434 and had an idea of how it could be improved, thus this PR.

Summary of changes

First commit: Small changes to reduce the diff of the second commit.

Second commit: Breaks up main() into a handful of component functions, aligned with distinct sections of the existing control flow. Each new function gets the previous one's return values as its arguments. The new functions destructure their args so the names are all the same.

Third commit: Move the tracing startup context guard out of where it was previously used, to make things more simple. Taken from #7600.

Checklist before requesting a review

  • I have performed a self-review of my code.
  • If it is a core feature, I have added thorough tests.
  • Do we need to implement analytics? if so did you add the relevant metrics to the dashboard?
  • If this PR requires public announcement, mark it with /release-notes label and add several sentences in this section.

Checklist before merging

  • Do not forget to reformat commit message to not include the above checklist

@sharnoff sharnoff requested a review from tristan957 May 1, 2024 19:15
@sharnoff sharnoff requested review from a team as code owners May 1, 2024 19:15
@sharnoff sharnoff requested a review from mtyazici May 1, 2024 19:15
Copy link

github-actions bot commented May 1, 2024

3072 tests run: 2939 passed, 0 failed, 133 skipped (full report)


Flaky tests (6)

Postgres 16

  • test_ancestor_detach_reparents_earlier[True]: release
  • test_vm_bit_clear_on_heap_lock: debug

Postgres 15

  • test_location_conf_churn[2]: debug
  • test_synthetic_size_while_deleting: debug
  • test_vm_bit_clear_on_heap_lock: debug

Postgres 14

  • test_detached_receives_flushes_while_being_detached[True]: debug

Code coverage* (full report)

  • functions: 31.2% (6258 of 20054 functions)
  • lines: 46.7% (46951 of 100591 lines)

* collected from Rust tests only


The comment gets automatically updated with the latest test results
7f45a29 at 2024-05-07T21:06:51.186Z :recycle:

compute_tools/src/bin/compute_ctl.rs Show resolved Hide resolved
compute_tools/src/bin/compute_ctl.rs Outdated Show resolved Hide resolved
compute_tools/src/bin/compute_ctl.rs Outdated Show resolved Hide resolved
compute_tools/src/bin/compute_ctl.rs Outdated Show resolved Hide resolved
@sharnoff sharnoff force-pushed the sharnoff/compute_ctl-main()-phase-refactor branch from ffe65ef to 10a0754 Compare May 4, 2024 01:26
hlinnaka added a commit that referenced this pull request May 4, 2024
- On a non-pooled start, do not reset the 'start_time' after launching
the HTTP service. In a non-pooled start, it's fair to include that in
the total startup time.

- When setting wait_for_spec_ms and resetting start_time, call
Utc::now() only once. It's a waste of cycles to call it twice, but also,
it ensures the time between setting wait_for_spec_ms and resetting
start_time is included in one or the other time period.

These differences should be insignificant in practice, in the
microsecond range, but IMHO it seems more logical and readable this way
too. Also fix and clarify some of the surrounding comments.

(This caught my eye while reviewing PR #7577)
@sharnoff sharnoff force-pushed the sharnoff/compute_ctl-main()-phase-refactor branch from 10a0754 to 855679e Compare May 4, 2024 16:22
@sharnoff sharnoff changed the title compute_ctl: Break up main() into discrete phases compute_ctl: Break up main() May 4, 2024
@sharnoff
Copy link
Member Author

sharnoff commented May 7, 2024

Planning to merge in 24h or so, if no objections (cc @tristan957).

sharnoff and others added 3 commits May 7, 2024 12:32
A couple lines moved further down in main(), and one case of using
Option<&str> instead of Option<&String>.
This commit is intentionally designed to have as small a diff as
possible. To that end, the basic idea is that each distinct "chunk" of
the previous main() has been wrapped in its own function, with the
return values from each function being passed directly into the next.

The structure of main() is now visible from its contents, which have a
handful of smaller functions.

There's a lot of other work that can / should(?) be done beyond this,
but I figure that's more opinionated, and this should be a solid start.

Co-authored-by: Heikki Linnakangas <heikki@neon.tech>
Part of applying the changes from #7600. This piece *technically* can
change the semantics because now the context guard is held before
process_cli, but... the difference is likely quite small.

Co-authored-by: Heikki Linnakangas <heikki@neon.tech>
@sharnoff sharnoff force-pushed the sharnoff/compute_ctl-main()-phase-refactor branch from 855679e to 7f45a29 Compare May 7, 2024 19:32
@sharnoff sharnoff enabled auto-merge (rebase) May 7, 2024 20:50
@sharnoff sharnoff merged commit 26b1483 into main May 7, 2024
53 checks passed
@sharnoff sharnoff deleted the sharnoff/compute_ctl-main()-phase-refactor branch May 7, 2024 20:58
sharnoff added a commit that referenced this pull request May 7, 2024
A couple lines moved further down in main(), and one case of using
Option<&str> instead of Option<&String>.
sharnoff added a commit that referenced this pull request May 7, 2024
This commit is intentionally designed to have as small a diff as
possible. To that end, the basic idea is that each distinct "chunk" of
the previous main() has been wrapped in its own function, with the
return values from each function being passed directly into the next.

The structure of main() is now visible from its contents, which have a
handful of smaller functions.

There's a lot of other work that can / should(?) be done beyond this,
but I figure that's more opinionated, and this should be a solid start.

Co-authored-by: Heikki Linnakangas <heikki@neon.tech>
sharnoff added a commit that referenced this pull request May 7, 2024
sharnoff added a commit that referenced this pull request May 7, 2024
conradludgate pushed a commit that referenced this pull request May 8, 2024
- On a non-pooled start, do not reset the 'start_time' after launching
the HTTP service. In a non-pooled start, it's fair to include that in
the total startup time.

- When setting wait_for_spec_ms and resetting start_time, call
Utc::now() only once. It's a waste of cycles to call it twice, but also,
it ensures the time between setting wait_for_spec_ms and resetting
start_time is included in one or the other time period.

These differences should be insignificant in practice, in the
microsecond range, but IMHO it seems more logical and readable this way
too. Also fix and clarify some of the surrounding comments.

(This caught my eye while reviewing PR #7577)
conradludgate pushed a commit that referenced this pull request May 8, 2024
A couple lines moved further down in main(), and one case of using
Option<&str> instead of Option<&String>.
conradludgate pushed a commit that referenced this pull request May 8, 2024
This commit is intentionally designed to have as small a diff as
possible. To that end, the basic idea is that each distinct "chunk" of
the previous main() has been wrapped in its own function, with the
return values from each function being passed directly into the next.

The structure of main() is now visible from its contents, which have a
handful of smaller functions.

There's a lot of other work that can / should(?) be done beyond this,
but I figure that's more opinionated, and this should be a solid start.

Co-authored-by: Heikki Linnakangas <heikki@neon.tech>
conradludgate pushed a commit that referenced this pull request May 8, 2024
Part of applying the changes from #7600. This piece *technically* can
change the semantics because now the context guard is held before
process_cli, but... the difference is likely quite small.

Co-authored-by: Heikki Linnakangas <heikki@neon.tech>
conradludgate pushed a commit that referenced this pull request May 8, 2024
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.

None yet

3 participants