Commit b04aeb0
committed
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.us1 parent b66827c commit b04aeb0Copy full SHA for b04aeb0
File tree
Expand file treeCollapse file tree
7 files changed
+95
-3
lines changedOpen diff view settings
Filter options
- src
- backend
- access/heap
- parser
- storage/lmgr
- include/storage
Expand file treeCollapse file tree
7 files changed
+95
-3
lines changedOpen diff view settings
Collapse file
src/backend/access/heap/heapam.c
Copy file name to clipboardExpand all lines: src/backend/access/heap/heapam.c+14Lines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
1137 | 1137 | |
1138 | 1138 | |
1139 | 1139 | |
| 1140 | + |
| 1141 | + |
| 1142 | + |
| 1143 | + |
| 1144 | + |
| 1145 | + |
| 1146 | + |
| 1147 | + |
1140 | 1148 | |
1141 | 1149 | |
1142 | 1150 | |
| ||
1183 | 1191 | |
1184 | 1192 | |
1185 | 1193 | |
| 1194 | + |
| 1195 | + |
| 1196 | + |
| 1197 | + |
1186 | 1198 | |
1187 | 1199 | |
1188 | 1200 | |
| ||
8084 | 8096 | |
8085 | 8097 | |
8086 | 8098 | |
| 8099 | + |
| 8100 | + |
8087 | 8101 | |
8088 | 8102 | |
8089 | 8103 | |
|
Collapse file
src/backend/parser/parse_relation.c
Copy file name to clipboardExpand all lines: src/backend/parser/parse_relation.c+3-1Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
28 | 28 | |
29 | 29 | |
30 | 30 | |
| 31 | + |
31 | 32 | |
32 | 33 | |
33 | 34 | |
| ||
1272 | 1273 | |
1273 | 1274 | |
1274 | 1275 | |
1275 | | - |
| 1276 | + |
1276 | 1277 | |
1277 | 1278 | |
1278 | 1279 | |
| ||
1295 | 1296 | |
1296 | 1297 | |
1297 | 1298 | |
| 1299 | + |
1298 | 1300 | |
1299 | 1301 | |
1300 | 1302 | |
|
Collapse file
src/backend/storage/lmgr/lmgr.c
Copy file name to clipboardExpand all lines: src/backend/storage/lmgr/lmgr.c+45Lines changed: 45 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
287 | 287 | |
288 | 288 | |
289 | 289 | |
| 290 | + |
| 291 | + |
| 292 | + |
| 293 | + |
| 294 | + |
| 295 | + |
| 296 | + |
| 297 | + |
| 298 | + |
| 299 | + |
| 300 | + |
| 301 | + |
| 302 | + |
| 303 | + |
| 304 | + |
| 305 | + |
| 306 | + |
| 307 | + |
| 308 | + |
| 309 | + |
| 310 | + |
| 311 | + |
| 312 | + |
| 313 | + |
| 314 | + |
| 315 | + |
| 316 | + |
| 317 | + |
| 318 | + |
| 319 | + |
| 320 | + |
| 321 | + |
| 322 | + |
| 323 | + |
| 324 | + |
| 325 | + |
| 326 | + |
| 327 | + |
| 328 | + |
| 329 | + |
| 330 | + |
| 331 | + |
| 332 | + |
| 333 | + |
| 334 | + |
290 | 335 | |
291 | 336 | |
292 | 337 | |
|
Collapse file
src/backend/storage/lmgr/lock.c
Copy file name to clipboardExpand all lines: src/backend/storage/lmgr/lock.c+24Lines changed: 24 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
563 | 563 | |
564 | 564 | |
565 | 565 | |
| 566 | + |
| 567 | + |
| 568 | + |
| 569 | + |
| 570 | + |
| 571 | + |
| 572 | + |
| 573 | + |
| 574 | + |
| 575 | + |
| 576 | + |
| 577 | + |
| 578 | + |
| 579 | + |
| 580 | + |
| 581 | + |
| 582 | + |
| 583 | + |
| 584 | + |
| 585 | + |
| 586 | + |
| 587 | + |
| 588 | + |
| 589 | + |
566 | 590 | |
567 | 591 | |
568 | 592 | |
|
Collapse file
+2Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
45 | 45 | |
46 | 46 | |
47 | 47 | |
| 48 | + |
| 49 | + |
48 | 50 | |
49 | 51 | |
50 | 52 | |
|
Collapse file
+1Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
540 | 540 | |
541 | 541 | |
542 | 542 | |
| 543 | + |
543 | 544 | |
544 | 545 | |
545 | 546 | |
|
Collapse file
src/include/storage/lockdefs.h
Copy file name to clipboardExpand all lines: src/include/storage/lockdefs.h+6-2Lines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
45 | 45 | |
46 | 46 | |
47 | 47 | |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | + |
48 | 52 | |
49 | 53 | |
50 | 54 | |
51 | | - |
52 | | - |
| 55 | + |
| 56 | + |
53 | 57 | |
54 | 58 | |
55 | 59 | |
0 commit comments