-
Notifications
You must be signed in to change notification settings - Fork 898
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
Add optional force
argument to refresh_continuous_aggregate
#7521
Conversation
af8c263
to
bde8617
Compare
I think we discussed this previously, and one idea was to invalidate the region covered by the tiered data when the GUC to enable tiered refreshing was changed to "true/on". This would not require changes to our API and is the natural way to make the region refresh with current mechanisms. Was that approach discarded for some reason? If so, can someone explain what disqualified it? |
I probably didn't catch that. Do you mean that in the GUC callback we set some sort of a flag that would indicate that we should insert an invalidation record whenever we refresh a range? I see a couple of issues:
In both cases it feels like not a clear UX. |
The problem with this approach is the case when the tiered data is already materialized that will generate unnecessary invalidation logs. |
I meant adding the invalidations in the GUC, not setting a flag. Nothing else needs to change.
Not sure I follow why they'd have to turn off and on again. I believe guc callbacks are called on parsing the server config file as well.
I don't think this would be necessary if the invalidations are added via the guc callback.
The idea is that this would be completely transparent and no need for user to learn about a With the other approach, the user first has to enable the GUC for tiered caggs to work, then use the |
That's just one large invalidation entry per affected cagg. It should not be an issue right? Also, can't we detect whether it is up-to-date or not and avoid adding the invalidation? If we can't detect it, it would be "correct" to add the invalidation AFAICT. |
It is a problem (actually this is exact the problem I want to avoid) because the current architecture don't deal with large ranges very well and doing that will make things worse for the customer.
We can check if exists some tiered data already materialized but it don't guarantee that everything is actually materialized and this is the reason to have this |
Ok, sounds like a bigger problem then. It is just that my alarm bells start to ring when I see that we are trying to build around the current architecture. I'd prefer we fix the underlying problem, but maybe this is not possible in the short term.
But it will only work for one cagg, so you'd have to manually force refresh all caggs that are connected to a tiered hypertable. If you forget one or more, you are now actually in a bad state where some caggs aren't accurately representing the data even if you refresh normally. In contrast, adding the invalidation will add the proper state to remember that this region is no longer valid and needs a refresh. This is what invalidations are for. But now we are saying we cannot use invalidations because they don't work well. So, now we use them sometimes, but in other times we don't. To me that sounds like a system where you cannot fully trust that a refresh is actually a refresh, which might lead to users always forcing a refresh just to be sure. Anyway, I am just pointing these things out to make sure we thought this through, but if you are convinced that relying on the user forcing a refresh is the best option right now, then I trust you that there is no better option. |
Unfortunately no... the short term solution we're working on is build some custom jobs to execute the refresh in small ranges instead of a big one and this new option will be used by OSM team when they have this situation when the tiered reads are disabled then they enable it and want to materialize the data.
Your points are valid and many thanks to jump into the discussion, but this option is not for wide audience but instead to ourselves use it in some custom jobs to execute the refresh in an incremental fashion. We don't want to rely on users to make sure that their data is in the correct state. Anyway all of this is for short term solution but starting on Q1 2025 Mats and I will start to work on a new architecture for refreshing caggs to address all this write amplification we have nowadays, but it is not a small project. |
bde8617
to
40f1986
Compare
40f1986
to
d932511
Compare
@akuzm, @fabriziomello: please review this pull request.
|
d932511
to
742ec32
Compare
DELETE FROM :mat_ht; | ||
|
||
-- Run regular refresh, it should not touch previously materialized range | ||
-- CALL refresh_continuous_aggregate('daily_temp', '2020-05-04 00:00 UTC', '2020-05-05 00:00 UTC'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leftover?
7b1f47a
to
70e7628
Compare
70e7628
to
e977ffe
Compare
e977ffe
to
23f851d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few nits and some minor comments.
Although I agree that the "correct" solution is to ensure that the invalidation tables are correct rather than force the refresh, I think this option is a useful workaround for those cases where things break.
Although the commit comment is correct and gives a rationale behind why it exists, this is more useful in a design document. I would argue that the commit comment should just contain what the change does and how it works, not why it is implemented.
I also miss a test using an empty table: if you force-refresh an empty range, you could potentially end up with a situation where you try to use a min and max that does not exist, so it's prudent to have a test for that.
@@ -140,7 +140,8 @@ static Invalidation cut_cagg_invalidation_and_compute_remainder( | |||
const CaggInvalidationState *state, const InternalTimeRange *refresh_window, | |||
const Invalidation *mergedentry, const Invalidation *current_remainder); | |||
static void clear_cagg_invalidations_for_refresh(const CaggInvalidationState *state, | |||
const InternalTimeRange *refresh_window); | |||
const InternalTimeRange *refresh_window, | |||
const bool force); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: The previous ones are "pointers to constant data", but this one is a "constant boolean" which is not part of the function signature, so better skip it. There are some compilers that make a big deal out of it.
const bool force); | |
bool force); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree, I removed const
s
@@ -878,7 +879,7 @@ cut_cagg_invalidation_and_compute_remainder(const CaggInvalidationState *state, | |||
*/ | |||
static void | |||
clear_cagg_invalidations_for_refresh(const CaggInvalidationState *state, | |||
const InternalTimeRange *refresh_window) | |||
const InternalTimeRange *refresh_window, const bool force) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const InternalTimeRange *refresh_window, const bool force) | |
const InternalTimeRange *refresh_window, bool force) |
tsl/test/expected/cagg_refresh.out
Outdated
-- because it would skip previously materialized ranges, but it should be | ||
-- possible with `force=>true` parameter. To simulate this use-case we clear | ||
-- the materialization hypertable and forefully re-materialize it. | ||
SELECT ht.schema_name || '.' || ht.table_name AS mat_ht, mat_hypertable_id FROM _timescaledb_catalog.continuous_agg cagg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: If the schema name or table name is "strange", this code might generate something that does not parse as a table. Compare these:
mats=# select format('%I.%I', nspname, relname), nspname || '.' || relname from pg_class cls join pg_namespace nsp on relnamespace = nsp.oid where nspname = 'public';
format | ?column?
---------------------------------------+---------------------------------------
public."fnupp'" | public.fnupp'
public.foo | public.foo
public.conditions | public.conditions
public.conditions_time_idx | public.conditions_time_idx
public.events_event_id_seq | public.events_event_id_seq
public.events_updated_at_event_id_idx | public.events_updated_at_event_id_idx
public.events | public.events
public.unique_key3 | public.unique_key3
public.testtable3_time_idx3 | public.testtable3_time_idx3
public.testtable3 | public.testtable3
public.metric | public.metric
(11 rows)
SELECT ht.schema_name || '.' || ht.table_name AS mat_ht, mat_hypertable_id FROM _timescaledb_catalog.continuous_agg cagg | |
SELECT format('%I.%I', ht.schema_name, ht.table_name) AS mat_ht, mat_hypertable_id FROM _timescaledb_catalog.continuous_agg cagg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the test according to your suggestion, though in this particular case this should not be a problem because it is a standard auto-generated name like _timescaledb_internal._materialized_hypertable_xxx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, it works now and is not dependent on user data, hence a nit.
23f851d
to
b784c84
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #7521 +/- ##
==========================================
+ Coverage 80.06% 82.25% +2.18%
==========================================
Files 190 238 +48
Lines 37181 43798 +6617
Branches 9450 10997 +1547
==========================================
+ Hits 29770 36024 +6254
- Misses 2997 3428 +431
+ Partials 4414 4346 -68 ☔ View full report in Codecov by Sentry. |
b784c84
to
b9ab8e5
Compare
Add optional `force` parameter to the `refresh_continuous_aggregate` procedure that would allow user to partially re-materialize cagg within a time window that has been previously materialized.
b9ab8e5
to
9c9f04f
Compare
This release contains performance improvements and bug fixes since the 2.17.2 release. We recommend that you upgrade at the next available opportunity. **Features** * timescale#6901: Add hypertable support for transition tables. * timescale#7104: Hypercore table access method. * timescale#7271: Push down `order by` in real-time continuous aggregate queries. * timescale#7295: Support `alter table set access method` on hypertable. * timescale#7341: Vectorized aggregation with grouping by one fixed-size by-value compressed column * timescale#7390: Disable custom `hashagg` planner code. * timescale#7411: Change parameter name to enable hypercore table access method. * timescale#7412: Add GUC for `hypercore_use_access_method` default. * timescale#7413: Add GUC for segmentwise recompression. * timescale#7433 Add support for merging chunks * timescale#7436 Add index creation on orderby columns * timescale#7443: Add hypercore function and view aliases. * timescale#7455: Support `drop not null` on compressed hypertables. * timescale#7458: Support vecorized aggregation with aggregate `filter` clauses that are also vectorizable. * timescale#7482: Optimize recompression of partially compressed chunks. * timescale#7486: Prevent building against postgres versions with broken ABI. * timescale#7521 Add optional `force` argument to `refresh_continuous_aggregate` * timescale#7528 Transform sorting on `time_bucket` to sorting on time for compressed chunks in some cases. * timescale#7565 Add hint when hypertable creation fails * timescale#7587 Add `include_tiered_data` parameter to `add_continuous_aggregate_policy` API **Bugfixes** * timescale#7378: Remove obsolete job referencing `policy_job_error_retention`. * timescale#7409: Update `bgw_job` table when altering procedure. * timescale#7410: Fix the `aggregated compressed column not found` error on aggregation query. * timescale#7426: Fix `datetime` parsing error in chunk constraint creation. * timescale#7432: Verify that the heap tuple is valid before using. * timescale#7434: Fixes the segfault when internally setting the replica identity for a given chunk. * timescale#7488: Emit error for transition table trigger on chunks. * timescale#7514: Fix the error: `invalid child of chunk append`. * timescale#7517 Fixes performance regression on `cagg_migrate` procedure * timescale#7527 Restart scheduler on error * timescale#7557: Fix null handling for in-memory tuple filtering. * timescale#7566 Improve transaction check in CAgg refresh * timescale#7584 Fix NaN-handling for vectorized aggregation **Thanks** * @bharrisau for reporting the segfault when creating chunks. * @k-rus for suggesting the improvement * @pgloader for reporting the issue in an internal background job. * @staticlibs for sending PR to improve transaction check in CAgg refresh * @uasiddiqi for reporting the `aggregated compressed column not found` error.
This release contains performance improvements and bug fixes since the 2.17.2 release. We recommend that you upgrade at the next available opportunity. **Features** * timescale#6901: Add hypertable support for transition tables. * timescale#7104: Hypercore table access method. * timescale#7271: Push down `order by` in real-time continuous aggregate queries. * timescale#7295: Support `alter table set access method` on hypertable. * timescale#7341: Vectorized aggregation with grouping by one fixed-size by-value compressed column * timescale#7390: Disable custom `hashagg` planner code. * timescale#7411: Change parameter name to enable hypercore table access method. * timescale#7412: Add GUC for `hypercore_use_access_method` default. * timescale#7413: Add GUC for segmentwise recompression. * timescale#7433 Add support for merging chunks * timescale#7436 Add index creation on orderby columns * timescale#7443: Add hypercore function and view aliases. * timescale#7455: Support `drop not null` on compressed hypertables. * timescale#7458: Support vecorized aggregation with aggregate `filter` clauses that are also vectorizable. * timescale#7482: Optimize recompression of partially compressed chunks. * timescale#7486: Prevent building against postgres versions with broken ABI. * timescale#7521 Add optional `force` argument to `refresh_continuous_aggregate` * timescale#7528 Transform sorting on `time_bucket` to sorting on time for compressed chunks in some cases. * timescale#7565 Add hint when hypertable creation fails * timescale#7587 Add `include_tiered_data` parameter to `add_continuous_aggregate_policy` API **Bugfixes** * timescale#7378: Remove obsolete job referencing `policy_job_error_retention`. * timescale#7409: Update `bgw_job` table when altering procedure. * timescale#7410: Fix the `aggregated compressed column not found` error on aggregation query. * timescale#7426: Fix `datetime` parsing error in chunk constraint creation. * timescale#7432: Verify that the heap tuple is valid before using. * timescale#7434: Fixes the segfault when internally setting the replica identity for a given chunk. * timescale#7488: Emit error for transition table trigger on chunks. * timescale#7514: Fix the error: `invalid child of chunk append`. * timescale#7517 Fixes performance regression on `cagg_migrate` procedure * timescale#7527 Restart scheduler on error * timescale#7557: Fix null handling for in-memory tuple filtering. * timescale#7566 Improve transaction check in CAgg refresh * timescale#7584 Fix NaN-handling for vectorized aggregation **Thanks** * @bharrisau for reporting the segfault when creating chunks. * @k-rus for suggesting the improvement * @pgloader for reporting the issue in an internal background job. * @staticlibs for sending PR to improve transaction check in CAgg refresh * @uasiddiqi for reporting the `aggregated compressed column not found` error.
Following the SDC. Continuous aggregates that are built on top of tiered hypertables cannot access and materialize tiered data when the
timescaledb.enable_tiered_reads
GUC is disabled at the server level. And there is no way for a user to manually force the refresh with tiered reads enabled. Here we add an optionalforce
parameter to therefresh_continuous_aggregate
procedure that would allow user to partially re-materialize cagg within a time window that has already been materialized.