Skip to content

Commit

Permalink
Fix crash in 1-step integer policy creation
Browse files Browse the repository at this point in the history
Previously when a retention policy existed on the underlying hypertable,
we would get a segmentation fault when trying to add a Cagg refresh
policy, due to passing a bool instead of pointer to bool argument to
function `ts_jsonb_get_int64_field` in a particular code path.
Fixed by passing the expected pointer type.

Fixes #5907
  • Loading branch information
konskov committed Aug 1, 2023
1 parent 0d127f6 commit 725c4bb
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
1 change: 1 addition & 0 deletions .unreleased/bugfix_5907
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixes: #5912 Fix crash in 1-step integer retention policy creation
3 changes: 2 additions & 1 deletion tsl/src/bgw_policy/policies_v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,10 @@ validate_and_create_policies(policies_info all_policies, bool if_exists)
{
if (IS_INTEGER_TYPE(all_policies.partition_type))
{
bool found_drop_after = false;
drop_after_HT = ts_jsonb_get_int64_field(orig_ht_reten_job->fd.config,
POL_RETENTION_CONF_KEY_DROP_AFTER,
false);
&found_drop_after);
}
else
{
Expand Down
31 changes: 31 additions & 0 deletions tsl/test/expected/cagg_policy.out
Original file line number Diff line number Diff line change
Expand Up @@ -1275,3 +1275,34 @@ SELECT * FROM deals_best_weekly;
Sun Apr 24 17:00:00 2022 PDT | 117.764705882353 | 6
(1 row)

-- github issue 5907
CREATE TABLE t(a integer NOT NULL, b integer);
SELECT create_hypertable('t', 'a', chunk_time_interval=> 10);
create_hypertable
-------------------
(25,public,t,t)
(1 row)

CREATE OR REPLACE FUNCTION unix_now() returns int LANGUAGE SQL IMMUTABLE as $$ SELECT extract(epoch from now())::INT $$;
SELECT set_integer_now_func('t', 'unix_now');
set_integer_now_func
----------------------

(1 row)

SELECT add_retention_policy('t', 20);
add_retention_policy
----------------------
1056
(1 row)

CREATE MATERIALIZED VIEW cagg(a, sumb) WITH (timescaledb.continuous)
AS SELECT time_bucket(1, a), sum(b)
FROM t GROUP BY time_bucket(1, a);
NOTICE: continuous aggregate "cagg" is already up-to-date
SELECT timescaledb_experimental.add_policies('cagg');
add_policies
--------------
f
(1 row)

15 changes: 15 additions & 0 deletions tsl/test/sql/cagg_policy.sql
Original file line number Diff line number Diff line change
Expand Up @@ -630,3 +630,18 @@ SELECT * FROM deals_best_daily ORDER BY bucket LIMIT 2;
-- expect to get an up-to-date notice
CALL refresh_continuous_aggregate('deals_best_weekly', '2022-04-24', '2022-05-05');
SELECT * FROM deals_best_weekly;

-- github issue 5907
CREATE TABLE t(a integer NOT NULL, b integer);
SELECT create_hypertable('t', 'a', chunk_time_interval=> 10);

CREATE OR REPLACE FUNCTION unix_now() returns int LANGUAGE SQL IMMUTABLE as $$ SELECT extract(epoch from now())::INT $$;
SELECT set_integer_now_func('t', 'unix_now');

SELECT add_retention_policy('t', 20);

CREATE MATERIALIZED VIEW cagg(a, sumb) WITH (timescaledb.continuous)
AS SELECT time_bucket(1, a), sum(b)
FROM t GROUP BY time_bucket(1, a);

SELECT timescaledb_experimental.add_policies('cagg');

0 comments on commit 725c4bb

Please sign in to comment.