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 CREATE/DROP tde_heap in non-default tablespace #329

Closed
wants to merge 3 commits into from

Conversation

dAdAbird
Copy link
Member

@dAdAbird dAdAbird commented Nov 6, 2024

  1. tde_mdopen() is called before tde_mdcreate() during CREATE. In the case of non-default tablespace, the creation of the key will fail in tde_mdopen(), as the storage is yet to be created (namely database dir). This doesn't happen with default table space because the db dir had been already created before the CREATE TABLE call.
  2. When dropping/moving relations in non-default table space we also have clean-up *.tde files. And remove those files physically if there is nothing (tde related) left in the table space. Otherwise DROP TABLESPACE will fail.
    One caveat is that tde_mdunlink() is called after the transaction is commited, so we must not have any errors down the call stack. For that, we need related tdemap* functions to have an option of not failing on error.

Fixes PG-1196

@dAdAbird dAdAbird changed the title Fix CREATE tde_heap in non-default tablespace Fix CREATE/DROP tde_heap in non-default tablespace Nov 13, 2024
@dAdAbird dAdAbird marked this pull request as ready for review November 13, 2024 16:43
@dAdAbird dAdAbird requested a review from dutow as a code owner November 13, 2024 16:43
@dAdAbird dAdAbird requested review from codeforall and dutow and removed request for dutow November 13, 2024 16:43
tde_mdopen() is called before tde_mdcreate() during CREATE. And in case
of non-default tablespace, the creation of the key will fail in
tde_mdopen(), as the storage is yet to be created (namely database dir). This
doesn't happen with default table space because the db dir had been already
created before the CREATE TABLE call.
We must clean up *.tde files in the non-default tablespace after
dropping/moving tde_heap relations. There is no way for `tde_mdunlink`
to determine the relation type so we check any (tde and non-tde)
relations.
@@ -141,7 +141,7 @@ pg_tde_ddl_command_start_capture(PG_FUNCTION_ARGS)
foreach(lcmd, stmt->cmds)
{
AlterTableCmd *cmd = (AlterTableCmd *) lfirst(lcmd);
if (cmd->subtype == AT_SetAccessMethod &&
if ((cmd->subtype == AT_SetAccessMethod || cmd->subtype == AT_SetTableSpace) &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you sure about this? I think name will refer to the tablespace name for SET TABLESPACE, not the access method name, making the next access method name checks incorrect. In case of SET TABLESPACE, we should open the table instead and check the current access method.

Also, the TODO comment below is outdated with these changes.

/* if this is a CREATE TABLE, we have to generate the key */
if (event->encryptMode == true && event->eventType == TDE_TABLE_CREATE_EVENT)
if(event->encryptMode == true && event->eventType == TDE_TABLE_CREATE_EVENT)
Copy link
Collaborator

Choose a reason for hiding this comment

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

accidental whitespace change?

* of non-default tablespace, the creation of the key will fail here, as
* the storage is yet to be created.
*/
RelKeyData *key = tde_smgr_get_key(reln, NULL, false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

But we will emit warnings even with false, that could be confusing.

@dAdAbird
Copy link
Member Author

@dAdAbird dAdAbird closed this Nov 15, 2024
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.

2 participants