Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .unreleased/pr_7766
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixes: #7766 Load OSM extension in retention background worker to drop tiered chunks
14 changes: 13 additions & 1 deletion src/chunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <commands/trigger.h>
#include <executor/executor.h>
#include <fmgr.h>
#include <foreign/fdwapi.h>
#include <funcapi.h>
#include <miscadmin.h>
#include <nodes/execnodes.h>
Expand Down Expand Up @@ -4034,16 +4035,27 @@ 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 (osm_chunk_id != INVALID_CHUNK_ID)
{
Chunk *osm_chunk = ts_chunk_get_by_id(osm_chunk_id, true);

hypertable_drop_chunks_hook_type osm_drop_chunks_hook =
ts_get_osm_hypertable_drop_chunks_hook();

/*
* The OSM library may not be loaded at the moment if
* `ts_chunk_do_drop_chunks` is called from the a background worker
* (e.g. from a retention policy). We call `GetFdwRoutineByRelId` to
* ensure the library is loaded.
*/
if (!osm_drop_chunks_hook && GetFdwRoutineByRelId(osm_chunk->table_id))
osm_drop_chunks_hook = ts_get_osm_hypertable_drop_chunks_hook();

if (osm_drop_chunks_hook)
{
ListCell *lc;
Dimension *dim = &ht->space->dimensions[0];
/* convert to PG timestamp from timescaledb internal format */
int64 range_start = ts_internal_to_time_int64(newer_than, dim->fd.column_type);
int64 range_end = ts_internal_to_time_int64(older_than, dim->fd.column_type);
Chunk *osm_chunk = ts_chunk_get_by_id(osm_chunk_id, true);
List *osm_dropped_names = osm_drop_chunks_hook(osm_chunk->table_id,
NameStr(ht->fd.schema_name),
NameStr(ht->fd.table_name),
Expand Down
Loading