25
25
#include <commands/trigger.h>
26
26
#include <executor/executor.h>
27
27
#include <fmgr.h>
28
+ #include <foreign/fdwapi.h>
28
29
#include <funcapi.h>
29
30
#include <miscadmin.h>
30
31
#include <nodes/execnodes.h>
@@ -4035,15 +4036,18 @@ ts_chunk_do_drop_chunks(Hypertable *ht, int64 older_than, int64 newer_than, int3
4035
4036
// if we have tiered chunks cascade drop to tiering layer as well
4036
4037
if (osm_chunk_id != INVALID_CHUNK_ID )
4037
4038
{
4039
+ Chunk * osm_chunk = ts_chunk_get_by_id (osm_chunk_id , true);
4040
+
4038
4041
hypertable_drop_chunks_hook_type osm_drop_chunks_hook =
4039
4042
ts_get_osm_hypertable_drop_chunks_hook ();
4040
4043
4041
4044
/*
4042
- * OSM library may not be loaded at the moment if `ts_chunk_do_drop_chunks`
4043
- * is called from the a background worker. If this is the case try to
4044
- * load it now.
4045
+ * The OSM library may not be loaded at the moment if
4046
+ * `ts_chunk_do_drop_chunks` is called from the a background worker
4047
+ * (e.g. from a retention policy). We call `GetFdwRoutineByRelId` to
4048
+ * ensure the library is loaded.
4045
4049
*/
4046
- if (!osm_drop_chunks_hook && ts_try_load_osm ( ))
4050
+ if (!osm_drop_chunks_hook && GetFdwRoutineByRelId ( osm_chunk -> table_id ))
4047
4051
osm_drop_chunks_hook = ts_get_osm_hypertable_drop_chunks_hook ();
4048
4052
4049
4053
if (osm_drop_chunks_hook )
@@ -4053,7 +4057,6 @@ ts_chunk_do_drop_chunks(Hypertable *ht, int64 older_than, int64 newer_than, int3
4053
4057
/* convert to PG timestamp from timescaledb internal format */
4054
4058
int64 range_start = ts_internal_to_time_int64 (newer_than , dim -> fd .column_type );
4055
4059
int64 range_end = ts_internal_to_time_int64 (older_than , dim -> fd .column_type );
4056
- Chunk * osm_chunk = ts_chunk_get_by_id (osm_chunk_id , true);
4057
4060
List * osm_dropped_names = osm_drop_chunks_hook (osm_chunk -> table_id ,
4058
4061
NameStr (ht -> fd .schema_name ),
4059
4062
NameStr (ht -> fd .table_name ),
0 commit comments