Hold required lock when initializing shmem

According to the documentation, each backend is supposed to hold
AddinShmemInitLock when calling ShmemInitStruct. We only did that for
half of our calls before this patch.
pull/238/head
Anders Åstrand 3 weeks ago committed by AndersAstrand
parent ff8a389bfd
commit b709662c25
  1. 2
      contrib/pg_tde/src/access/pg_tde_xlog_smgr.c
  2. 4
      contrib/pg_tde/src/catalog/tde_principal_key.c
  3. 4
      contrib/pg_tde/src/pg_tde.c

@ -158,6 +158,8 @@ TDEXLogShmemInit(void)
{ {
bool foundBuf; bool foundBuf;
Assert(LWLockHeldByMeInMode(AddinShmemInitLock, LW_EXCLUSIVE));
EncryptionState = (EncryptionStateData *) EncryptionState = (EncryptionStateData *)
ShmemInitStruct("TDE XLog Encryption State", ShmemInitStruct("TDE XLog Encryption State",
TDEXLogEncryptStateSize(), TDEXLogEncryptStateSize(),

@ -127,7 +127,7 @@ PrincipalKeyShmemInit(void)
char *free_start; char *free_start;
Size required_shmem_size = PrincipalKeyShmemSize(); Size required_shmem_size = PrincipalKeyShmemSize();
LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE); Assert(LWLockHeldByMeInMode(AddinShmemInitLock, LW_EXCLUSIVE));
/* Create or attach to the shared memory state */ /* Create or attach to the shared memory state */
ereport(NOTICE, errmsg("PrincipalKeyShmemInit: requested %ld bytes", required_shmem_size)); ereport(NOTICE, errmsg("PrincipalKeyShmemInit: requested %ld bytes", required_shmem_size));
@ -175,8 +175,6 @@ PrincipalKeyShmemInit(void)
dshash_detach(dsh); dshash_detach(dsh);
} }
LWLockRelease(AddinShmemInitLock);
} }
/* /*

@ -64,11 +64,15 @@ tde_shmem_startup(void)
if (prev_shmem_startup_hook) if (prev_shmem_startup_hook)
prev_shmem_startup_hook(); prev_shmem_startup_hook();
LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE);
KeyProviderShmemInit(); KeyProviderShmemInit();
PrincipalKeyShmemInit(); PrincipalKeyShmemInit();
TDEXLogShmemInit(); TDEXLogShmemInit();
TDEXLogSmgrInit(); TDEXLogSmgrInit();
TDEXLogSmgrInitWrite(EncryptXLog); TDEXLogSmgrInitWrite(EncryptXLog);
LWLockRelease(AddinShmemInitLock);
} }
void void

Loading…
Cancel
Save