Skip to content

Commit

Permalink
Fix crash in 1-step integer retention policy creation
Browse files Browse the repository at this point in the history
When a retention policy existed on the underlying hypertable,
we would previously get a segmentation fault due to passing bool
instead of bool pointer. Fixed by passing the expected type.

Fixes #5907
  • Loading branch information
konskov committed Aug 1, 2023
1 parent d5268c3 commit ffc9d8c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
8 changes: 7 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,15 @@ 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);
if (!found_drop_after)
ereport(ERROR,
(errcode(ERRCODE_INTERNAL_ERROR),
errmsg("could not find %s in config for job",
POL_RETENTION_CONF_KEY_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 ffc9d8c

Please sign in to comment.