-
Notifications
You must be signed in to change notification settings - Fork 916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ABI for tracking events #7791
Draft
mkindahl
wants to merge
1
commit into
timescale:main
Choose a base branch
from
mkindahl:timescaledb-plugin-interface
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+126
−0
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation is prepared to call a function passing some parameters but without returning values. I think we also need a way to cover execute a callback function from other extension returning some value. I.e.: https://github.com/timescale/timescaledb/blob/main/src/tss_callbacks.h#L16
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I did that since I was unsure if the added functions need a return value. It is easy to add/modify if we need, even in later versions, since this is just a convenience macro.
Ah, good, I was wondering if there were anything else that we should add at this time.
It is possible to have callbacks both ways, but setting it up is a little tricky so thinking about good schemes for dealing with this to reduce the risk of mistakes.