mirror of
https://github.com/postgres/postgres.git
synced 2025-10-08 00:03:59 -04:00
Revert recent change to RequestNamedLWLockTranche().
Commit 38b602b028 modified this function to allocate enough space for MAX_NAMED_TRANCHES (256) requests, which is likely far more than most clusters need. This commit reverts that change so that it first allocates enough space for only 16 requests and resizes the array when necessary. While at it, remove the check for too many tranches from this function. We can now rely on InitializeLWLocks() to do that check via its calls to LWLockNewTrancheId() for the named tranches. Reviewed-by: Sami Imseih <samimseih@gmail.com> Discussion: https://postgr.es/m/aLmzwC2dRbqk14y6%40nathan
This commit is contained in:
parent
f0478149c3
commit
d814d7fc3d
@ -610,6 +610,7 @@ void
|
|||||||
RequestNamedLWLockTranche(const char *tranche_name, int num_lwlocks)
|
RequestNamedLWLockTranche(const char *tranche_name, int num_lwlocks)
|
||||||
{
|
{
|
||||||
NamedLWLockTrancheRequest *request;
|
NamedLWLockTrancheRequest *request;
|
||||||
|
static int NamedLWLockTrancheRequestsAllocated;
|
||||||
|
|
||||||
if (!process_shmem_requests_in_progress)
|
if (!process_shmem_requests_in_progress)
|
||||||
elog(FATAL, "cannot request additional LWLocks outside shmem_request_hook");
|
elog(FATAL, "cannot request additional LWLocks outside shmem_request_hook");
|
||||||
@ -628,17 +629,22 @@ RequestNamedLWLockTranche(const char *tranche_name, int num_lwlocks)
|
|||||||
|
|
||||||
if (NamedLWLockTrancheRequestArray == NULL)
|
if (NamedLWLockTrancheRequestArray == NULL)
|
||||||
{
|
{
|
||||||
|
NamedLWLockTrancheRequestsAllocated = 16;
|
||||||
NamedLWLockTrancheRequestArray = (NamedLWLockTrancheRequest *)
|
NamedLWLockTrancheRequestArray = (NamedLWLockTrancheRequest *)
|
||||||
MemoryContextAlloc(TopMemoryContext,
|
MemoryContextAlloc(TopMemoryContext,
|
||||||
MAX_NAMED_TRANCHES
|
NamedLWLockTrancheRequestsAllocated
|
||||||
* sizeof(NamedLWLockTrancheRequest));
|
* sizeof(NamedLWLockTrancheRequest));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NamedLWLockTrancheRequests >= MAX_NAMED_TRANCHES)
|
if (NamedLWLockTrancheRequests >= NamedLWLockTrancheRequestsAllocated)
|
||||||
ereport(ERROR,
|
{
|
||||||
(errmsg("maximum number of tranches already registered"),
|
int i = pg_nextpower2_32(NamedLWLockTrancheRequests + 1);
|
||||||
errdetail("No more than %d tranches may be registered.",
|
|
||||||
MAX_NAMED_TRANCHES)));
|
NamedLWLockTrancheRequestArray = (NamedLWLockTrancheRequest *)
|
||||||
|
repalloc(NamedLWLockTrancheRequestArray,
|
||||||
|
i * sizeof(NamedLWLockTrancheRequest));
|
||||||
|
NamedLWLockTrancheRequestsAllocated = i;
|
||||||
|
}
|
||||||
|
|
||||||
request = &NamedLWLockTrancheRequestArray[NamedLWLockTrancheRequests];
|
request = &NamedLWLockTrancheRequestArray[NamedLWLockTrancheRequests];
|
||||||
strlcpy(request->tranche_name, tranche_name, NAMEDATALEN);
|
strlcpy(request->tranche_name, tranche_name, NAMEDATALEN);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user