-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Cap refresh start when hypertable has tiered data #9811
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fixes: #9811 Cap refresh start when hypertable has tiered data |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,8 @@ | |
| #include "cache.h" | ||
| #include "continuous_aggs/invalidation_threshold.h" | ||
| #include "continuous_aggs/materialize.h" | ||
| #include "dimension.h" | ||
| #include "dimension_slice.h" | ||
| #include "guc.h" | ||
| #include "invalidation.h" | ||
| #include "refresh.h" | ||
|
|
@@ -1286,6 +1288,30 @@ invalidation_cagg_has_pending_mat_ranges(ContinuousAgg *cagg) | |
| return found; | ||
| } | ||
|
|
||
| /* | ||
| * Return the range_start of the earliest dimension slice (chunk) for the | ||
| * given raw hypertable, or INVAL_NEG_INFINITY when no chunks exist. | ||
| * | ||
| * This is used to ignore invalidation entries that lie entirely before any | ||
| * chunk — such entries cannot affect materialized data and should be | ||
| * preserved for future use rather than treated as pending work. | ||
| */ | ||
| int64 | ||
| invalidation_get_earliest_chunk_start(int32 raw_hypertable_id) | ||
| { | ||
| Hypertable *raw_ht = cagg_get_hypertable_or_fail(raw_hypertable_id); | ||
| const Dimension *time_dim = hyperspace_get_open_dimension(raw_ht->space, 0); | ||
| Assert(time_dim != NULL); | ||
|
|
||
| DimensionSlice *slice = ts_dimension_slice_earliest_non_osm_slice(time_dim->fd.id); | ||
| if (slice != NULL) | ||
| { | ||
| return slice->fd.range_start; | ||
| } | ||
|
|
||
| return INVAL_NEG_INFINITY; | ||
| } | ||
|
|
||
| bool | ||
| invalidation_cagg_has_invalidations(ContinuousAgg *cagg) | ||
| { | ||
|
|
@@ -1299,6 +1325,26 @@ invalidation_cagg_has_invalidations(ContinuousAgg *cagg) | |
| PG_INT64_MAX); | ||
|
|
||
| int64 watermark = ts_cagg_watermark_get(cagg_hyper_id); | ||
|
|
||
| /* | ||
| * Expand the earliest chunk boundary to the end of its containing | ||
| * bucket. Invalidation entries are also bucket-expanded, so both | ||
| * sides of the comparison use consistent bucket-aligned values. | ||
| * Any entry whose expanded greatest_modified_value falls within this | ||
| * bucket or earlier lies entirely before the first data and can be | ||
| * ignored. | ||
| */ | ||
| int64 earliest_start = invalidation_get_earliest_chunk_start(cagg->data.raw_hypertable_id); | ||
| if (earliest_start != INVAL_NEG_INFINITY) | ||
| { | ||
| Invalidation boundary = { .lowest_modified_value = earliest_start, | ||
| .greatest_modified_value = earliest_start }; | ||
| invalidation_expand_to_bucket_boundaries(&boundary, | ||
| cagg->partition_type, | ||
| cagg->bucket_function); | ||
| earliest_start = boundary.greatest_modified_value; | ||
| } | ||
|
Comment on lines
+1337
to
+1346
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand why we want to ignore anything before the value initially return by I feel like skipping the whole bucket as if it's not invalidated may trigger rewrite to use the cagg when the specific bucket is actually stale in the cagg. |
||
|
|
||
| ts_scanner_foreach(&iterator) | ||
| { | ||
| TupleInfo *ti; | ||
|
|
@@ -1310,9 +1356,11 @@ invalidation_cagg_has_invalidations(ContinuousAgg *cagg) | |
| ti, | ||
| cagg->partition_type, | ||
| cagg->bucket_function); | ||
|
|
||
| /* Entries which cannot be invalidations */ | ||
| if (logentry.greatest_modified_value == INVAL_NEG_INFINITY || | ||
| logentry.lowest_modified_value >= watermark) | ||
| logentry.lowest_modified_value >= watermark || | ||
| logentry.greatest_modified_value <= earliest_start) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
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.
*slicehere assigned whether it's an osm chunk or not. Imagine a case where there is no non-osm chunk and all data is tiered, we would end up this*slicealready assigned. The caller assumes that it's non-osm as long as it's not NULL which does not hold in this case.We should either check again in the caller, or nullify
*sliceif it's osm in the laterIS_OSM_CHUNKcheck here.