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

Manually delete physical files for ENR entries when leaving scope. #450

Conversation

Sairakan
Copy link
Contributor

@Sairakan Sairakan commented Sep 25, 2024

Description

Second attempt at babelfish-for-postgresql/babelfish_extensions#2930 (which was reverted). This time, we completely ignore the pending deletes list, and instead manually trigger file deletion for each of the ENR entries we are dropping during ENRDropTempTables(). This ensures that we don't need to mess with the pendingDeletes list at all, while still properly deleting the physical storage for ENR entries when they are no longer in scope (such as at the end of a stored procedure call, explicit transaction, or batch).

Issues Resolved

BABEL-4751

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 PostgreSQL license, 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.

@Sairakan Sairakan changed the title Add separate list to track pending deletes for TSQL ENR entries. Use separate list to track pending deletes for TSQL ENR entries. Sep 25, 2024
/*
* Also register the physical file to be deleted at the end of scope.
*/
ENRDelete(enr->md.reliddesc);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not delete the file right here rather than adding it to delete list and later calling smgrDoPendingDeletes. We can write a new function to delete a file in SMGR

Copy link
Contributor Author

@Sairakan Sairakan Sep 26, 2024

Choose a reason for hiding this comment

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

Let me look into this. The original reasoning behind doing it this way is that I am not sure how much of the storage deletion needs to be copied, vs just immediately calling smgr_close() on the relation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've implemented this suggestion - now the files are immediately cleaned up during this function, which has the added benefit of not needing to modify any other function signatures or anything else in the code.

@Sairakan Sairakan changed the title Use separate list to track pending deletes for TSQL ENR entries. Manually delete physical files for ENR entries when leaving scope. Sep 26, 2024
srel = smgropen(rel->rd_locator, rel->rd_backend);

/* allocate the initial array, or extend it, if needed */
if (maxrels == 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

why are we doing this? we have single relationship, we should just pass pointer to that relation with count as 1 to smgrdounlinkall

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We do not necessarily only have one relation - there can be multiple table variables and temp tables defined in the same scope, which would all be cleaned up at once by this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correction: currently table variables are being cleaned up prior to this function during pltsql_clean_table_variables(), which manually executes a DROP TABLE statement to drop the table variable. Since that function only registers the physical file for deletion at transaction rather than immediately, we probably should remove that function and let this function do both table variable and temp table cleanup, but that can be done in a later commit.

TLDR: currently only temp tables in scope are being cleaned up here, and not table variables, which are handled separately.

@lejaokri lejaokri merged commit f5394b4 into babelfish-for-postgresql:BABEL_4_X_DEV__PG_16_X Sep 27, 2024
2 checks passed
roshan0708 pushed a commit to amazon-aurora/postgresql_modified_for_babelfish that referenced this pull request Oct 18, 2024
…ope. (babelfish-for-postgresql#450)

Add separate list to track pending deletes for TSQL ENR entries.

Signed-off-by: Jason Teng <[email protected]>
roshan0708 pushed a commit to amazon-aurora/postgresql_modified_for_babelfish that referenced this pull request Oct 18, 2024
…ope. (babelfish-for-postgresql#450)

Add separate list to track pending deletes for TSQL ENR entries.

Signed-off-by: Jason Teng <[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.

3 participants