Skip to content
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
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mkindahl
Copy link
Contributor

@mkindahl mkindahl commented Mar 4, 2025

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. It is mostly useful to deal with issues inside a minor release and make sure that we have a venue to handle bugs.

@mkindahl mkindahl force-pushed the timescaledb-plugin-interface branch 3 times, most recently from 6088e9e to 2cd2858 Compare March 5, 2025 08:53
Copy link

codecov bot commented Mar 5, 2025

Codecov Report

Attention: Patch coverage is 42.85714% with 4 lines in your changes missing coverage. Please review.

Project coverage is 81.88%. Comparing base (59f50f2) to head (b0bcbc2).
Report is 805 commits behind head on main.

Files with missing lines Patch % Lines
src/bgw/job.c 0.00% 0 Missing and 3 partials ⚠️
src/init.c 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7791      +/-   ##
==========================================
+ Coverage   80.06%   81.88%   +1.82%     
==========================================
  Files         190      247      +57     
  Lines       37181    45466    +8285     
  Branches     9450    11372    +1922     
==========================================
+ Hits        29770    37232    +7462     
- Misses       2997     3752     +755     
- Partials     4414     4482      +68     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mkindahl mkindahl changed the title Timescaledb plugin interface Add ABI for tracking events Mar 5, 2025
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.
@mkindahl mkindahl force-pushed the timescaledb-plugin-interface branch from 2cd2858 to b0bcbc2 Compare March 5, 2025 17:22
Comment on lines +58 to +63
#define TS_PLUGIN_CALLBACK(PTR, FUNC, ...) \
do \
{ \
if ((PTR) && offsetof(TimescaleDBPlugin, FUNC) < (PTR)->size && (PTR)->FUNC) \
(*(PTR)->FUNC)(__VA_ARGS__); \
} while (0)
Copy link
Contributor

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

Copy link
Contributor Author

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.

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.

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants