Repository navigation
Fix cagg refresh skipping the last variable bucket - #10419
Conversation
|
@svenklemm, @pnthao: please review this pull request.
|
|
This PR has been closed due to a newly discovered issue. |
|
What was the newly discovered issue? |
|
Hi @JoongHyuk-Shin, we are looking at this bug now, and your fix looks like it's in the right direction. Would you like to reopen it? We'd be happy to review it and look into the "newly discovered issue" you mentioned. If you don't have the time now, please let us know so we can work on it and make sure we credit you. Thank you! |
e86be2b to
c6c0368
Compare
|
@Romeren @pnthao The newly discovered issue was in the +1: an invalidation ending exactly at the start of the last bucket within TimescaleDB's time range (294247-01-01 for a monthly timestamptz cagg) raised "timestamp out of range" while being expanded. The entry then stays in the hypertable log, so later refreshes that process the log fail for every cagg on that hypertable. main already fails this way when the end falls inside that bucket. The update expands the end to one before its next bucket start and treats a next bucket start beyond that range, or one whose computation overflows PostgreSQL's timestamp range for a wide bucket, as +infinity, as the fixed-width branch does past its last full bucket. The tests cover that bucket for a monthly and a 100-year cagg, plus an ordinary refresh with an offset of -100 years. Not changed here: a variable-bucket cagg with data in that last bucket still fails to refresh with the same error once the refresh window reaches it, even with an empty hypertable invalidation log. With default options I saw it come from the batch split in continuous_agg_split_refresh_window with an explicit end, and from invalidation_threshold_compute with a NULL end. Both reach ts_cagg_variable_next_bucket_start, which does not saturate the way cagg_fixed_next_bucket_start does. A daily cagg without a timezone in the same setup refreshes fine. Both reproducers in #10745 give the expected results on this branch: 101 for the second day in Riyadh, and April = 100 in the monthly aggregate. |
|
@JoongHyuk-Shin, thank you for updating the PR and explaining the overflow issue. I like that the updated fix computes the current bucket start and the next bucket start directly, instead of calling the helper meant for windows with an exclusive end. For the overflow issue, though, I'd like to explore approaches other than PG_TRY/PG_CATCH. Since the overflow case is very unlikely and is really a separate issue, for this PR I'd suggest:
Thanks again for the fix! |
Codecov Reportβ All modified and coverable lines are covered by tests. π’ Thoughts on this report? Let us know! |
c6c0368 to
1a6e055
Compare
|
@pnthao Thanks for the review. I updated the PR as you suggested: the overflow handling is removed, the fix calls ts_cagg_variable_next_bucket_start, and the changelog has the three Thanks lines. It is also rebased onto main. I agree the overflow case is very unlikely, and it may not have needed handling at all. I handled it here only because this fix newly exposes it, as I described in my previous comment: with ts_cagg_variable_next_bucket_start, an invalidation ending exactly at the start of the last bucket within TimescaleDB's time range raises "timestamp out of range" again. Your call to treat it as a separate issue is the right one, so I also removed the tests that came with the overflow handling, including the one with an offset of -100 years. I'll open that issue after this PR is merged. |
| inv->greatest_modified_value != INVAL_NEG_INFINITY) | ||
| { | ||
| inv->greatest_modified_value = | ||
| ts_cagg_variable_next_bucket_start(inv->greatest_modified_value, bucket_function); |
There was a problem hiding this comment.
Please add a comment here that we subtract 1 from the start of the next bucket because invalidations are inclusive at both ends.
|
Thanks @JoongHyuk-Shin for updating the fix. I noticed you also removed the test you added for the fix (other than the overflow test). Could you please add that back? |
1a6e055 to
3e8b3f5
Compare
|
Sorry, my mistake. I restored the test and the comment. Thanks! |
pnthao
left a comment
There was a problem hiding this comment.
Look good to me. Thank you @JoongHyuk-Shin for fixing the issue!
|
@JoongHyuk-Shin, could you please rebase with main again so the upgrade/downgrade tests can pass? Thank you! |
Invalidations are inclusive at the end, but ts_compute_circumscribed_bucketed_refresh_window_variable expects an exclusive end. The variable-bucket branch passed the inclusive value unchanged, so an invalidation that started in an earlier bucket and ended exactly on a bucket start lost that bucket, leaving it stale or unmaterialized without an error. A bucket with a named timezone is always classified as variable, even a daily one. The reported daily buckets start at local midnight, and every row of the reported write sits on one, so each invalidation it logs ends on a bucket start and loses that bucket. Expand the end directly to the last value of its bucket, one before the next bucket start. The hierarchical cagg test was asserting the buggy value: Q2 2025 has 30 + 31 + 30 days plus the row the test inserts at the quarter start, so its expected count becomes 92. A new test covers the reported case: a daily bucket with a named timezone and an invalidation that ends at local midnight. Fixes timescale#10296, fixes timescale#10745
3e8b3f5 to
d9a75ea
Compare
|
Rebased onto main. Thanks! |
|
I've merged the PR. Thank you @JoongHyuk-Shin again for the fix! |
This release includes security fixes, performance improvements, and bug fixes since 2.31.0. As part of our ongoing proactive security reviews, this release includes a larger set of security fixes than usual. We recommend that you upgrade as soon as possible. **Loader Changes** For the loader changes take effect a PostgreSQL restart is required. * [#10966](#10966) Check database ownership before stopping or restarting background workers on database commands * [#10983](#10983) Run the background worker scheduler as the database owner instead of as superuser **Features** * [#10864](#10864) Improve continuous aggregate refresh performance by updating the watermark once per batch * [#10878](#10878) Enable Adaptive Integer Compression (AIC) by default * [#10927](#10927) Remove user switching when allocating ids from the internal catalog sequences * [#10953](#10953) Allow database owners to start, stop, and restart background workers without superuser * [#10960](#10960) Run the telemetry job as the database owner instead of the role that installed the extension **Bugfixes** * [#10075](#10075) Removing the bloom1_contains function and rejecting anonymous record arrays in bloom1_contains_any * [#10296](#10296), [#10745](#10745) Fix continuous aggregate refresh skipping the last invalidated bucket for variable-sized buckets * [#10854](#10854) Correctly skip rows with conversion errors during `COPY FROM ON_ERROR` ignore * [#10855](#10855) Enforce `REJECT_LIMIT` during `COPY FROM` on PostgreSQL 18 and later * [#10887](#10887) Fix "repalloc called with invalid pointer" when compressing batches of more than 992 rows for certain data patterns * [#10893](#10893) Fix typo in the columnar README example * [#10902](#10902) Fix concurrent `UPDATE`/`DELETE` on hypertables silently skipping rows under `READ COMMITTED` * [#10919](#10919) Check schema `CREATE` privilege when creating a continuous aggregate * [#10925](#10925) Create chunk constraints without switching to the catalog owner * [#10961](#10961) Fix crash in `decompress_chunk` when the hypertable is dropped concurrently * [#10961](#10961) Fix null dereference in in-memory recompression when the compression settings are missing * [#10961](#10961) Fix stale chunk and hypertable state in `compress_chunk` when a concurrent decompress or compression change commits * [#10962](#10962) Reset `search_path` after every `COMMIT` in the columnstore policy * [#10964](#10964) Fix crash in `cagg_validate_query` when called with a `SELECT INTO` statement * [#10964](#10964) Fix crash in `cagg_validate_query` when the user lacks `SELECT` permission on the hypertable * [#10965](#10965) Verify the server certificate on telemetry SSL connections * [#10967](#10967) Fix crash in `show_policies` when called more than once in the same query * [#10968](#10968) Fix crash in `add_policies` and `alter_policies` when a `drop_created_before` retention policy exists on the hypertable or the continuous aggregate * [#10970](#10970) Fix `ORDER BY` pushdown for realtime continuous aggregates with an `ORDER BY` in their definition * [#10988](#10988) Report a missing policy config key as a user error instead of an internal error * [#10988](#10988) Restrict changing the config check function of a job to the job owner * [#10989](#10989) Match job procedures by OID in DDL hooks * [#10991](#10991) Fix function overload in `approximate_row_count` * [#10993](#10993) Require ownership of the chunk, not just of the hypertable, to do chunk operations on them **GUCs** * `compression_orderby_default_function`: Function to use for calculating default order_by setting for compression. Default: `timescaledb.compression_orderby_default_function` * `compression_segmentby_default_function`: Function to use for calculating default segment_by setting for compression. Default: `timescaledb.compression_segmentby_default_function` **Thanks** * @JoongHyuk-Shin for fixing continuous aggregate refresh skipping the last invalidated bucket for variable-width buckets, [10419](#10419) * @manishnithinreddy for reporting the concurrent `UPDATE`/`DELETE` regression and bisecting it to `2.28.1`, [10902](#10902) * @martin-omacht for reporting missing and stale buckets in a continuous aggregate with a timezone, [#10296](#10296) * @owhiterabbito for reporting the compression error and analyzing the selector buffer size, [#10887](#10887) * @pei711 for fixing a typo in the README, [#10893](#10893) * @salmanazmat666 for reporting the continuous aggregate refresh skipping the last bucket on a variable-width bucket boundary, [#10745](#10745)
Invalidations are inclusive at the end, but
ts_compute_circumscribed_bucketed_refresh_window_variable expects an exclusive end. The variable-bucket branch passed the inclusive value unchanged, so an invalidation that started in an earlier bucket and ended exactly on a bucket start lost that bucket, leaving it stale or unmaterialized without an error.
A bucket with a named timezone is always classified as variable, even a daily one. The reported daily buckets start at local midnight, and every row of the reported write sits on one, so each invalidation it logs ends on a bucket start and loses that bucket.
Expand the end directly to the last value of its bucket, one before the next bucket start.
The hierarchical cagg test was asserting the buggy value: Q2 2025 has 30 + 31 + 30 days plus the row the test inserts at the quarter start, so its expected count becomes 92. A new test covers the reported case: a daily bucket with a named timezone and an invalidation that ends at local midnight.
Fixes #10296, fixes #10745