-
Notifications
You must be signed in to change notification settings - Fork 916
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
If another extension want to track TimescaleDB events it is necessary to have a structure that can use the rendezvouz interface available in PostgreSQL in a safe manner. This commit adds such a structure containing: The size of the structure to be able to check that function pointers are not out-of-bounds. PostgreSQL magic to get compilation parameters affecting the ABI. This allow the plugin to check that it is compatible with the PostgreSQL server. PostgreSQL and TimescaleDB full version to be able to control usage from the plugin side. The PostgreSQL magic contains the major version of the server, but not the minor version, so we store `PG_VERSION_NUM` in this field and generate a similar `TS_VERSION_NUM` constant for TimescaleDB. This is mostly intended to deal with bugs inside a minor version.
- Loading branch information
Showing
9 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Implements: #7791 ABI for tracking TimescaleDB events |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* This file and its contents are licensed under the Apache License 2.0. | ||
* Please see the included NOTICE for copyright information and | ||
* LICENSE-APACHE for a copy of the license. | ||
*/ | ||
#include <postgres.h> | ||
|
||
#include "planner/planner.h" | ||
#include "timescaledb.h" | ||
#include <c.h> | ||
|
||
/* | ||
* This file contains function and support for dealing with the ABI. See the | ||
* header file for more information. | ||
*/ | ||
|
||
/* Structure to go from old definition in mem_guard to the TimescaleDB plugin | ||
structure defined in the header file. */ | ||
static TimescaleDBPlugin plugin_callbacks = { | ||
.magic = PG_MODULE_MAGIC_DATA, | ||
.pg_version = PG_VERSION_NUM, | ||
.ts_version = TS_VERSION_NUM, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* This file and its contents are licensed under the Apache License 2.0. | ||
* Please see the included NOTICE for copyright information and | ||
* LICENSE-APACHE for a copy of the license. | ||
*/ | ||
|
||
/* | ||
* File with definitions intended for plugins that want to interact with TimescaleDB. | ||
* | ||
* WARNING! Do not add variables, functions, macros, or other stuff that is | ||
* not intended for an external user, e.g., a separate plugin. | ||
*/ | ||
#pragma once | ||
|
||
#include <postgres.h> | ||
#include <fmgr.h> | ||
|
||
/* | ||
* Plugin structure with callbacks. | ||
* | ||
* Other plugins can use this to get information about the running version of | ||
* TimescaleDB as well as callbacks on particular events. | ||
* | ||
* IMPORTANT: If you extend this structure, take care to not remove any fields | ||
* and add new fields last. If you do not do this, you might break plugins | ||
* that are using the wrong version and read some field that you moved or | ||
* deleted. | ||
*/ | ||
typedef struct TimescaleDBPlugin | ||
{ | ||
size_t size; /* Size of this structure */ | ||
Pg_magic_struct magic; /* Pointer to PostgreSQL magic */ | ||
int pg_version; /* PostgreSQL version as a number */ | ||
int ts_version; /* TimescaleDB version as a number */ | ||
|
||
/* | ||
* Plugins can fill this in and get callbacks on particular events. | ||
*/ | ||
void (*bgw_job_starting)(Oid db_id, int32 job_id, Oid user_oid); | ||
void (*bgw_job_exiting)(Oid db_id, int job_id, int result); | ||
} TimescaleDBPlugin; | ||
|
||
#define TIMESCALEDB_PLUGIN_NAME "TimescaleDBPlugin" | ||
|
||
/* | ||
* Convenience macro for plugin callback. | ||
* | ||
* The expands to a check if: the plugin pointer is non-zero, the offset of | ||
* the function pointer is inside the structure, and the function pointer is | ||
* non-zero. | ||
* | ||
* If either is false, this is effectively a no-op. | ||
* | ||
* The check that the pointer is inside the size of the structure allows you | ||
* to add new functions to the structure without risking a call to a random | ||
* location if the structure is too "old" for the call. | ||
*/ | ||
#define TS_PLUGIN_CALLBACK(PTR, FUNC, ...) \ | ||
do \ | ||
{ \ | ||
if ((PTR) && offsetof(TimescaleDBPlugin, FUNC) < (PTR)->size && (PTR)->FUNC) \ | ||
(*(PTR)->FUNC)(__VA_ARGS__); \ | ||
} while (0) |