Skip to content

Commit 6db732c

Browse files
author
Commitfest Bot
committed
[CF 5940] v20 - Improve LWLock tranche name visibility across backends
This branch was automatically generated by a robot using patches from an email thread registered at: https://commitfest.postgresql.org/patch/5940 The branch will be overwritten each time a new patch version is posted to the thread, and also periodically to check for bitrot caused by changes on the master branch. Patch(es): https://www.postgresql.org/message-id/aLMHVosexT5D-Ybz@nathan Author(s): Sami Imseih
2 parents 36aed19 + eec6e07 commit 6db732c

File tree

20 files changed

+535
-174
lines changed

20 files changed

+535
-174
lines changed

contrib/pg_prewarm/autoprewarm.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ apw_init_state(void *ptr)
864864
{
865865
AutoPrewarmSharedState *state = (AutoPrewarmSharedState *) ptr;
866866

867-
LWLockInitialize(&state->lock, LWLockNewTrancheId());
867+
LWLockInitialize(&state->lock, LWLockNewTrancheId("autoprewarm"));
868868
state->bgworker_pid = InvalidPid;
869869
state->pid_using_dumpfile = InvalidPid;
870870
}
@@ -883,7 +883,6 @@ apw_init_shmem(void)
883883
sizeof(AutoPrewarmSharedState),
884884
apw_init_state,
885885
&found);
886-
LWLockRegisterTranche(apw_state->lock.tranche, "autoprewarm");
887886

888887
return found;
889888
}

doc/src/sgml/xfunc.sgml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3759,7 +3759,7 @@ LWLockPadded *GetNamedLWLockTranche(const char *tranche_name)
37593759
<literal>shmem_request_hook</literal>. To do so, first allocate a
37603760
<literal>tranche_id</literal> by calling:
37613761
<programlisting>
3762-
int LWLockNewTrancheId(void)
3762+
int LWLockNewTrancheId(const char *name)
37633763
</programlisting>
37643764
Next, initialize each LWLock, passing the new
37653765
<literal>tranche_id</literal> as an argument:
@@ -3777,17 +3777,8 @@ void LWLockInitialize(LWLock *lock, int tranche_id)
37773777
</para>
37783778

37793779
<para>
3780-
Finally, each backend using the <literal>tranche_id</literal> should
3781-
associate it with a <literal>tranche_name</literal> by calling:
3782-
<programlisting>
3783-
void LWLockRegisterTranche(int tranche_id, const char *tranche_name)
3784-
</programlisting>
3785-
</para>
3786-
3787-
<para>
3788-
A complete usage example of <function>LWLockNewTrancheId</function>,
3789-
<function>LWLockInitialize</function>, and
3790-
<function>LWLockRegisterTranche</function> can be found in
3780+
A complete usage example of <function>LWLockNewTrancheId</function> and
3781+
<function>LWLockInitialize</function> can be found in
37913782
<filename>contrib/pg_prewarm/autoprewarm.c</filename> in the
37923783
<productname>PostgreSQL</productname> source tree.
37933784
</para>

src/backend/postmaster/launch_backend.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ typedef struct
101101
struct InjectionPointsCtl *ActiveInjectionPoints;
102102
#endif
103103
int NamedLWLockTrancheRequests;
104-
NamedLWLockTranche *NamedLWLockTrancheArray;
104+
char **NamedLWLockTrancheNames;
105105
int *LWLockCounter;
106106
LWLockPadded *MainLWLockArray;
107107
slock_t *ProcStructLock;
@@ -761,7 +761,7 @@ save_backend_variables(BackendParameters *param,
761761
#endif
762762

763763
param->NamedLWLockTrancheRequests = NamedLWLockTrancheRequests;
764-
param->NamedLWLockTrancheArray = NamedLWLockTrancheArray;
764+
param->NamedLWLockTrancheNames = NamedLWLockTrancheNames;
765765
param->LWLockCounter = LWLockCounter;
766766
param->MainLWLockArray = MainLWLockArray;
767767
param->ProcStructLock = ProcStructLock;
@@ -1022,7 +1022,7 @@ restore_backend_variables(BackendParameters *param)
10221022
#endif
10231023

10241024
NamedLWLockTrancheRequests = param->NamedLWLockTrancheRequests;
1025-
NamedLWLockTrancheArray = param->NamedLWLockTrancheArray;
1025+
NamedLWLockTrancheNames = param->NamedLWLockTrancheNames;
10261026
LWLockCounter = param->LWLockCounter;
10271027
MainLWLockArray = param->MainLWLockArray;
10281028
ProcStructLock = param->ProcStructLock;

src/backend/storage/ipc/dsm_registry.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,7 @@ GetNamedDSA(const char *name, bool *found)
299299
entry->type = DSMR_ENTRY_TYPE_DSA;
300300

301301
/* Initialize the LWLock tranche for the DSA. */
302-
state->tranche = LWLockNewTrancheId();
303-
LWLockRegisterTranche(state->tranche, name);
302+
state->tranche = LWLockNewTrancheId(name);
304303

305304
/* Initialize the DSA. */
306305
ret = dsa_create(state->tranche);
@@ -321,9 +320,6 @@ GetNamedDSA(const char *name, bool *found)
321320
ereport(ERROR,
322321
(errmsg("requested DSA already attached to current process")));
323322

324-
/* Initialize existing LWLock tranche for the DSA. */
325-
LWLockRegisterTranche(state->tranche, name);
326-
327323
/* Attach to existing DSA. */
328324
ret = dsa_attach(state->handle);
329325
dsa_pin_mapping(ret);
@@ -378,8 +374,7 @@ GetNamedDSHash(const char *name, const dshash_parameters *params, bool *found)
378374
entry->type = DSMR_ENTRY_TYPE_DSH;
379375

380376
/* Initialize the LWLock tranche for the hash table. */
381-
dsh_state->tranche = LWLockNewTrancheId();
382-
LWLockRegisterTranche(dsh_state->tranche, name);
377+
dsh_state->tranche = LWLockNewTrancheId(name);
383378

384379
/* Initialize the DSA for the hash table. */
385380
dsa = dsa_create(dsh_state->tranche);
@@ -409,9 +404,6 @@ GetNamedDSHash(const char *name, const dshash_parameters *params, bool *found)
409404
ereport(ERROR,
410405
(errmsg("requested DSHash already attached to current process")));
411406

412-
/* Initialize existing LWLock tranche for the hash table. */
413-
LWLockRegisterTranche(dsh_state->tranche, name);
414-
415407
/* Attach to existing DSA for the hash table. */
416408
dsa = dsa_attach(dsh_state->dsa_handle);
417409
dsa_pin_mapping(dsa);

0 commit comments

Comments
 (0)