-
Notifications
You must be signed in to change notification settings - Fork 20
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
Conversation
e84f04e
to
479a9b4
Compare
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.
479a9b4
to
0d646b0
Compare
@@ -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) && |
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.
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) |
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.
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); |
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.
But we will emit warnings even with false
, that could be confusing.
Will fix in https://perconadev.atlassian.net/browse/PG-1209 |
tde_mdopen()
is called beforetde_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.*.tde
files. And remove those files physically if there is nothing (tde related) left in the table space. OtherwiseDROP 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