@@ -102,23 +102,20 @@ tde_smgr_create_key_redo(const RelFileLocator *rlocator)
102
102
{
103
103
InternalKey key ;
104
104
105
- if (pg_tde_has_smgr_key (* rlocator ))
106
- return ;
105
+ pg_tde_free_key_map_entry (* rlocator );
107
106
108
107
pg_tde_generate_internal_key (& key , TDE_KEY_TYPE_SMGR );
109
108
110
109
pg_tde_save_smgr_key (* rlocator , & key );
111
110
}
112
111
113
112
static void
114
- tde_smgr_delete_key (const RelFileLocatorBackend * smgr_rlocator )
113
+ tde_smgr_log_delete_key (const RelFileLocatorBackend * smgr_rlocator )
115
114
{
116
115
XLogRelKey xlrec = {
117
116
.rlocator = smgr_rlocator -> locator ,
118
117
};
119
118
120
- pg_tde_free_key_map_entry (smgr_rlocator -> locator );
121
-
122
119
XLogBeginInsert ();
123
120
XLogRegisterData ((char * ) & xlrec , sizeof (xlrec ));
124
121
XLogInsert (RM_TDERMGR_ID , XLOG_TDE_DELETE_RELATION_KEY );
@@ -380,15 +377,15 @@ tde_mdcreate(RelFileLocator relold, SMgrRelation reln, ForkNumber forknum, bool
380
377
* If we have a key for this relation already, we need to remove it. This
381
378
* can happen if OID is re-used after a crash left a key for a
382
379
* non-existing relation in the key file.
383
- *
384
- * If we're in redo, a separate WAL record will make sure the key is
385
- * removed.
386
380
*/
387
381
if (!RelFileLocatorBackendIsTemp (reln -> smgr_rlocator ))
388
- tde_smgr_delete_key ( & reln -> smgr_rlocator );
382
+ pg_tde_free_key_map_entry ( reln -> smgr_rlocator . locator );
389
383
390
384
if (!tde_smgr_should_encrypt (& reln -> smgr_rlocator , & relold ))
391
385
{
386
+ if (!RelFileLocatorBackendIsTemp (reln -> smgr_rlocator ))
387
+ tde_smgr_log_delete_key (& reln -> smgr_rlocator );
388
+
392
389
tdereln -> encryption_status = RELATION_NOT_ENCRYPTED ;
393
390
return ;
394
391
}
0 commit comments