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

Fix transaction leak when DMLs contains a non pltsql language function which calls another non tsql function inside try catch #3217

Merged

Conversation

tanscorpio7
Copy link
Contributor

@tanscorpio7 tanscorpio7 commented Dec 6, 2024

Description

When DMLs are executed outside a user transaction block, babelfish starts an implicit transaction to handle errors inside triggers. This is done irrespective of whether the statement actually fires a trigger.
Now if the DML calls a non pltsql function which in calls another non tsql func or procedure inside a try catch, we do not properly decrement the pltsql_sys_func_entry_count variable properly. So the return value of pltsql_support_tsql_transactions() is different at beginning of the DML compared to after the end of the statement. This difference leads to babelfish not commit the implict transaction block.
As a fix, store the value of pltsql_support_tsql_transactions() at start of execution of DML and just reuse it for after execution.

Issues Resolved

[BABEL-5446]

Sign Off

Signed-off-by: Tanzeel Khan [email protected]

Check List

  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is under the terms of the Apache 2.0 and PostgreSQL licenses, and grant any person obtaining a copy of the contribution permission to relicense all or a portion of my contribution to the PostgreSQL License solely to contribute all or a portion of my contribution to the PostgreSQL open source project.

For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@coveralls
Copy link
Collaborator

coveralls commented Dec 6, 2024

Pull Request Test Coverage Report for Build 12281033050

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 9 of 9 (100.0%) changed or added relevant lines in 1 file are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.002%) to 74.81%

Files with Coverage Reduction New Missed Lines %
contrib/babelfishpg_tds/src/backend/tds/tdscomm.c 2 76.03%
Totals Coverage Status
Change from base Build 12240640252: -0.002%
Covered Lines: 46471
Relevant Lines: 62119

💛 - Coveralls

@tanscorpio7 tanscorpio7 changed the title draft Fix transaction leak when DMLs contains a non pltsql language function which calls another non tsql function inside try catch Dec 9, 2024
Signed-off-by: Tanzeel Khan <[email protected]>
@@ -4622,6 +4622,7 @@ exec_stmt_execsql(PLtsql_execstate *estate,
bool fmtonly_enabled = true;
CmdType cmd = CMD_UNKNOWN;
bool enable_txn_in_triggers = !pltsql_disable_txn_in_triggers;
bool support_tsql_trans = pltsql_support_tsql_transactions();
Copy link
Contributor

Choose a reason for hiding this comment

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

Please see if this fix is needed for other callers of pltsql_support_tsql_transactions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also made this change in pltsql_exec_trigger. Change was not needed there, but did it anyway for consistency in code.

@shardgupta shardgupta merged commit 8d92966 into babelfish-for-postgresql:BABEL_5_X_DEV Dec 12, 2024
44 checks passed
tanscorpio7 added a commit to tanscorpio7/babelfish_extensions that referenced this pull request Dec 18, 2024
…n which calls another non tsql function inside try catch (babelfish-for-postgresql#3217)

When DMLs are executed outside a user transaction block, babelfish starts an implicit transaction to handle errors inside triggers. This is done irrespective of whether the statement actually fires a trigger.
Now if the DML calls a non pltsql function which in calls another non tsql func or procedure inside a try catch, we do not properly decrement the pltsql_sys_func_entry_count variable properly. So the return value of pltsql_support_tsql_transactions() is different at beginning of the DML compared to after the end of the statement. This difference leads to babelfish not commit the implict transaction block.
As a fix, store the value of pltsql_support_tsql_transactions() at start of execution of DML and just reuse it for after execution.

Issues Resolved: [BABEL-5446]

Signed-off-by: Tanzeel Khan [email protected]
tanscorpio7 added a commit to tanscorpio7/babelfish_extensions that referenced this pull request Dec 18, 2024
…n which calls another non tsql function inside try catch (babelfish-for-postgresql#3217)

When DMLs are executed outside a user transaction block, babelfish starts an implicit transaction to handle errors inside triggers. This is done irrespective of whether the statement actually fires a trigger.
Now if the DML calls a non pltsql function which in calls another non tsql func or procedure inside a try catch, we do not properly decrement the pltsql_sys_func_entry_count variable properly. So the return value of pltsql_support_tsql_transactions() is different at beginning of the DML compared to after the end of the statement. This difference leads to babelfish not commit the implict transaction block.
As a fix, store the value of pltsql_support_tsql_transactions() at start of execution of DML and just reuse it for after execution.

Issues Resolved: [BABEL-5446]

Signed-off-by: Tanzeel Khan [email protected]
shardgupta pushed a commit that referenced this pull request Dec 18, 2024
…n which calls another non tsql function inside try catch (#3217) (#3272)

When DMLs are executed outside a user transaction block, babelfish starts an implicit transaction to handle errors inside triggers. This is done irrespective of whether the statement actually fires a trigger.
Now if the DML calls a non pltsql function which in calls another non tsql func or procedure inside a try catch, we do not properly decrement the pltsql_sys_func_entry_count variable properly. So the return value of pltsql_support_tsql_transactions() is different at beginning of the DML compared to after the end of the statement. This difference leads to babelfish not commit the implict transaction block.
As a fix, store the value of pltsql_support_tsql_transactions() at start of execution of DML and just reuse it for after execution.

Issues Resolved: [BABEL-5446]

Signed-off-by: Tanzeel Khan [email protected]
shardgupta pushed a commit that referenced this pull request Dec 18, 2024
…n which calls another non tsql function inside try catch (#3217) (#3273)

When DMLs are executed outside a user transaction block, babelfish starts an implicit transaction to handle errors inside triggers. This is done irrespective of whether the statement actually fires a trigger.
Now if the DML calls a non pltsql function which in calls another non tsql func or procedure inside a try catch, we do not properly decrement the pltsql_sys_func_entry_count variable properly. So the return value of pltsql_support_tsql_transactions() is different at beginning of the DML compared to after the end of the statement. This difference leads to babelfish not commit the implict transaction block.
As a fix, store the value of pltsql_support_tsql_transactions() at start of execution of DML and just reuse it for after execution.

Issues Resolved: [BABEL-5446]

Signed-off-by: Tanzeel Khan [email protected]
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.

4 participants