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

Commit4eda0a6

Browse files
committed
Don't include low level locking code from frontend code.
Some frontend code like e.g. pg_xlogdump or pg_resetxlog, has to usebackend headers. Unfortunately until now that code includes most of thelocking code. It's generally not nice to expose such low level details,butde6fd1c made that a hard problem. We fall back to defining'inline' away if the compiler doesn't support it - that can cause linkererrors like on buildfarm animal pademelon if a inline functionreferences backend only code.To fix that problem separate definitions from lock.h that are requiredfrom frontend code into lockdefs.h and use it in the relevantplaces. I've only removed the minimal amount of necessary definitionsfor now - it might turn out that we want more for other reasons.To avoid such details being exposed again put some checks against beingincluded from frontend code into atomics.h, lock.h, lwlock.h ands_lock.h. It's otherwise fairly easy to indirectly include theseheaders.Discussion: 20150806070902.GE12214@awork2.anarazel.de
1 parent18e8613 commit4eda0a6

File tree

12 files changed

+80
-43
lines changed

12 files changed

+80
-43
lines changed

‎src/backend/utils/hash/hashfn.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include"postgres.h"
2323

2424
#include"access/hash.h"
25+
#include"utils/hsearch.h"
2526

2627

2728
/*

‎src/include/access/genam.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include"access/sdir.h"
1818
#include"access/skey.h"
1919
#include"nodes/tidbitmap.h"
20-
#include"storage/lock.h"
20+
#include"storage/lockdefs.h"
2121
#include"utils/relcache.h"
2222
#include"utils/snapshot.h"
2323

‎src/include/access/hash.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include"fmgr.h"
2525
#include"lib/stringinfo.h"
2626
#include"storage/bufmgr.h"
27-
#include"storage/lock.h"
27+
#include"storage/lockdefs.h"
2828
#include"utils/relcache.h"
2929

3030
/*

‎src/include/access/tuptoaster.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
#defineTUPTOASTER_H
1515

1616
#include"access/htup_details.h"
17+
#include"storage/lockdefs.h"
1718
#include"utils/relcache.h"
18-
#include"storage/lock.h"
1919

2020
/*
2121
* This enables de-toasting of index entries. Needed until VACUUM is

‎src/include/catalog/objectaddress.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#defineOBJECTADDRESS_H
1515

1616
#include"nodes/pg_list.h"
17-
#include"storage/lock.h"
17+
#include"storage/lockdefs.h"
1818
#include"utils/acl.h"
1919
#include"utils/relcache.h"
2020

‎src/include/port/atomics.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
#ifndefATOMICS_H
3838
#defineATOMICS_H
3939

40+
#ifdefFRONTEND
41+
#error "atomics.h may not be included from frontend code"
42+
#endif
43+
4044
#defineINSIDE_ATOMICS_H
4145

4246
#include<limits.h>

‎src/include/storage/lock.h

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
#ifndefLOCK_H_
1515
#defineLOCK_H_
1616

17+
#ifdefFRONTEND
18+
#error "lock.h may not be included from frontend code"
19+
#endif
20+
21+
#include"storage/lockdefs.h"
1722
#include"storage/backendid.h"
1823
#include"storage/lwlock.h"
1924
#include"storage/shmem.h"
@@ -77,15 +82,6 @@ typedef struct
7782
((vxid).backendId = (proc).backendId, \
7883
(vxid).localTransactionId = (proc).lxid)
7984

80-
81-
/*
82-
* LOCKMODE is an integer (1..N) indicating a lock type. LOCKMASK is a bit
83-
* mask indicating a set of held or requested lock types (the bit 1<<mode
84-
* corresponds to a particular lock mode).
85-
*/
86-
typedefintLOCKMASK;
87-
typedefintLOCKMODE;
88-
8985
/* MAX_LOCKMODES cannot be larger than the # of bits in LOCKMASK */
9086
#defineMAX_LOCKMODES10
9187

@@ -133,28 +129,6 @@ typedef uint16 LOCKMETHODID;
133129
#defineDEFAULT_LOCKMETHOD1
134130
#defineUSER_LOCKMETHOD2
135131

