Skip to content

Move SMGR code out of pg_tde_tdemap.c #361

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

Merged
merged 3 commits into from
May 28, 2025

Conversation

jeltz
Copy link
Collaborator

@jeltz jeltz commented May 23, 2025

Especially all code related to the keys of temporary tables did not belong in the TDE map code and fit better in the SMGR code.

Additionally we speed up pg_tde_is_encrypted() by relying on the SMGR to cache the relations. This might in some cases lead to blow up of the SMGR relation cache if you query every relation in the database but given the small size I am not overly worried.

Also removes an optimization where we skipped trying to look for a key during SMGR open for catalog tables. It made the code harder to read and I do not think it was a very useful optimization.

So what do you think about the removed catalog optimization and the potential cache issue? Also I am not entirely happy with the naming of some of the functions.

@jeltz jeltz requested review from dutow and dAdAbird as code owners May 23, 2025 16:58
@jeltz jeltz force-pushed the tde/smgr-refactor branch 10 times, most recently from cc70455 to 4a15334 Compare May 23, 2025 18:20
Copy link
Collaborator

@AndersAstrand AndersAstrand left a comment

Choose a reason for hiding this comment

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

This looks great in general! I have some minor questions about things that aren't entirely clear to me.

@@ -962,14 +908,56 @@ pg_tde_has_smgr_key(RelFileLocator rel)
}

/*
* Returns TDE key for a given relation.
* Reads the key of the required relation. It identifies its map entry and then simply
Copy link
Collaborator

Choose a reason for hiding this comment

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

map entry and keydata file are no longer separate things

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

{
TDESMgrRelation *tdereln = (TDESMgrRelation *) reln;

if (reln->smgr_which != OurSMgrId)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is the first time we actually use our SMgrId afaics. Should we use it more? Why haven't we needed it before?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because the other calls go through the smgr*() functions while this one does not.

@@ -328,7 +417,67 @@ RegisterStorageMgr(void)
{
if (storage_manager_id != MdSMgrId)
elog(FATAL, "Another storage manager was loaded before pg_tde. Multiple storage managers is unsupported.");
storage_manager_id = smgr_register(&tde_smgr, sizeof(TDESMgrRelation));
storage_manager_id = OurSMgrId = smgr_register(&tde_smgr, sizeof(TDESMgrRelation));
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not a big fan of chained assignments like this. I think they're always harder than necessary to read.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

@jeltz jeltz force-pushed the tde/smgr-refactor branch 2 times, most recently from be58a0a to 187449b Compare May 27, 2025 16:23
Copy link
Collaborator

@dutow dutow left a comment

Choose a reason for hiding this comment

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

I'm not 100% sure that the smgr source is a better place for the temporary files. Similarly to the tdemap source, it doesn't really belong there.

But I also don't have a better idea, other than moving it into a completely new source file.

@jeltz
Copy link
Collaborator Author

jeltz commented May 28, 2025

Yeah, maybe it should be in a separate file. I did consider that but will merge this as-is.

jeltz added 3 commits May 28, 2025 03:57
Since we rely on the SMGR relation cache for fast key lookup when
opening a SMGR relation and that the catalog should be open basically
all the time this optimization adds little value and only complicates
the code.
Especially all code realted to the keys of temporary tables did not
belong in the TDE map code and fit better in the SMGR code.

Additionally we speed up pg_tde_is_encrypted() by relying on the SMGR to
cache the relations. This might in some cases lead to blow up of the
SMGR relation cache if you query every relation in the database but
given the small size I am not overly worried.
Since the caller of the function became a very thin wrapper having both
functions no longer make any sense.
@jeltz jeltz force-pushed the tde/smgr-refactor branch from 187449b to 68b9f96 Compare May 28, 2025 02:07
Copy link
Collaborator

@AndersAstrand AndersAstrand left a comment

Choose a reason for hiding this comment

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

There is a typo in the second commit message. realted instead of related

@jeltz jeltz merged commit 69f7a38 into percona:TDE_REL_17_STABLE May 28, 2025
16 checks passed
@jeltz jeltz deleted the tde/smgr-refactor branch June 4, 2025 10:24
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