Skip to content

Commit e257f22

Browse files
committed
Only initialize WAL shmem once in EXEC_BACKEND builds
This only affects EXEC_BACKEND/Windows builds which we currently do not support, but we fix this anyway to make the code more consistent and easier to understand since we try to care about this in other places. In the future we may want to add CI and proper support for EXEC_BACKEND builds. The issue was originally found by Zsolt Parragi.
1 parent 8b3289b commit e257f22

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

contrib/pg_tde/src/access/pg_tde_xlog_smgr.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,24 +156,27 @@ TDEXLogEncryptStateSize(void)
156156
void
157157
TDEXLogShmemInit(void)
158158
{
159-
bool foundBuf;
159+
bool found;
160160

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

163163
EncryptionState = (EncryptionStateData *)
164164
ShmemInitStruct("TDE XLog Encryption State",
165165
TDEXLogEncryptStateSize(),
166-
&foundBuf);
166+
&found);
167167

168-
memset(EncryptionState, 0, sizeof(EncryptionStateData));
168+
if (!found)
169+
{
170+
memset(EncryptionState, 0, sizeof(EncryptionStateData));
169171

170-
EncryptionBuf = (char *) TYPEALIGN(PG_IO_ALIGN_SIZE, ((char *) EncryptionState) + sizeof(EncryptionStateData));
172+
pg_atomic_init_u64(&EncryptionState->enc_key_lsn, 0);
171173

172-
Assert((char *) EncryptionState + TDEXLogEncryptStateSize() >= (char *) EncryptionBuf + TDEXLogEncryptBuffSize());
174+
elog(DEBUG1, "pg_tde: initialized encryption buffer %lu bytes", TDEXLogEncryptStateSize());
175+
}
173176

174-
pg_atomic_init_u64(&EncryptionState->enc_key_lsn, 0);
177+
EncryptionBuf = (char *) TYPEALIGN(PG_IO_ALIGN_SIZE, ((char *) EncryptionState) + sizeof(EncryptionStateData));
175178

176-
elog(DEBUG1, "pg_tde: initialized encryption buffer %lu bytes", TDEXLogEncryptStateSize());
179+
Assert((char *) EncryptionState + TDEXLogEncryptStateSize() >= (char *) EncryptionBuf + TDEXLogEncryptBuffSize());
177180
}
178181

179182
#else /* !FRONTEND */

0 commit comments

Comments
 (0)