Skip to content

Commit 93cd768

Browse files
committed
Properly acquire buffer lock for page-at-a-time hash vacuum.
In a couple of places, _hash_kill_items was mistakenly called with the buffer lock not held. Repair. Ashutosh Sharma, per a report from Andreas Seltenreich Discussion: http://postgr.es/m/87o9wo8o0j.fsf@credativ.de
1 parent f578093 commit 93cd768

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/backend/access/hash/hash.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,9 +476,17 @@ hashrescan(IndexScanDesc scan, ScanKey scankey, int nscankeys,
476476
HashScanOpaque so = (HashScanOpaque) scan->opaque;
477477
Relation rel = scan->indexRelation;
478478

479-
/* Before leaving current page, deal with any killed items */
479+
/*
480+
* Before leaving current page, deal with any killed items.
481+
* Also, ensure that we acquire lock on current page before
482+
* calling _hash_kill_items.
483+
*/
480484
if (so->numKilled > 0)
485+
{
486+
LockBuffer(so->hashso_curbuf, BUFFER_LOCK_SHARE);
481487
_hash_kill_items(scan);
488+
LockBuffer(so->hashso_curbuf, BUFFER_LOCK_UNLOCK);
489+
}
482490

483491
_hash_dropscanbuf(rel, so);
484492

@@ -507,9 +515,17 @@ hashendscan(IndexScanDesc scan)
507515
HashScanOpaque so = (HashScanOpaque) scan->opaque;
508516
Relation rel = scan->indexRelation;
509517

510-
/* Before leaving current page, deal with any killed items */
518+
/*
519+
* Before leaving current page, deal with any killed items.
520+
* Also, ensure that we acquire lock on current page before
521+
* calling _hash_kill_items.
522+
*/
511523
if (so->numKilled > 0)
524+
{
525+
LockBuffer(so->hashso_curbuf, BUFFER_LOCK_SHARE);
512526
_hash_kill_items(scan);
527+
LockBuffer(so->hashso_curbuf, BUFFER_LOCK_UNLOCK);
528+
}
513529

514530
_hash_dropscanbuf(rel, so);
515531

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy