Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
mkindahl committed Mar 4, 2025
1 parent a34987c commit b2fbb40
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ if(USE_OPENSSL)
endif(MSVC)
endif(USE_OPENSSL)

# This is a kind of strange usage, but it follows the convention of
# PG_VERSION_NUM, where you can get the major version by dividing by
# 100. However, the major number shows up as, e.g., 1500 for
# PostgreSQL version 15.
math(EXPR TS_VERSION_NUM "${PROJECT_VERSION_MAJOR} * 10000 + ${PROJECT_VERSION_MINOR}")

configure_file(config.h.in config.h)
add_dependencies(${PROJECT_NAME} gitcheck)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
Expand Down
13 changes: 13 additions & 0 deletions src/bgw/job.c
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,12 @@ ts_bgw_job_entrypoint(PG_FUNCTION_ARGS)
callbacks->toggle_allocation_blocking && !callbacks->enabled)
callbacks->toggle_allocation_blocking(/*enable=*/true);

TS_PLUGIN_CALLBACK(*timescaledb_plugin_ptr,
bgw_job_starting,
db_oid,
params.job_id,
params.user_oid);

BackgroundWorkerInitializeConnectionByOid(db_oid, params.user_oid, 0);

log_min_messages = ts_guc_bgw_log_level;
Expand Down Expand Up @@ -1285,6 +1291,11 @@ ts_bgw_job_entrypoint(PG_FUNCTION_ARGS)

CommitTransactionCommand();
FlushErrorState();
TS_PLUGIN_CALLBACK(*timescaledb_plugin_ptr,
bgw_job_exiting,
db_oid,
params.job_id,
JOB_FAILURE_IN_EXECUTION);
ReThrowError(edata);
}
PG_END_TRY();
Expand All @@ -1310,6 +1321,8 @@ ts_bgw_job_entrypoint(PG_FUNCTION_ARGS)
INSTR_TIME_SET_CURRENT(duration);
INSTR_TIME_SUBTRACT(duration, start);

TS_PLUGIN_CALLBACK(*timescaledb_plugin_ptr, bgw_job_exiting, db_oid, params.job_id, res);

elog(DEBUG1,
"job %d (%s) exiting with %s: execution time %.2f ms",
params.job_id,
Expand Down
1 change: 1 addition & 0 deletions src/bgw/job.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#pragma once

#include <postgres.h>
#include <fmgr.h>
#include <postmaster/bgworker.h>
#include <storage/lock.h>

Expand Down
1 change: 1 addition & 0 deletions src/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define BUILD_OS_VERSION "@CMAKE_SYSTEM_VERSION@"
#define BUILD_PROCESSOR "@CMAKE_SYSTEM_PROCESSOR@"
#define BUILD_POINTER_BYTES @CMAKE_SIZEOF_VOID_P@
#define TS_VERSION_NUM @TS_VERSION_NUM@

/*
* Value should be set in package release scripts. Otherwise
Expand Down
3 changes: 3 additions & 0 deletions src/extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "export.h"
#include "extension_constants.h"
#include "timescaledb.h"

extern void ts_extension_invalidate(void);
extern TSDLLEXPORT bool ts_extension_is_loaded(void);
Expand All @@ -21,3 +22,5 @@ extern TSDLLEXPORT char *ts_extension_schema_name(void);
extern const char *ts_experimental_schema_name(void);
extern const char *ts_extension_get_so_name(void);
extern bool ts_extension_is_proxy_table_relid(Oid relid);

extern TimescaleDBPlugin **timescaledb_plugin_ptr;
15 changes: 15 additions & 0 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@
#include "guc.h"
#include "license_guc.h"
#include "nodes/constraint_aware_append/constraint_aware_append.h"
#include "timescaledb.h"
#include "ts_catalog/catalog.h"
#include "version.h"

#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif

TimescaleDBPlugin **timescaledb_plugin_ptr = NULL;

extern void _hypertable_cache_init(void);
extern void _hypertable_cache_fini(void);

Expand Down Expand Up @@ -92,6 +95,12 @@ void
_PG_init(void)
{
static bool init_done = false;
static TimescaleDBPlugin timescaledb_plugin_var = {
.size = sizeof(TimescaleDBPlugin),
.magic = PG_MODULE_MAGIC_DATA,
.pg_version = PG_VERSION_NUM,
.ts_version = TS_VERSION_NUM,
};

/*
* Check extension_is loaded to catch certain errors such as calls to
Expand All @@ -107,6 +116,12 @@ _PG_init(void)
if (init_done)
return;

timescaledb_plugin_ptr =
(TimescaleDBPlugin **) find_rendezvous_variable(TIMESCALEDB_PLUGIN_NAME);
/* We're the first, so set up the structure */
if (*timescaledb_plugin_ptr == NULL)
*timescaledb_plugin_ptr = &timescaledb_plugin_var;

_cache_init();
_hypertable_cache_init();
_cache_invalidate_init();
Expand Down

0 comments on commit b2fbb40

Please sign in to comment.