-
Notifications
You must be signed in to change notification settings - Fork 10
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
Conversation
cc70455
to
4a15334
Compare
There was a problem hiding this 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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
be58a0a
to
187449b
Compare
There was a problem hiding this 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.
Yeah, maybe it should be in a separate file. I did consider that but will merge this as-is. |
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.
There was a problem hiding this 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
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.