Skip to content

Commit

Permalink
modify code to account for OSM chunks having valid ranges
Browse files Browse the repository at this point in the history
in the catalog
  • Loading branch information
gayyappan committed Sep 19, 2023
1 parent 6d09d8a commit b4c2b56
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 45 deletions.
12 changes: 10 additions & 2 deletions src/chunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -3960,6 +3960,7 @@ ts_chunk_do_drop_chunks(Hypertable *ht, int64 older_than, int64 newer_than, int3

DEBUG_WAITPOINT("drop_chunks_chunks_found");

int32 osm_chunk_id = ts_chunk_get_osm_chunk_id(ht->fd.id);
if (has_continuous_aggs)
{
/* Exclusively lock all chunks, and invalidate the continuous
Expand Down Expand Up @@ -3989,6 +3990,11 @@ ts_chunk_do_drop_chunks(Hypertable *ht, int64 older_than, int64 newer_than, int3
* therefore be able to refresh accordingly.*/
for (uint64 i = 0; i < num_chunks; i++)
{
if (osm_chunk_id == chunks[i].fd.id)
{
// we do not rebuild continuous aggs if tiered data is dropped */
continue;
}
int64 start = ts_chunk_primary_dimension_start(&chunks[i]);
int64 end = ts_chunk_primary_dimension_end(&chunks[i]);

Expand All @@ -4008,8 +4014,11 @@ ts_chunk_do_drop_chunks(Hypertable *ht, int64 older_than, int64 newer_than, int3
/* frozen chunks are skipped. Not dropped. */
if (!ts_chunk_validate_chunk_status_for_operation(&chunks[i],
CHUNK_DROP,
false /*throw_error */))
false /*throw_error */) ||
osm_chunk_id == chunks[i].fd.id)
{
continue;
}

/* store chunk name for output */
schema_name = quote_identifier(chunks[i].fd.schema_name.data);
Expand All @@ -4032,7 +4041,6 @@ ts_chunk_do_drop_chunks(Hypertable *ht, int64 older_than, int64 newer_than, int3
}
// if we have tiered chunks cascade drop to tiering layer as well
#if PG14_GE
int32 osm_chunk_id = ts_chunk_get_osm_chunk_id(ht->fd.id);

if (osm_chunk_id != INVALID_CHUNK_ID)
{
Expand Down
49 changes: 20 additions & 29 deletions tsl/test/expected/chunk_utils_internal.out
Original file line number Diff line number Diff line change
Expand Up @@ -921,23 +921,34 @@ SELECT ts_setup_osm_hook();

(1 row)

BEGIN;
SELECT drop_chunks('hyper_constr', 10::int);
NOTICE: hypertable_drop_chunks_hook (-9223372036854775808 10)
drop_chunks
-------------
(0 rows)
NOTICE: hypertable_drop_chunks_hook
drop_chunks
-----------------------------
_timescaledb_internal.dummy
(1 row)

SELECT id, table_name FROM _timescaledb_catalog.chunk
where hypertable_id = (Select id from _timescaledb_catalog.hypertable where table_name = 'hyper_constr');
id | table_name
----+--------------------
13 | _hyper_7_13_chunk
14 | child_hyper_constr
(2 rows)

ROLLBACK;
CALL run_job(:deljob_id);
NOTICE: hypertable_drop_chunks_hook (-9223372036854775808 400)
NOTICE: hypertable_drop_chunks_hook
CALL run_job(:deljob_id);
NOTICE: hypertable_drop_chunks_hook (-9223372036854775808 400)
NOTICE: hypertable_drop_chunks_hook
SELECT chunk_name, range_start, range_end
FROM chunk_view
WHERE hypertable_name = 'hyper_constr'
ORDER BY chunk_name;
chunk_name | range_start | range_end
--------------------+---------------------------------------+-----------
child_hyper_constr | Sat Jan 09 20:00:54.775806 294247 PST | infinity
chunk_name | range_start | range_end
--------------------+-----------------------------------+------------------------------------
child_hyper_constr | Wed Dec 31 16:00:00.0001 1969 PST | Wed Dec 31 16:00:00.00011 1969 PST
(1 row)

SELECT ts_undo_osm_hook();
Expand Down Expand Up @@ -1049,26 +1060,6 @@ SELECT indexname, tablename FROM pg_indexes WHERE indexname = 'hyper_constr_mid_
(1 row)

DROP INDEX hyper_constr_mid_idx;
--TEST policy is applied on OSM chunk
-- XXX this is to be updated once the hook for dropping chunks is added
CREATE OR REPLACE FUNCTION dummy_now_smallint() RETURNS BIGINT LANGUAGE SQL IMMUTABLE as 'SELECT 500::bigint' ;
SELECT set_integer_now_func('hyper_constr', 'dummy_now_smallint');
set_integer_now_func
----------------------

(1 row)

SELECT add_retention_policy('hyper_constr', 100::int) AS deljob_id \gset
CALL run_job(:deljob_id);
CALL run_job(:deljob_id);
SELECT chunk_name, range_start, range_end
FROM chunk_view
WHERE hypertable_name = 'hyper_constr'
ORDER BY chunk_name;
chunk_name | range_start | range_end
------------+-------------+-----------
(0 rows)

-- test range of dimension slice for osm chunk for different datatypes
CREATE TABLE osm_int2(time int2 NOT NULL);
CREATE TABLE osm_int4(time int4 NOT NULL);
Expand Down
18 changes: 4 additions & 14 deletions tsl/test/sql/chunk_utils_internal.sql
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,11 @@ SELECT add_retention_policy('hyper_constr', 100::int) AS deljob_id \gset

--add hooks for osm callbacks that are triggered when drop_chunks is invoked---
SELECT ts_setup_osm_hook();
BEGIN;
SELECT drop_chunks('hyper_constr', 10::int);
SELECT id, table_name FROM _timescaledb_catalog.chunk
where hypertable_id = (Select id from _timescaledb_catalog.hypertable where table_name = 'hyper_constr');
ROLLBACK;
CALL run_job(:deljob_id);
CALL run_job(:deljob_id);
SELECT chunk_name, range_start, range_end
Expand Down Expand Up @@ -602,20 +606,6 @@ CREATE INDEX hyper_constr_mid_idx ON hyper_constr(mid, time) WITH (timescaledb.t
SELECT indexname, tablename FROM pg_indexes WHERE indexname = 'hyper_constr_mid_idx';
DROP INDEX hyper_constr_mid_idx;

--TEST policy is applied on OSM chunk
-- XXX this is to be updated once the hook for dropping chunks is added
CREATE OR REPLACE FUNCTION dummy_now_smallint() RETURNS BIGINT LANGUAGE SQL IMMUTABLE as 'SELECT 500::bigint' ;

SELECT set_integer_now_func('hyper_constr', 'dummy_now_smallint');
SELECT add_retention_policy('hyper_constr', 100::int) AS deljob_id \gset

CALL run_job(:deljob_id);
CALL run_job(:deljob_id);
SELECT chunk_name, range_start, range_end
FROM chunk_view
WHERE hypertable_name = 'hyper_constr'
ORDER BY chunk_name;

-- test range of dimension slice for osm chunk for different datatypes
CREATE TABLE osm_int2(time int2 NOT NULL);
CREATE TABLE osm_int4(time int4 NOT NULL);
Expand Down

0 comments on commit b4c2b56

Please sign in to comment.