Skip to content

Commit 1f56ec5

Browse files
committed
Use GetFdwRoutineByRelId to load the OSM library
1 parent 03ab0d7 commit 1f56ec5

File tree

3 files changed

+8
-49
lines changed

3 files changed

+8
-49
lines changed

src/chunk.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <commands/trigger.h>
2626
#include <executor/executor.h>
2727
#include <fmgr.h>
28+
#include <foreign/fdwapi.h>
2829
#include <funcapi.h>
2930
#include <miscadmin.h>
3031
#include <nodes/execnodes.h>
@@ -4035,15 +4036,18 @@ ts_chunk_do_drop_chunks(Hypertable *ht, int64 older_than, int64 newer_than, int3
40354036
// if we have tiered chunks cascade drop to tiering layer as well
40364037
if (osm_chunk_id != INVALID_CHUNK_ID)
40374038
{
4039+
Chunk *osm_chunk = ts_chunk_get_by_id(osm_chunk_id, true);
4040+
40384041
hypertable_drop_chunks_hook_type osm_drop_chunks_hook =
40394042
ts_get_osm_hypertable_drop_chunks_hook();
40404043

40414044
/*
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.
40454049
*/
4046-
if (!osm_drop_chunks_hook && ts_try_load_osm())
4050+
if (!osm_drop_chunks_hook && GetFdwRoutineByRelId(osm_chunk->table_id))
40474051
osm_drop_chunks_hook = ts_get_osm_hypertable_drop_chunks_hook();
40484052

40494053
if (osm_drop_chunks_hook)
@@ -4053,7 +4057,6 @@ ts_chunk_do_drop_chunks(Hypertable *ht, int64 older_than, int64 newer_than, int3
40534057
/* convert to PG timestamp from timescaledb internal format */
40544058
int64 range_start = ts_internal_to_time_int64(newer_than, dim->fd.column_type);
40554059
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);
40574060
List *osm_dropped_names = osm_drop_chunks_hook(osm_chunk->table_id,
40584061
NameStr(ht->fd.schema_name),
40594062
NameStr(ht->fd.table_name),

src/osm_callbacks.c

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -79,46 +79,3 @@ ts_get_osm_hypertable_drop_chunks_hook()
7979
return ptr->hypertable_drop_chunks_hook;
8080
return NULL;
8181
}
82-
83-
TSDLLEXPORT bool
84-
ts_try_load_osm(void)
85-
{
86-
bool res = false;
87-
Oid osm_extension_oid = get_extension_oid(OSM_EXTENSION_NAME, true);
88-
89-
if (OidIsValid(osm_extension_oid))
90-
{
91-
MemoryContext old_mcxt = CurrentMemoryContext;
92-
93-
PG_TRY();
94-
{
95-
char version[MAX_VERSION_LEN];
96-
char soname[MAX_SO_NAME_LEN];
97-
98-
/* Format the osm library path */
99-
strlcpy(version, ts_osm_extension_version(), MAX_VERSION_LEN);
100-
snprintf(soname, MAX_SO_NAME_LEN, "%s%s-%s", TS_LIBDIR, OSM_EXTENSION_NAME, version);
101-
102-
/* Load the library */
103-
load_external_function(soname, "pfdw_handler_wrapper", false, NULL);
104-
res = true;
105-
}
106-
PG_CATCH();
107-
{
108-
ErrorData *error;
109-
110-
/* Switch to the original context & copy edata */
111-
MemoryContextSwitchTo(old_mcxt);
112-
error = CopyErrorData();
113-
FlushErrorState();
114-
115-
elog(LOG, "failed to load OSM extension: %s", error->message);
116-
117-
/* Finally, free error data */
118-
FreeErrorData(error);
119-
}
120-
PG_END_TRY();
121-
}
122-
123-
return res;
124-
}

src/osm_callbacks.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,3 @@ typedef struct
4242
extern chunk_insert_check_hook_type ts_get_osm_chunk_insert_hook(void);
4343
extern hypertable_drop_hook_type ts_get_osm_hypertable_drop_hook(void);
4444
extern hypertable_drop_chunks_hook_type ts_get_osm_hypertable_drop_chunks_hook(void);
45-
extern bool ts_try_load_osm(void);

0 commit comments

Comments
 (0)