diff options
author | Alvaro Herrera | 2020-08-12 19:33:36 +0000 |
---|---|---|
committer | Alvaro Herrera | 2020-08-12 19:33:36 +0000 |
commit | ce3a8fde8e62c62c29e4342ad32b07b2bbf33b64 (patch) | |
tree | e947ddc7b271ed6d319ba34f060a05de58cdf2e1 | |
parent | 641d7cf4bc92499fdbf23f3b47112502d5720599 (diff) |
BRIN: Handle concurrent desummarization properly
If a page range is desummarized at just the right time concurrently with
an index walk, BRIN would raise an error indicating index corruption.
This is scary and unhelpful; silently returning that the page range is
not summarized is sufficient reaction.
This bug was introduced by commit 975ad4e602ff as additional protection
against a bug whose actual fix was elsewhere. Backpatch equally.
Reported-By: Anastasia Lubennikova <[email protected]>
Diagnosed-By: Alexander Lakhin <[email protected]>
Discussion: https://postgr.es/m/[email protected]
Backpatch: 9.5 - master
-rw-r--r-- | src/backend/access/brin/brin_revmap.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/backend/access/brin/brin_revmap.c b/src/backend/access/brin/brin_revmap.c index d16d87b9af..d7b70f7817 100644 --- a/src/backend/access/brin/brin_revmap.c +++ b/src/backend/access/brin/brin_revmap.c @@ -266,10 +266,17 @@ brinGetTupleForHeapBlock(BrinRevmap *revmap, BlockNumber heapBlk, /* If we land on a revmap page, start over */ if (BRIN_IS_REGULAR_PAGE(page)) { + /* + * If the offset number is greater than what's in the page, it's + * possible that the range was desummarized concurrently. Just + * return NULL to handle that case. + */ if (*off > PageGetMaxOffsetNumber(page)) - ereport(ERROR, - (errcode(ERRCODE_INDEX_CORRUPTED), - errmsg_internal("corrupted BRIN index: inconsistent range map"))); + { + LockBuffer(*buf, BUFFER_LOCK_UNLOCK); + return NULL; + } + lp = PageGetItemId(page, *off); if (ItemIdIsUsed(lp)) { |