136-
/*
137-
* These are the valid values of type LOCKMODE for all the standard lock
138-
* methods (both DEFAULT and USER).
139-
*/
140-
141-
/* NoLock is not a lock mode, but a flag value meaning "don't get a lock" */
142-
#defineNoLock0
143-
144-
#defineAccessShareLock1/* SELECT */
145-
#defineRowShareLock2/* SELECT FOR UPDATE/FOR SHARE */
146-
#defineRowExclusiveLock3/* INSERT, UPDATE, DELETE */
147-
#defineShareUpdateExclusiveLock 4/* VACUUM (non-FULL),ANALYZE, CREATE
148-
* INDEX CONCURRENTLY */
149-
#defineShareLock5/* CREATE INDEX (WITHOUT CONCURRENTLY) */
150-
#defineShareRowExclusiveLock6/* like EXCLUSIVE MODE, but allows ROW
151-
* SHARE */
152-
#defineExclusiveLock7/* blocks ROW SHARE/SELECT...FOR
153-
* UPDATE */
154-
#defineAccessExclusiveLock8/* ALTER TABLE, DROP TABLE, VACUUM
155-
* FULL, and unqualified LOCK TABLE */
156-
157-
158132
/*
159133
* LOCKTAG is the key information needed to look up a LOCK item in the
160134
* lock hashtable. A LOCKTAG value uniquely identifies a lockable object.
@@ -536,13 +510,6 @@ extern void RemoveFromWaitQueue(PGPROC *proc, uint32 hashcode);
536510
externSizeLockShmemSize(void);
537511
externLockData*GetLockStatusData(void);
538512

539-
typedefstructxl_standby_lock
540-
{
541-
TransactionIdxid;/* xid of holder of AccessExclusiveLock */
542-
OiddbOid;
543-
OidrelOid;
544-
}xl_standby_lock;
545-
546513
externxl_standby_lock*GetRunningTransactionLocks(int*nlocks);
547514
externconstchar*GetLockmodeName(LOCKMETHODIDlockmethodid,LOCKMODEmode);
548515

‎src/include/storage/lockdefs.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* lockdefs.h
4+
* Frontend exposed parts of postgres' low level lock mechanism
5+
*
6+
* The split between lockdefs.h and lock.h is not very principled. This file
7+
* contains definition that have to (indirectly) be available when included by
8+
* FRONTEND code.
9+
*
10+
* Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group
11+
* Portions Copyright (c) 1994, Regents of the University of California
12+
*
13+
* src/include/storage/lockdefs.h
14+
*
15+
*-------------------------------------------------------------------------
16+
*/
17+
#ifndefLOCKDEFS_H_
18+
#defineLOCKDEFS_H_
19+
20+
/*
21+
* LOCKMODE is an integer (1..N) indicating a lock type. LOCKMASK is a bit
22+
* mask indicating a set of held or requested lock types (the bit 1<<mode
23+
* corresponds to a particular lock mode).
24+
*/
25+
typedefintLOCKMASK;
26+
typedefintLOCKMODE;
27+
28+
/*
29+
* These are the valid values of type LOCKMODE for all the standard lock
30+
* methods (both DEFAULT and USER).
31+
*/
32+
33+
/* NoLock is not a lock mode, but a flag value meaning "don't get a lock" */
34+
#defineNoLock0
35+
36+
#defineAccessShareLock1/* SELECT */
37+
#defineRowShareLock2/* SELECT FOR UPDATE/FOR SHARE */
38+
#defineRowExclusiveLock3/* INSERT, UPDATE, DELETE */
39+
#defineShareUpdateExclusiveLock 4/* VACUUM (non-FULL),ANALYZE, CREATE
40+
* INDEX CONCURRENTLY */
41+
#defineShareLock5/* CREATE INDEX (WITHOUT CONCURRENTLY) */
42+
#defineShareRowExclusiveLock6/* like EXCLUSIVE MODE, but allows ROW
43+
* SHARE */
44+
#defineExclusiveLock7/* blocks ROW SHARE/SELECT...FOR
45+
* UPDATE */
46+
#defineAccessExclusiveLock8/* ALTER TABLE, DROP TABLE, VACUUM
47+
* FULL, and unqualified LOCK TABLE */
48+
49+
typedefstructxl_standby_lock
50+
{
51+
TransactionIdxid;/* xid of holder of AccessExclusiveLock */
52+
OiddbOid;
53+
OidrelOid;
54+
}xl_standby_lock;
55+
56+
#endif/* LOCKDEF_H_ */

‎src/include/storage/lwlock.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
#ifndefLWLOCK_H
1515
#defineLWLOCK_H
1616

17+
#ifdefFRONTEND
18+
#error "lwlock.h may not be included from frontend code"
19+
#endif
20+
1721
#include"lib/ilist.h"
1822
#include"storage/s_lock.h"
1923
#include"port/atomics.h"

‎src/include/storage/procarray.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#ifndefPROCARRAY_H
1515
#definePROCARRAY_H
1616

17+
#include"storage/lock.h"
1718
#include"storage/standby.h"
1819
#include"utils/relcache.h"
1920
#include"utils/snapshot.h"

‎src/include/storage/s_lock.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@
9696
#ifndefS_LOCK_H
9797
#defineS_LOCK_H
9898

99+
#ifdefFRONTEND
100+
#error "s_lock.h may not be included from frontend code"
101+
#endif
102+
99103
#ifdefHAVE_SPINLOCKS/* skip spinlocks if requested */
100104

101105
#if defined(__GNUC__)|| defined(__INTEL_COMPILER)

‎src/include/storage/standby.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#include"access/xlogreader.h"
1818
#include"lib/stringinfo.h"
19-
#include"storage/lock.h"
19+
#include"storage/lockdefs.h"
2020
#include"storage/procsignal.h"
2121
#include"storage/relfilenode.h"
2222

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp