Skip to content

Commit 108aac3

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 167aef2 commit 108aac3

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

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,22 +156,25 @@ TDEXLogEncryptStateSize(void)
156156
void
157157
TDEXLogShmemInit(void)
158158
{
159-
bool foundBuf;
159+
bool found;
160160

161161
EncryptionState = (EncryptionStateData *)
162162
ShmemInitStruct("TDE XLog Encryption State",
163163
TDEXLogEncryptStateSize(),
164-
&foundBuf);
164+
&found);
165165

166-
memset(EncryptionState, 0, sizeof(EncryptionStateData));
166+
if (!found)
167+
{
168+
memset(EncryptionState, 0, sizeof(EncryptionStateData));
167169

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

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

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

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

177180
#else /* !FRONTEND */

0 commit comments

Comments
 (0)