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

pgsqlSetNoticeCallback #6764

Closed
wants to merge 10 commits into from
Closed

pgsqlSetNoticeCallback #6764

wants to merge 10 commits into from

Conversation

outtersg
Copy link
Contributor

Allows a callback to be triggered on every notice sent by PostgreSQL.

Such notices can be sent with a RAISE NOTICE in PL/pgSQL; in a long running
stored procedure, they prove useful as realtime checkpoint indicators.

Originally proposed at https://bugs.php.net/78621

@driesvints
Copy link

@outtersg you might want to rebase here so the PR can be merged. The appveyor build also seems to fail.

@outtersg
Copy link
Contributor Author

@outtersg you might want to rebase here so the PR can be merged. The appveyor build also seems to fail.

Thanks @driesvints for mentionning it… I did not even noticed I wasn't notified of my own PR's status changes.

@outtersg outtersg force-pushed the issue-78621-php8 branch 3 times, most recently from dbae1c6 to 9c4507e Compare October 26, 2021 05:40
@HellLeaf
Copy link

Is this PR still active?

@outtersg
Copy link
Contributor Author

@HellLeaf wrote:

Is this PR still active?

Yes, I ensure it still compiles (with PHP 8.1.2);
and it still proves really useful in a production environment where PHP launches long PL/pgsql stored procedures.

@devnexen
Copy link
Member

Sorry for the long reply, could you possibly rebase against the current master please ? thanks.

@outtersg
Copy link
Contributor Author

@devnexen wrote:

Sorry for the long reply, could you possibly rebase against the current master please ? thanks.

And here it is;
by the way, the CI spotted an approximation I did on the generated _arginfo.h, so long live the CI!
(and thank you for showing interest to this PR from so far away in time!)

@devnexen
Copy link
Member

Thanks I ll have a look later this week, at first glance looking good.

Copy link
Member

@devnexen devnexen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good but will wait a bit before merging.

Copy link
Member

@nielsdos nielsdos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some things about the code don't seem 100% right. Please also test this with a Closure object and a trampoline.

ext/pdo_pgsql/php_pdo_pgsql_int.h Outdated Show resolved Hide resolved
ext/pdo_pgsql/pgsql_driver.c Show resolved Hide resolved
ext/pdo_pgsql/pgsql_driver.c Outdated Show resolved Hide resolved
ext/pdo_pgsql/pgsql_driver.c Outdated Show resolved Hide resolved
ext/pdo_pgsql/pgsql_driver.c Outdated Show resolved Hide resolved
ext/pdo_pgsql/pgsql_driver.c Outdated Show resolved Hide resolved
ext/pdo_pgsql/pgsql_driver.c Outdated Show resolved Hide resolved
ext/pdo_pgsql/pgsql_driver.c Outdated Show resolved Hide resolved
ext/pdo_pgsql/pgsql_driver.c Outdated Show resolved Hide resolved
ext/pdo_pgsql/pgsql_driver.c Outdated Show resolved Hide resolved
@outtersg
Copy link
Contributor Author

outtersg commented May 7, 2024

Thank you @nielsdos for your invaluable review! I started this as an amateur quick way of implementing my need, with zero knowledge of the PHP coding best practices (and in fact no intelligence at all in the code: most of it is a big copy-paste-adapt of some other ext where I found callback use, from a PHP 5.3 source tree). So your detailed review with tips on exactly how to converge to a clean solution is really welcome for the newby I am here.

I'm wondering with your:

Please also test this with a Closure object and a trampoline.

that I'm not familiar at all with. Would you please point me to a test sample of a trampoline callback I could elaborate upon?

I'll try to digest and apply all you recommendations, but it will take me some time (and probably many IC failures) before something polished emerges here.

@nielsdos
Copy link
Member

nielsdos commented May 7, 2024

that I'm not familiar at all with. Would you please point me to a test sample of a trampoline callback I could elaborate upon?

Please see


When you have a class with the __call magic function, you can create a "trampoline" by creating a callable to any name that is not a method already on the class. E.g. on line 18 of that test, a callable to the authorizer function of that class is made which will implicitly call the __call function. Internally this kind of callable is known as a trampoline because the engine needs an extra step.

The commit that added the test also has some code for the "F" ZPP modifier.

I'll try to digest and apply all you recommendations, but it will take me some time (and probably many IC failures) before something polished emerges here.

No worries!

In any case, if you're stuck or have questions just ping us 🙂

Allows a callback to be triggered on every notice sent by PostgreSQL.

Such notices can be sent with a RAISE NOTICE in PL/pgSQL; in a long running
stored procedure, they prove useful as realtime checkpoint indicators.
Copy link
Member

@nielsdos nielsdos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks much much better! Thanks!
I have some review comments, but the hard part of the work is over :)

