Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3fed417

Browse files
committed
Provide a way to predefine LWLock tranche IDs.
It's a bit cumbersome to use LWLockNewTrancheId(), because the returnedvalue needs to be shared between backends so that each backend can callLWLockRegisterTranche() with the correct ID. So, for built-in tranches,use a hard-coded value instead.This is motivated by an upcoming patch adding further built-in tranches.Andres Freund and Robert Haas
1 parent43cd468 commit3fed417

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

‎src/backend/access/transam/xlog.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,6 @@ typedef struct XLogCtlInsert
512512
*/
513513
WALInsertLockPadded*WALInsertLocks;
514514
LWLockTrancheWALInsertLockTranche;
515-
intWALInsertLockTrancheId;
516515
}XLogCtlInsert;
517516

518517
/*
@@ -4653,7 +4652,7 @@ XLOGShmemInit(void)
46534652

46544653
/* Initialize local copy of WALInsertLocks and register the tranche */
46554654
WALInsertLocks=XLogCtl->Insert.WALInsertLocks;
4656-
LWLockRegisterTranche(XLogCtl->Insert.WALInsertLockTrancheId,
4655+
LWLockRegisterTranche(LWTRANCHE_WAL_INSERT,
46574656
&XLogCtl->Insert.WALInsertLockTranche);
46584657
return;
46594658
}
@@ -4677,17 +4676,14 @@ XLOGShmemInit(void)
46774676
(WALInsertLockPadded*)allocptr;
46784677
allocptr+=sizeof(WALInsertLockPadded)*NUM_XLOGINSERT_LOCKS;
46794678

4680-
XLogCtl->Insert.WALInsertLockTrancheId=LWLockNewTrancheId();
4681-
46824679
XLogCtl->Insert.WALInsertLockTranche.name="WALInsertLocks";
46834680
XLogCtl->Insert.WALInsertLockTranche.array_base=WALInsertLocks;
46844681
XLogCtl->Insert.WALInsertLockTranche.array_stride=sizeof(WALInsertLockPadded);
46854682

4686-
LWLockRegisterTranche(XLogCtl->Insert.WALInsertLockTrancheId,&XLogCtl->Insert.WALInsertLockTranche);
4683+
LWLockRegisterTranche(LWTRANCHE_WAL_INSERT,&XLogCtl->Insert.WALInsertLockTranche);
46874684
for (i=0;i<NUM_XLOGINSERT_LOCKS;i++)
46884685
{
4689-
LWLockInitialize(&WALInsertLocks[i].l.lock,
4690-
XLogCtl->Insert.WALInsertLockTrancheId);
4686+
LWLockInitialize(&WALInsertLocks[i].l.lock,LWTRANCHE_WAL_INSERT);
46914687
WALInsertLocks[i].l.insertingAt=InvalidXLogRecPtr;
46924688
}
46934689

‎src/backend/storage/lmgr/lwlock.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ CreateLWLocks(void)
445445

446446
/* Initialize all LWLocks in main array */
447447
for (id=0,lock=MainLWLockArray;id<numLocks;id++,lock++)
448-
LWLockInitialize(&lock->lock,0);
448+
LWLockInitialize(&lock->lock,LWTRANCHE_MAIN);
449449

450450
/*
451451
* Initialize the dynamic-allocation counters, which are stored just
@@ -457,7 +457,7 @@ CreateLWLocks(void)
457457
LWLockCounter= (int*) ((char*)MainLWLockArray-3*sizeof(int));
458458
LWLockCounter[0]=NUM_FIXED_LWLOCKS;
459459
LWLockCounter[1]=numLocks;
460-
LWLockCounter[2]=1;/* 0 is the main array */
460+
LWLockCounter[2]=LWTRANCHE_FIRST_USER_DEFINED;
461461
}
462462

463463
if (LWLockTrancheArray==NULL)
@@ -466,12 +466,13 @@ CreateLWLocks(void)
466466
LWLockTrancheArray= (LWLockTranche**)
467467
MemoryContextAlloc(TopMemoryContext,
468468
LWLockTranchesAllocated*sizeof(LWLockTranche*));
469+
Assert(LWLockTranchesAllocated >=LWTRANCHE_FIRST_USER_DEFINED);
469470
}
470471

471472
MainLWLockTranche.name="main";
472473
MainLWLockTranche.array_base=MainLWLockArray;
473474
MainLWLockTranche.array_stride=sizeof(LWLockPadded);
474-
LWLockRegisterTranche(0,&MainLWLockTranche);
475+
LWLockRegisterTranche(LWTRANCHE_MAIN,&MainLWLockTranche);
475476
}
476477

477478
/*

‎src/include/storage/lwlock.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,17 @@ extern intLWLockNewTrancheId(void);
176176
externvoidLWLockRegisterTranche(inttranche_id,LWLockTranche*tranche);
177177
externvoidLWLockInitialize(LWLock*lock,inttranche_id);
178178

179+
/*
180+
* We reserve a few predefined tranche IDs. A call to LWLockNewTrancheId
181+
* will never return a value less than LWTRANCHE_FIRST_USER_DEFINED.
182+
*/
183+
typedefenumBuiltinTrancheIds
184+
{
185+
LWTRANCHE_MAIN,
186+
LWTRANCHE_WAL_INSERT,
187+
LWTRANCHE_FIRST_USER_DEFINED
188+
}BuiltinTrancheIds;
189+
179190
/*
180191
* Prior to PostgreSQL 9.4, we used an enum type called LWLockId to refer
181192
* to LWLocks. New code should instead use LWLock *. However, for the

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp