diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2018-10-01 12:43:21 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2018-10-01 12:43:21 -0400 |
commit | b04aeb0a053e7cf7faad89f7d47844d8ba0dc839 (patch) | |
tree | 543d8a9de0d421fe4cb624260f4ec0e1724a3fa4 /src/include/storage/lockdefs.h | |
parent | b66827ca7c5a4c9e31b1a1eced677f8677efc0cf (diff) | |
download | postgresql-b04aeb0a053e7cf7faad89f7d47844d8ba0dc839.tar.gz postgresql-b04aeb0a053e7cf7faad89f7d47844d8ba0dc839.zip |
Add assertions that we hold some relevant lock during relation open.
Opening a relation with no lock at all is unsafe; there's no guarantee
that we'll see a consistent state of the relevant catalog entries.
While use of MVCC scans to read the catalogs partially addresses that
complaint, it's still possible to switch to a new catalog snapshot
partway through loading the relcache entry. Moreover, whether or not
you trust the reasoning behind sometimes using less than
AccessExclusiveLock for ALTER TABLE, that reasoning is certainly not
valid if concurrent users of the table don't hold a lock corresponding
to the operation they want to perform.
Hence, add some assertion-build-only checks that require any caller
of relation_open(x, NoLock) to hold at least AccessShareLock. This
isn't a full solution, since we can't verify that the lock level is
semantically appropriate for the action --- but it's definitely of
some use, because it's already caught two bugs.
We can also assert that callers of addRangeTableEntryForRelation()
hold at least the lock level specified for the new RTE.
Amit Langote and Tom Lane
Discussion: https://postgr.es/m/16565.1538327894@sss.pgh.pa.us
Diffstat (limited to 'src/include/storage/lockdefs.h')
-rw-r--r-- | src/include/storage/lockdefs.h | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/include/storage/lockdefs.h b/src/include/storage/lockdefs.h index 72eca39f17f..9c933fab3fb 100644 --- a/src/include/storage/lockdefs.h +++ b/src/include/storage/lockdefs.h @@ -45,11 +45,15 @@ typedef int LOCKMODE; #define AccessExclusiveLock 8 /* ALTER TABLE, DROP TABLE, VACUUM FULL, * and unqualified LOCK TABLE */ +#define MaxLockMode 8 + + +/* WAL representation of an AccessExclusiveLock on a table */ typedef struct xl_standby_lock { TransactionId xid; /* xid of holder of AccessExclusiveLock */ - Oid dbOid; - Oid relOid; + Oid dbOid; /* DB containing table */ + Oid relOid; /* OID of table */ } xl_standby_lock; #endif /* LOCKDEF_H_ */ |