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

Refactor continuous aggregate materialization code #7505

Merged

Conversation

fabriziomello
Copy link
Contributor

@fabriziomello fabriziomello commented Nov 30, 2024

Refactor continuous aggregate materialization code

In addition to the code reorganization and simplification we changed it by splitting the query execution in multiple steps taking advantage of SPI_prepare, SPI_execute_plan and SPI_freeplan:

  • create_materialization_plan(PlanType)
  • execute_materialization_plan(PlanType)
  • free_materialization_plan(PlanType)

This PR is in preparation for a following PR to execute the materialization in small batches to alleviate the I/O spikes when reading and writing many buckets.

Disable-check: force-changelog-file

@fabriziomello fabriziomello added continuous_aggregate tech-debt Needs refactoring and improvement tasks related to the source code and its architecture. labels Nov 30, 2024
@fabriziomello fabriziomello self-assigned this Nov 30, 2024
Copy link

codecov bot commented Nov 30, 2024

Codecov Report

Attention: Patch coverage is 83.56164% with 24 lines in your changes missing coverage. Please review.

Project coverage is 82.19%. Comparing base (59f50f2) to head (050c9e4).
Report is 649 commits behind head on main.

Files with missing lines Patch % Lines
tsl/src/continuous_aggs/materialize.c 83.56% 16 Missing and 8 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7505      +/-   ##
==========================================
+ Coverage   80.06%   82.19%   +2.12%     
==========================================
  Files         190      230      +40     
  Lines       37181    43250    +6069     
  Branches     9450    10875    +1425     
==========================================
+ Hits        29770    35548    +5778     
- Misses       2997     3385     +388     
+ Partials     4414     4317      -97     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@fabriziomello fabriziomello force-pushed the cagg_refactor_materialize branch 5 times, most recently from 6e70ed9 to 4c47fdb Compare December 3, 2024 00:41
@fabriziomello fabriziomello marked this pull request as ready for review December 3, 2024 00:51
@github-actions github-actions bot requested review from akuzm and gayyappan December 3, 2024 00:59
Copy link

github-actions bot commented Dec 3, 2024

@akuzm, @gayyappan: please review this pull request.

Powered by pull-review

@fabriziomello fabriziomello force-pushed the cagg_refactor_materialize branch 2 times, most recently from 64bc413 to 94cdd5b Compare December 3, 2024 19:06
@mkindahl mkindahl self-requested a review December 4, 2024 13:27
Copy link
Contributor

@mkindahl mkindahl left a comment

Choose a reason for hiding this comment

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

Would suggest that you modify the way plans are prepared as outlined below. Also one bug that will cause problems later (a missing "volatile"). Also a bunch of nits. but that is entirely your decision if you want to use them.

You might also switch to use function pointers and a dispatch table, which probably makes the code a little easier to maintain and also make it a little faster, but that is optional.

tsl/src/continuous_aggs/materialize.c Outdated Show resolved Hide resolved
tsl/src/continuous_aggs/materialize.c Outdated Show resolved Hide resolved
tsl/src/continuous_aggs/materialize.c Outdated Show resolved Hide resolved
tsl/src/continuous_aggs/materialize.c Outdated Show resolved Hide resolved
tsl/src/continuous_aggs/materialize.c Outdated Show resolved Hide resolved
tsl/src/continuous_aggs/materialize.c Outdated Show resolved Hide resolved
tsl/src/continuous_aggs/materialize.c Outdated Show resolved Hide resolved
tsl/src/continuous_aggs/materialize.c Outdated Show resolved Hide resolved
tsl/src/continuous_aggs/materialize.c Outdated Show resolved Hide resolved
tsl/src/continuous_aggs/materialize.c Outdated Show resolved Hide resolved
@fabriziomello fabriziomello force-pushed the cagg_refactor_materialize branch from 94cdd5b to 67a0e4c Compare December 10, 2024 15:59
Copy link
Contributor

@mkindahl mkindahl left a comment

Choose a reason for hiding this comment

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

A few comments, but nothing critical, so approving.

tsl/src/continuous_aggs/materialize.c Show resolved Hide resolved
tsl/src/continuous_aggs/materialize.c Outdated Show resolved Hide resolved
@fabriziomello fabriziomello force-pushed the cagg_refactor_materialize branch 2 times, most recently from da55567 to c0e6efc Compare December 11, 2024 00:30
tsl/src/continuous_aggs/materialize.c Outdated Show resolved Hide resolved
In addition to the code reorganization and simplification we changed
it by splitting the query execution in multiple steps taking advantage
of `SPI_prepare`, `SPI_execute_plan` and `SPI_freeplan`:
* create_materialization_plan(PlanType)
* execute_materialization_plan(PlanType)
* free_materialization_plan(PlanType)

This PR is in preparation for a following PR to execute the
materialization in small batches to alleviate the I/O spikes when
reading and writing many buckets.
@fabriziomello fabriziomello force-pushed the cagg_refactor_materialize branch from c0e6efc to 050c9e4 Compare December 11, 2024 12:55
@fabriziomello fabriziomello merged commit 63f7cc8 into timescale:main Dec 11, 2024
45 checks passed
fabriziomello added a commit to fabriziomello/timescaledb that referenced this pull request Dec 11, 2024
In timescale#7505 we used PG_TRY() .. PG_FINALLY() but some CI configurations was
not happy with it reporting "variable might be clobbered by longjmp".

Fixed it by using PG_TRY() .. PG_CATCH() instead.

https://github.com/timescale/timescaledb/actions/runs/12277548387/job/34257269473#step:13:206
akuzm pushed a commit that referenced this pull request Dec 12, 2024
In #7505 we used PG_TRY() .. PG_FINALLY() but some CI configurations was
not happy with it reporting "variable might be clobbered by longjmp".

Fixed it by using PG_TRY() .. PG_CATCH() instead.


https://github.com/timescale/timescaledb/actions/runs/12277548387/job/34257269473#step:13:206

Disable-check: force-changelog-file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
continuous_aggregate tech-debt Needs refactoring and improvement tasks related to the source code and its architecture.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants