Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4eda0a6

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 use backend headers. Unfortunately until now that code includes most of the locking code. It's generally not nice to expose such low level details, but de6fd1c made that a hard problem. We fall back to defining 'inline' away if the compiler doesn't support it - that can cause linker errors like on buildfarm animal pademelon if a inline function references backend only code. To fix that problem separate definitions from lock.h that are required from frontend code into lockdefs.h and use it in the relevant places. I've only removed the minimal amount of necessary definitions for now - it might turn out that we want more for other reasons. To avoid such details being exposed again put some checks against being included from frontend code into atomics.h, lock.h, lwlock.h and s_lock.h. It's otherwise fairly easy to indirectly include these headers. Discussion: 20150806070902.GE12214@awork2.anarazel.de
1 parent 18e8613 commit 4eda0a6

File tree

12 files changed

+80
-43
lines changed

12 files changed

+80
-43
lines changed

src/backend/utils/hash/hashfn.c

+1
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

+1-1
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

+1-1
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
#define TUPTOASTER_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

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#define OBJECTADDRESS_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

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
#ifndef ATOMICS_H
3838
#define ATOMICS_H
3939

40+
#ifdef FRONTEND
41+
#error "atomics.h may not be included from frontend code"
42+
#endif
43+
4044
#define INSIDE_ATOMICS_H
4145

4246
#include <limits.h>

src/include/storage/lock.h

+5-38
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
#ifndef LOCK_H_
1515
#define LOCK_H_
1616

17+
#ifdef FRONTEND
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-
typedef int LOCKMASK;
87-
typedef int LOCKMODE;
88-
8985
/* MAX_LOCKMODES cannot be larger than the # of bits in LOCKMASK */
9086
#define MAX_LOCKMODES 10
9187

@@ -133,28 +129,6 @@ typedef uint16 LOCKMETHODID;
133129
#define DEFAULT_LOCKMETHOD 1
134130
#define USER_LOCKMETHOD 2
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-
#define NoLock 0
143-
144-
#define AccessShareLock 1 /* SELECT */
145-
#define RowShareLock 2 /* SELECT FOR UPDATE/FOR SHARE */
146-
#define RowExclusiveLock 3 /* INSERT, UPDATE, DELETE */
147-
#define ShareUpdateExclusiveLock 4 /* VACUUM (non-FULL),ANALYZE, CREATE
148-
* INDEX CONCURRENTLY */
149-
#define ShareLock 5 /* CREATE INDEX (WITHOUT CONCURRENTLY) */
150-
#define ShareRowExclusiveLock 6 /* like EXCLUSIVE MODE, but allows ROW
151-
* SHARE */
152-
#define ExclusiveLock 7 /* blocks ROW SHARE/SELECT...FOR
153-
* UPDATE */
154-
#define AccessExclusiveLock 8 /* 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
extern Size LockShmemSize(void);
537511
extern LockData *GetLockStatusData(void);
538512

539-
typedef struct xl_standby_lock
540-
{
541-
TransactionId xid; /* xid of holder of AccessExclusiveLock */
542-
Oid dbOid;
543-
Oid relOid;
544-
} xl_standby_lock;
545-
546513
extern xl_standby_lock *GetRunningTransactionLocks(int *nlocks);
547514
extern const char *GetLockmodeName(LOCKMETHODID lockmethodid, LOCKMODE mode);
548515

src/include/storage/lockdefs.h

+56
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+
#ifndef LOCKDEFS_H_
18+
#define LOCKDEFS_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+
typedef int LOCKMASK;
26+
typedef int LOCKMODE;
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+
#define NoLock 0
35+
36+
#define AccessShareLock 1 /* SELECT */
37+
#define RowShareLock 2 /* SELECT FOR UPDATE/FOR SHARE */
38+
#define RowExclusiveLock 3 /* INSERT, UPDATE, DELETE */
39+
#define ShareUpdateExclusiveLock 4 /* VACUUM (non-FULL),ANALYZE, CREATE
40+
* INDEX CONCURRENTLY */
41+
#define ShareLock 5 /* CREATE INDEX (WITHOUT CONCURRENTLY) */
42+
#define ShareRowExclusiveLock 6 /* like EXCLUSIVE MODE, but allows ROW
43+
* SHARE */
44+
#define ExclusiveLock 7 /* blocks ROW SHARE/SELECT...FOR
45+
* UPDATE */
46+
#define AccessExclusiveLock 8 /* ALTER TABLE, DROP TABLE, VACUUM
47+
* FULL, and unqualified LOCK TABLE */
48+
49+
typedef struct xl_standby_lock
50+
{
51+
TransactionId xid; /* xid of holder of AccessExclusiveLock */
52+
Oid dbOid;
53+
Oid relOid;
54+
} xl_standby_lock;
55+
56+
#endif /* LOCKDEF_H_ */

src/include/storage/lwlock.h

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
#ifndef LWLOCK_H
1515
#define LWLOCK_H
1616

17+
#ifdef FRONTEND
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

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#ifndef PROCARRAY_H
1515
#define PROCARRAY_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

+4
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@
9696
#ifndef S_LOCK_H
9797
#define S_LOCK_H
9898

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

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

src/include/storage/standby.h

+1-1
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)