Skip to content

Commit 767a59e

Browse files
committed
PG-1866 Reset WAL key cache on shmem init
It seems like there are cases when the postmaster have "restarted" after a backend crash where the wal cache inherited from the postmaster is wrong. I'm not at all sure exactly how and why this happens, but this patch fixes a bug with this and allows recovery/013_crash_restart to pass with WAL encryption enabled.
1 parent b709662 commit 767a59e

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

contrib/pg_tde/src/access/pg_tde_xlog_keys.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,23 @@ get_wal_key_file_path(void)
7272
return wal_key_file_path;
7373
}
7474

75+
void
76+
pg_tde_free_wal_key_cache(void)
77+
{
78+
WALKeyCacheRec *rec = tde_wal_key_cache;
79+
80+
while (rec != NULL)
81+
{
82+
WALKeyCacheRec *next = rec->next;
83+
84+
pfree(rec);
85+
rec = next;
86+
}
87+
88+
tde_wal_key_cache = NULL;
89+
tde_wal_key_last_rec = NULL;
90+
}
91+
7592
void
7693
pg_tde_wal_last_key_set_location(WalLocation loc)
7794
{

contrib/pg_tde/src/access/pg_tde_xlog_smgr.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ TDEXLogShmemInit(void)
160160

161161
Assert(LWLockHeldByMeInMode(AddinShmemInitLock, LW_EXCLUSIVE));
162162

163+
pg_tde_free_wal_key_cache();
164+
163165
EncryptionState = (EncryptionStateData *)
164166
ShmemInitStruct("TDE XLog Encryption State",
165167
TDEXLogEncryptStateSize(),

contrib/pg_tde/src/include/access/pg_tde_xlog_keys.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ extern int pg_tde_count_wal_keys_in_file(void);
7474
extern void pg_tde_create_wal_key(WalEncryptionKey *rel_key_data, WalEncryptionKeyType entry_type);
7575
extern void pg_tde_delete_server_key(void);
7676
extern WALKeyCacheRec *pg_tde_fetch_wal_keys(WalLocation start);
77+
extern void pg_tde_free_wal_key_cache(void);
7778
extern WALKeyCacheRec *pg_tde_get_last_wal_key(void);
7879
extern TDESignedPrincipalKeyInfo *pg_tde_get_server_key_info(void);
7980
extern WALKeyCacheRec *pg_tde_get_wal_cache_keys(void);

0 commit comments

Comments
 (0)