-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ tde_is_encryption_required(TDESMgrRelation tdereln, ForkNumber forknum) | |
} | ||
|
||
static RelKeyData * | ||
tde_smgr_get_key(SMgrRelation reln, RelFileLocator* old_locator) | ||
tde_smgr_get_key(SMgrRelation reln, RelFileLocator* old_locator, bool createIfNone) | ||
{ | ||
TdeCreateEvent *event; | ||
RelKeyData *rkd; | ||
|
@@ -68,19 +68,23 @@ tde_smgr_get_key(SMgrRelation reln, RelFileLocator* old_locator) | |
return rkd; | ||
} | ||
|
||
if (!createIfNone) | ||
return NULL; | ||
|
||
/* 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 commentThe reason will be displayed to describe this comment to others. Learn more. accidental whitespace change? |
||
{ | ||
return pg_tde_create_smgr_key(&reln->smgr_rlocator.locator); | ||
} | ||
|
||
/* if this is a CREATE INDEX, we have to load the key based on the table */ | ||
if (event->encryptMode == true && event->eventType == TDE_INDEX_CREATE_EVENT) | ||
{ | ||
/* For now keep it simple and create separate key for indexes */ | ||
/* | ||
/* | ||
* For now keep it simple and create separate key for indexes. | ||
* | ||
* Later we might modify the map infrastructure to support the same | ||
* keys | ||
* keys. | ||
*/ | ||
return pg_tde_create_smgr_key(&reln->smgr_rlocator.locator); | ||
} | ||
|
@@ -226,21 +230,23 @@ tde_mdreadv(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, | |
static void | ||
tde_mdcreate(RelFileLocator relold, SMgrRelation reln, ForkNumber forknum, bool isRedo) | ||
{ | ||
RelKeyData* key; | ||
TDESMgrRelation tdereln = (TDESMgrRelation) reln; | ||
|
||
/* | ||
* This is the only function that gets called during actual CREATE | ||
* TABLE/INDEX (EVENT TRIGGER) | ||
/* | ||
* We have to ensure that all direcories are created before moving on with | ||
* the possible key createion. This is crucial for non-default tablespaces. | ||
*/ | ||
/* so we create the key here by loading it */ | ||
|
||
mdcreate(relold, reln, forknum, isRedo); | ||
|
||
/* | ||
* This is the only function that gets called during actual CREATE | ||
* TABLE/INDEX (EVENT TRIGGER) so we create the key here by loading it. | ||
* Later calls then decide to encrypt or not based on the existence of the | ||
* key | ||
* key. | ||
* So we create the key here by loading it. | ||
*/ | ||
RelKeyData *key = tde_smgr_get_key(reln, &relold); | ||
key = tde_smgr_get_key(reln, &relold, true); | ||
|
||
if (key) | ||
{ | ||
|
@@ -254,14 +260,20 @@ tde_mdcreate(RelFileLocator relold, SMgrRelation reln, ForkNumber forknum, bool | |
} | ||
|
||
/* | ||
* mdopen() -- Initialize newly-opened relation. | ||
* tde_mdopen() -- Initialize newly-opened relation. | ||
*/ | ||
static void | ||
tde_mdopen(SMgrRelation reln) | ||
{ | ||
TDESMgrRelation tdereln = (TDESMgrRelation) reln; | ||
RelKeyData *key = tde_smgr_get_key(reln, NULL); | ||
|
||
/* | ||
* tde_mdopen() is called before tde_mdcreate() during CREATE. And in case | ||
* 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 commentThe reason will be displayed to describe this comment to others. Learn more. But we will emit warnings even with |
||
|
||
if (key) | ||
{ | ||
tdereln->encrypted_relation = true; | ||
|
@@ -274,6 +286,18 @@ tde_mdopen(SMgrRelation reln) | |
mdopen(reln); | ||
} | ||
|
||
static void | ||
tde_mdunlink(RelFileLocatorBackend rlocator, ForkNumber forknum, bool isRedo) | ||
{ | ||
/* | ||
* tde_mdunlink() being called after the transaction is commited, so we | ||
* cannot have any errors down the call stack. | ||
*/ | ||
pg_tde_clean_map_data(&rlocator.locator, false); | ||
|
||
mdunlink(rlocator, forknum, isRedo); | ||
} | ||
|
||
static SMgrId tde_smgr_id; | ||
static const struct f_smgr tde_smgr = { | ||
.name = "tde", | ||
|
@@ -283,7 +307,7 @@ static const struct f_smgr tde_smgr = { | |
.smgr_close = mdclose, | ||
.smgr_create = tde_mdcreate, | ||
.smgr_exists = mdexists, | ||
.smgr_unlink = mdunlink, | ||
.smgr_unlink = tde_mdunlink, | ||
.smgr_extend = tde_mdextend, | ||
.smgr_zeroextend = mdzeroextend, | ||
.smgr_prefetch = mdprefetch, | ||
|
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 forSET TABLESPACE
, not the access method name, making the next access method name checks incorrect. In case ofSET TABLESPACE
, we should open the table instead and check the current access method.Also, the TODO comment below is outdated with these changes.