ext/pdo_pgsql/pgsql_driver.c Outdated Show resolved Hide resolved
ext/pdo_pgsql/pgsql_driver.c Outdated Show resolved Hide resolved
ext/pdo_pgsql/pgsql_driver.c Show resolved Hide resolved
ext/pdo_pgsql/pgsql_driver.c Outdated Show resolved Hide resolved
ext/pdo_pgsql/pgsql_driver.c Outdated Show resolved Hide resolved
ext/pdo_pgsql/pgsql_driver.c Outdated Show resolved Hide resolved
ext/pdo_pgsql/pgsql_driver.c Show resolved Hide resolved
ext/pdo_pgsql/pgsql_driver.c Outdated Show resolved Hide resolved
ext/pdo_pgsql/pgsql_driver.stub.php Outdated Show resolved Hide resolved
@outtersg
Copy link
Contributor Author

Thanks @nielsdos for your second, exhaustive review (and your responsiveness)!

Your advice made a monstrously satisfying simplification and clarification to the whole thing.

Three notes:

  • for reviewing purpose, I like to keep individual commits, but here the history begins to look like Amazonia: do I need to squash? (or will it be done at merging, so that the branch can keep its prolific history?)
  • I let two comments unresolved, waiting for your verdict. I had to give my somewhat controversial point of view, but really I'm torn between both ways
  • I chose not to store the FCC as is in the pdo_pgsql_db_handle, but instead rely on a pointer: as pgsqlSetNoticeCallback is uncommon, having a full unitialized FCC there 99,999 % of the time would have been a waste of bytes (yes, I'm counting them one by one!)

@nielsdos
Copy link
Member

Thanks @nielsdos for your second, exhaustive review (and your responsiveness)!

Your advice made a monstrously satisfying simplification and clarification to the whole thing.

You're welcome!

Three notes:

* for reviewing purpose, I like to keep individual commits, but here the history begins to look like Amazonia: do I need to squash? (or will it be done at merging, so that the branch can keep its prolific history?)

No need to worry about the history. We will do the squash upon merging.

* I let two comments unresolved, waiting for your verdict. I had to give my somewhat controversial point of view, but really I'm torn between both ways

Replied on your comment 🙂

* I chose _not_ to store the FCC as is in the pdo_pgsql_db_handle, but instead rely on a pointer: as pgsqlSetNoticeCallback is uncommon, having a full unitialized FCC there 99,999 % of the time would have been a waste of bytes (yes, I'm counting them one by one!)

That's fine, it makes sense.

Copy link
Member

@nielsdos nielsdos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your work! Looks good to me.
@devnexen Want to have a final sanity check and take it from here?

ext/pdo_pgsql/pgsql_driver.c Outdated Show resolved Hide resolved
@devnexen
Copy link
Member

Thanks I ll have a last look tomorrow :)

@devnexen
Copy link
Member

Thanks for your work !

@kocsismate
Copy link
Member

@outtersg Was the new method intentionally not added to the new PdoPgsql class?

@outtersg
Copy link
Contributor Author

outtersg commented May 22, 2024

@kocsismate wrote:

@outtersg Was the new method intentionally not added to the new PdoPgsql class?

:-\ I started this closely following pgsqlCopyFromArray (available but undocumented), and I didn't think to check if anything had changed regarding the exposition points of all those semi-public functions.

… But nothing is unchangeable, see #14299.

outtersg added a commit to outtersg/php-src that referenced this pull request May 22, 2024
Make the newly implemented setNoticeCallback() officially exposed (php#6764)
outtersg added a commit to outtersg/php-src that referenced this pull request May 22, 2024
Make the newly implemented setNoticeCallback() officially exposed (php#6764)
outtersg added a commit to outtersg/php-src that referenced this pull request May 22, 2024
Make the newly implemented setNoticeCallback() officially exposed (php#6764)
outtersg added a commit to outtersg/php-src that referenced this pull request May 23, 2024
Make the newly implemented setNoticeCallback() officially exposed (php#6764)
outtersg added a commit to outtersg/php-src that referenced this pull request May 24, 2024
Make the newly implemented setNoticeCallback() officially exposed (php#6764)
outtersg added a commit to outtersg/php-src that referenced this pull request May 25, 2024
Make the newly implemented setNoticeCallback() officially exposed (php#6764)
outtersg added a commit to outtersg/php-src that referenced this pull request May 30, 2024
Make the newly implemented setNoticeCallback() officially exposed (php#6764)
outtersg added a commit to outtersg/php-src that referenced this pull request May 30, 2024
Make the newly implemented setNoticeCallback() officially exposed (php#6764)
outtersg added a commit to outtersg/php-src that referenced this pull request Jun 7, 2024
Make the newly implemented setNoticeCallback() officially exposed (php#6764)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants