pg.ddx.io pgsql-committers@postgresql.org mailing list archive
help / color / mirror / Atom feedpgsql: Fix potential assertion failure when reindexing a pg_class index
8+ messages / 3 participants
[nested] [flat]
* pgsql: Fix potential assertion failure when reindexing a pg_class index
@ 2019-04-30 03:04 Andres Freund <andres@anarazel.de>
0 siblings, 1 reply; 8+ messages in thread
From: Andres Freund @ 2019-04-30 03:04 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Fix potential assertion failure when reindexing a pg_class index.
When reindexing individual indexes on pg_class it was possible to
either trigger an assertion failure:
TRAP: FailedAssertion("!(!ReindexIsProcessingIndex(((index)->rd_id)))
That's because reindex_index() called SetReindexProcessing() - which
enables an asserts ensuring no index insertions happen into the index
- before calling RelationSetNewRelfilenode(). That not correct for
indexes on pg_class, because RelationSetNewRelfilenode() updates the
relevant pg_class row, which needs to update the indexes.
The are two reasons this wasn't noticed earlier. Firstly the bug
doesn't trigger when reindexing all of pg_class, as reindex_relation
has code "hiding" all yet-to-be-reindexed indexes. Secondly, the bug
only triggers when the the update to pg_class doesn't turn out to be a
HOT update - otherwise there's no index insertion to trigger the
bug. Most of the time there's enough space, making this bug hard to
trigger.
To fix, move RelationSetNewRelfilenode() to before the
SetReindexProcessing() (and, together with some other code, to outside
of the PG_TRY()).
To make sure the error checking intended by SetReindexProcessing() is
more robust, modify CatalogIndexInsert() to check
ReindexIsProcessingIndex() even when the update is a HOT update.
Also add a few regression tests for REINDEXing of system catalogs.
The last two improvements would have prevented some of the issues
fixed in 5c1560606dc4c from being introduced in the first place.
Reported-By: Michael Paquier
Diagnosed-By: Tom Lane and Andres Freund
Author: Andres Freund
Reviewed-By: Tom Lane
Discussion: https://postgr.es/m/20190418011430.GA19133@paquier.xyz
Backpatch: 9.4-, the bug is present in all branches
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/3dbb317d32f4f084ef7badaed8ef36f5c9b85fe6
Modified Files
--------------
contrib/test_decoding/expected/rewrite.out | 4 +++
contrib/test_decoding/sql/rewrite.sql | 5 ++++
src/backend/catalog/index.c | 40 +++++++++++++++++-------------
src/backend/catalog/indexing.c | 21 ++++++++++++++--
src/test/regress/expected/create_index.out | 18 ++++++++++++++
src/test/regress/sql/create_index.sql | 21 ++++++++++++++++
6 files changed, 90 insertions(+), 19 deletions(-)
^ permalink raw reply [nested|flat] 8+ messages in thread
* pgsql: Fix potential assertion failure when reindexing a pg_class index
@ 2019-04-30 03:04 Andres Freund <andres@anarazel.de>
0 siblings, 0 replies; 8+ messages in thread
From: Andres Freund @ 2019-04-30 03:04 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Fix potential assertion failure when reindexing a pg_class index.
When reindexing individual indexes on pg_class it was possible to
either trigger an assertion failure:
TRAP: FailedAssertion("!(!ReindexIsProcessingIndex(((index)->rd_id)))
That's because reindex_index() called SetReindexProcessing() - which
enables an asserts ensuring no index insertions happen into the index
- before calling RelationSetNewRelfilenode(). That not correct for
indexes on pg_class, because RelationSetNewRelfilenode() updates the
relevant pg_class row, which needs to update the indexes.
The are two reasons this wasn't noticed earlier. Firstly the bug
doesn't trigger when reindexing all of pg_class, as reindex_relation
has code "hiding" all yet-to-be-reindexed indexes. Secondly, the bug
only triggers when the the update to pg_class doesn't turn out to be a
HOT update - otherwise there's no index insertion to trigger the
bug. Most of the time there's enough space, making this bug hard to
trigger.
To fix, move RelationSetNewRelfilenode() to before the
SetReindexProcessing() (and, together with some other code, to outside
of the PG_TRY()).
To make sure the error checking intended by SetReindexProcessing() is
more robust, modify CatalogIndexInsert() to check
ReindexIsProcessingIndex() even when the update is a HOT update.
Also add a few regression tests for REINDEXing of system catalogs.
The last two improvements would have prevented some of the issues
fixed in 5c1560606dc4c from being introduced in the first place.
Reported-By: Michael Paquier
Diagnosed-By: Tom Lane and Andres Freund
Author: Andres Freund
Reviewed-By: Tom Lane
Discussion: https://postgr.es/m/20190418011430.GA19133@paquier.xyz
Backpatch: 9.4-, the bug is present in all branches
Branch
------
REL_11_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/14323493dd5313934899db59f5d12a3298dfe7af
Modified Files
--------------
contrib/test_decoding/expected/rewrite.out | 4 +++
contrib/test_decoding/sql/rewrite.sql | 5 ++++
src/backend/catalog/index.c | 42 +++++++++++++++++-------------
src/backend/catalog/indexing.c | 21 +++++++++++++--
src/test/regress/expected/create_index.out | 18 +++++++++++++
src/test/regress/sql/create_index.sql | 21 +++++++++++++++
6 files changed, 91 insertions(+), 20 deletions(-)
^ permalink raw reply [nested|flat] 8+ messages in thread
* pgsql: Fix potential assertion failure when reindexing a pg_class index
@ 2019-04-30 03:04 Andres Freund <andres@anarazel.de>
0 siblings, 0 replies; 8+ messages in thread
From: Andres Freund @ 2019-04-30 03:04 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Fix potential assertion failure when reindexing a pg_class index.
When reindexing individual indexes on pg_class it was possible to
either trigger an assertion failure:
TRAP: FailedAssertion("!(!ReindexIsProcessingIndex(((index)->rd_id)))
That's because reindex_index() called SetReindexProcessing() - which
enables an asserts ensuring no index insertions happen into the index
- before calling RelationSetNewRelfilenode(). That not correct for
indexes on pg_class, because RelationSetNewRelfilenode() updates the
relevant pg_class row, which needs to update the indexes.
The are two reasons this wasn't noticed earlier. Firstly the bug
doesn't trigger when reindexing all of pg_class, as reindex_relation
has code "hiding" all yet-to-be-reindexed indexes. Secondly, the bug
only triggers when the the update to pg_class doesn't turn out to be a
HOT update - otherwise there's no index insertion to trigger the
bug. Most of the time there's enough space, making this bug hard to
trigger.
To fix, move RelationSetNewRelfilenode() to before the
SetReindexProcessing() (and, together with some other code, to outside
of the PG_TRY()).
To make sure the error checking intended by SetReindexProcessing() is
more robust, modify CatalogIndexInsert() to check
ReindexIsProcessingIndex() even when the update is a HOT update.
Also add a few regression tests for REINDEXing of system catalogs.
The last two improvements would have prevented some of the issues
fixed in 5c1560606dc4c from being introduced in the first place.
Reported-By: Michael Paquier
Diagnosed-By: Tom Lane and Andres Freund
Author: Andres Freund
Reviewed-By: Tom Lane
Discussion: https://postgr.es/m/20190418011430.GA19133@paquier.xyz
Backpatch: 9.4-, the bug is present in all branches
Branch
------
REL_10_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/f495b65a5659eaca26e7f7778ae31110a73f4483
Modified Files
--------------
contrib/test_decoding/expected/rewrite.out | 4 +++
contrib/test_decoding/sql/rewrite.sql | 5 ++++
src/backend/catalog/index.c | 42 +++++++++++++++++-------------
src/backend/catalog/indexing.c | 21 +++++++++++++--
src/test/regress/expected/create_index.out | 18 +++++++++++++
src/test/regress/sql/create_index.sql | 21 +++++++++++++++
6 files changed, 91 insertions(+), 20 deletions(-)
^ permalink raw reply [nested|flat] 8+ messages in thread
* pgsql: Fix potential assertion failure when reindexing a pg_class index
@ 2019-04-30 03:04 Andres Freund <andres@anarazel.de>
0 siblings, 0 replies; 8+ messages in thread
From: Andres Freund @ 2019-04-30 03:04 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Fix potential assertion failure when reindexing a pg_class index.
When reindexing individual indexes on pg_class it was possible to
either trigger an assertion failure:
TRAP: FailedAssertion("!(!ReindexIsProcessingIndex(((index)->rd_id)))
That's because reindex_index() called SetReindexProcessing() - which
enables an asserts ensuring no index insertions happen into the index
- before calling RelationSetNewRelfilenode(). That not correct for
indexes on pg_class, because RelationSetNewRelfilenode() updates the
relevant pg_class row, which needs to update the indexes.
The are two reasons this wasn't noticed earlier. Firstly the bug
doesn't trigger when reindexing all of pg_class, as reindex_relation
has code "hiding" all yet-to-be-reindexed indexes. Secondly, the bug
only triggers when the the update to pg_class doesn't turn out to be a
HOT update - otherwise there's no index insertion to trigger the
bug. Most of the time there's enough space, making this bug hard to
trigger.
To fix, move RelationSetNewRelfilenode() to before the
SetReindexProcessing() (and, together with some other code, to outside
of the PG_TRY()).
To make sure the error checking intended by SetReindexProcessing() is
more robust, modify CatalogIndexInsert() to check
ReindexIsProcessingIndex() even when the update is a HOT update.
Also add a few regression tests for REINDEXing of system catalogs.
The last two improvements would have prevented some of the issues
fixed in 5c1560606dc4c from being introduced in the first place.
Reported-By: Michael Paquier
Diagnosed-By: Tom Lane and Andres Freund
Author: Andres Freund
Reviewed-By: Tom Lane
Discussion: https://postgr.es/m/20190418011430.GA19133@paquier.xyz
Backpatch: 9.4-, the bug is present in all branches
Branch
------
REL9_6_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/17126e0892cb7085b50fa4852b0719e37621ac40
Modified Files
--------------
contrib/test_decoding/expected/rewrite.out | 4 +++
contrib/test_decoding/sql/rewrite.sql | 5 ++++
src/backend/catalog/index.c | 42 +++++++++++++++++-------------
src/backend/catalog/indexing.c | 21 +++++++++++++--
src/test/regress/expected/create_index.out | 18 +++++++++++++
src/test/regress/sql/create_index.sql | 21 +++++++++++++++
6 files changed, 91 insertions(+), 20 deletions(-)
^ permalink raw reply [nested|flat] 8+ messages in thread
* pgsql: Fix potential assertion failure when reindexing a pg_class index
@ 2019-04-30 03:04 Andres Freund <andres@anarazel.de>
0 siblings, 0 replies; 8+ messages in thread
From: Andres Freund @ 2019-04-30 03:04 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Fix potential assertion failure when reindexing a pg_class index.
When reindexing individual indexes on pg_class it was possible to
either trigger an assertion failure:
TRAP: FailedAssertion("!(!ReindexIsProcessingIndex(((index)->rd_id)))
That's because reindex_index() called SetReindexProcessing() - which
enables an asserts ensuring no index insertions happen into the index
- before calling RelationSetNewRelfilenode(). That not correct for
indexes on pg_class, because RelationSetNewRelfilenode() updates the
relevant pg_class row, which needs to update the indexes.
The are two reasons this wasn't noticed earlier. Firstly the bug
doesn't trigger when reindexing all of pg_class, as reindex_relation
has code "hiding" all yet-to-be-reindexed indexes. Secondly, the bug
only triggers when the the update to pg_class doesn't turn out to be a
HOT update - otherwise there's no index insertion to trigger the
bug. Most of the time there's enough space, making this bug hard to
trigger.
To fix, move RelationSetNewRelfilenode() to before the
SetReindexProcessing() (and, together with some other code, to outside
of the PG_TRY()).
To make sure the error checking intended by SetReindexProcessing() is
more robust, modify CatalogIndexInsert() to check
ReindexIsProcessingIndex() even when the update is a HOT update.
Also add a few regression tests for REINDEXing of system catalogs.
The last two improvements would have prevented some of the issues
fixed in 5c1560606dc4c from being introduced in the first place.
Reported-By: Michael Paquier
Diagnosed-By: Tom Lane and Andres Freund
Author: Andres Freund
Reviewed-By: Tom Lane
Discussion: https://postgr.es/m/20190418011430.GA19133@paquier.xyz
Backpatch: 9.4-, the bug is present in all branches
Branch
------
REL9_5_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/670a492c5f1bf74b098c200aa469db044ec06d6e
Modified Files
--------------
contrib/test_decoding/expected/rewrite.out | 4 +++
contrib/test_decoding/sql/rewrite.sql | 5 ++++
src/backend/catalog/index.c | 42 +++++++++++++++++-------------
src/backend/catalog/indexing.c | 21 +++++++++++++--
src/test/regress/expected/create_index.out | 18 +++++++++++++
src/test/regress/sql/create_index.sql | 21 +++++++++++++++
6 files changed, 91 insertions(+), 20 deletions(-)
^ permalink raw reply [nested|flat] 8+ messages in thread
* pgsql: Fix potential assertion failure when reindexing a pg_class index
@ 2019-04-30 03:04 Andres Freund <andres@anarazel.de>
0 siblings, 0 replies; 8+ messages in thread
From: Andres Freund @ 2019-04-30 03:04 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Fix potential assertion failure when reindexing a pg_class index.
When reindexing individual indexes on pg_class it was possible to
either trigger an assertion failure:
TRAP: FailedAssertion("!(!ReindexIsProcessingIndex(((index)->rd_id)))
That's because reindex_index() called SetReindexProcessing() - which
enables an asserts ensuring no index insertions happen into the index
- before calling RelationSetNewRelfilenode(). That not correct for
indexes on pg_class, because RelationSetNewRelfilenode() updates the
relevant pg_class row, which needs to update the indexes.
The are two reasons this wasn't noticed earlier. Firstly the bug
doesn't trigger when reindexing all of pg_class, as reindex_relation
has code "hiding" all yet-to-be-reindexed indexes. Secondly, the bug
only triggers when the the update to pg_class doesn't turn out to be a
HOT update - otherwise there's no index insertion to trigger the
bug. Most of the time there's enough space, making this bug hard to
trigger.
To fix, move RelationSetNewRelfilenode() to before the
SetReindexProcessing() (and, together with some other code, to outside
of the PG_TRY()).
To make sure the error checking intended by SetReindexProcessing() is
more robust, modify CatalogIndexInsert() to check
ReindexIsProcessingIndex() even when the update is a HOT update.
Also add a few regression tests for REINDEXing of system catalogs.
The last two improvements would have prevented some of the issues
fixed in 5c1560606dc4c from being introduced in the first place.
Reported-By: Michael Paquier
Diagnosed-By: Tom Lane and Andres Freund
Author: Andres Freund
Reviewed-By: Tom Lane
Discussion: https://postgr.es/m/20190418011430.GA19133@paquier.xyz
Backpatch: 9.4-, the bug is present in all branches
Branch
------
REL9_4_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/e7418f89f17ad351d8cbd513a104efda6d25a2bd
Modified Files
--------------
contrib/test_decoding/expected/rewrite.out | 4 +++
contrib/test_decoding/sql/rewrite.sql | 5 ++++
src/backend/catalog/index.c | 42 +++++++++++++++++-------------
src/backend/catalog/indexing.c | 21 +++++++++++++--
src/test/regress/expected/create_index.out | 18 +++++++++++++
src/test/regress/sql/create_index.sql | 21 +++++++++++++++
6 files changed, 91 insertions(+), 20 deletions(-)
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: pgsql: Fix potential assertion failure when reindexing a pg_class index
@ 2019-04-30 12:24 Andrew Dunstan <andrew.dunstan@2ndquadrant.com>
parent: Andres Freund <andres@anarazel.de>
0 siblings, 1 reply; 8+ messages in thread
From: Andrew Dunstan @ 2019-04-30 12:24 UTC (permalink / raw)
To: Andres Freund <andres@anarazel.de>; pgsql-committers@lists.postgresql.org
On 4/29/19 11:04 PM, Andres Freund wrote:
> Fix potential assertion failure when reindexing a pg_class index.
>
There seem to be a number of regression test failures involving deadlock
resulting from this. e.g. on prion:
2019-04-30 03:20:12.772 UTC [15476:388] pg_regress/create_view LOG: statement: alter table tt14t alter column f4 type integer using f4::integer;
2019-04-30 03:20:12.776 UTC [15479:450] pg_regress/create_index LOG: statement: REINDEX TABLE pg_class;
2019-04-30 03:20:13.777 UTC [15476:389] pg_regress/create_view LOG: process 15476 detected deadlock while waiting for AccessShareLock on relation 2662 of database 16384 after 1000.109 ms
2019-04-30 03:20:13.777 UTC [15476:390] pg_regress/create_view DETAIL: Process holding the lock: 15479. Wait queue: .
2019-04-30 03:20:13.777 UTC [15476:391] pg_regress/create_view STATEMENT: alter table tt14t alter column f4 type integer using f4::integer;
2019-04-30 03:20:13.777 UTC [15476:392] pg_regress/create_view ERROR: deadlock detected
2019-04-30 03:20:13.777 UTC [15476:393] pg_regress/create_view DETAIL: Process 15476 waits for AccessShareLock on relation 2662 of database 16384; blocked by process 15479.
Process 15479 waits for ShareLock on transaction 2887; blocked by process 15476.
Process 15476: alter table tt14t alter column f4 type integer using f4::integer;
Process 15479: REINDEX TABLE pg_class;
cheers
andrew
--
Andrew Dunstan https://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: pgsql: Fix potential assertion failure when reindexing a pg_class index
@ 2019-04-30 13:28 Tom Lane <tgl@sss.pgh.pa.us>
parent: Andrew Dunstan <andrew.dunstan@2ndquadrant.com>
0 siblings, 0 replies; 8+ messages in thread
From: Tom Lane @ 2019-04-30 13:28 UTC (permalink / raw)
To: Andrew Dunstan <andrew.dunstan@2ndquadrant.com>; +Cc: Andres Freund <andres@anarazel.de>; pgsql-committers@lists.postgresql.org
Andrew Dunstan <andrew.dunstan@2ndquadrant.com> writes:
> There seem to be a number of regression test failures involving deadlock
> resulting from this. e.g. on prion:
Yeah, see -hackers thread: <20190430070552.jzqgcy4ihalx7nur@alap3.anarazel.de>
regards, tom lane
^ permalink raw reply [nested|flat] 8+ messages in thread
end of thread, other threads:[~2019-04-30 13:28 UTC | newest]
Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-04-30 03:04 pgsql: Fix potential assertion failure when reindexing a pg_class index Andres Freund <andres@anarazel.de>
2019-04-30 12:24 ` Andrew Dunstan <andrew.dunstan@2ndquadrant.com>
2019-04-30 13:28 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-04-30 03:04 pgsql: Fix potential assertion failure when reindexing a pg_class index Andres Freund <andres@anarazel.de>
2019-04-30 03:04 pgsql: Fix potential assertion failure when reindexing a pg_class index Andres Freund <andres@anarazel.de>
2019-04-30 03:04 pgsql: Fix potential assertion failure when reindexing a pg_class index Andres Freund <andres@anarazel.de>
2019-04-30 03:04 pgsql: Fix potential assertion failure when reindexing a pg_class index Andres Freund <andres@anarazel.de>
2019-04-30 03:04 pgsql: Fix potential assertion failure when reindexing a pg_class index Andres Freund <andres@anarazel.de>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox