This is an automated email from the ASF dual-hosted git repository.

leborchuk pushed a commit to branch REL_2_STABLE
in repository https://gitbox.apache.org/repos/asf/cloudberry.git

commit c9f0f908522743589b3b429ff3561e2b58506d88
Author: FairyFar <[email protected]>
AuthorDate: Wed Sep 2 15:39:49 2026 +0800

    Fix assert failure triggered by "CREATE INDEX CONCURRENTLY" (#1845)
    
    When resource group is enabled, StartTransaction() may take a catalog
    snapshot while assigning a resource group, leaving a valid xmin in MyProc.
    That fails the assertion in set_indexsafe_procflags() that the process must
    not advertise an xmin when running "CREATE INDEX CONCURRENTLY".
    
    Fix it at the point the invariant lives: set_indexsafe_procflags() now
    invalidates any stale catalog snapshot before asserting, so every
    REINDEX CONCURRENTLY phase clears the xmin ahead of setting PROC_IN_SAFE_IC.
---
 src/backend/commands/indexcmds.c                            | 11 +++++++++++
 .../isolation2/expected/resgroup/resgroup_transaction.out   | 13 +++++++++++++
 src/test/isolation2/sql/resgroup/resgroup_transaction.sql   |  9 +++++++++
 3 files changed, 33 insertions(+)

diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c
index 0fa8a961f0b..4f5e85e7633 100644
--- a/src/backend/commands/indexcmds.c
+++ b/src/backend/commands/indexcmds.c
@@ -5406,6 +5406,17 @@ update_relispartition(Oid relationId, bool newval)
 static inline void
 set_indexsafe_procflags(void)
 {
+       /*
+        * A catalog snapshot taken earlier in this transaction (for example, by
+        * resource-group slot assignment during StartTransaction) leaves a 
valid
+        * xmin advertised in MyProc.  Drop it here so the assertion below 
holds;
+        * CREATE INDEX CONCURRENTLY phases must not hold any snapshot at this
+        * point anyway.
+        */
+       if (MyProc->xid != InvalidTransactionId ||
+               MyProc->xmin != InvalidTransactionId)
+               InvalidateCatalogSnapshot();
+
        /*
         * This should only be called before installing xid or xmin in MyProc;
         * otherwise, concurrent processes could see an Xmin that moves 
backwards.
diff --git a/src/test/isolation2/expected/resgroup/resgroup_transaction.out 
b/src/test/isolation2/expected/resgroup/resgroup_transaction.out
index baad66ef535..a302f77236f 100644
--- a/src/test/isolation2/expected/resgroup/resgroup_transaction.out
+++ b/src/test/isolation2/expected/resgroup/resgroup_transaction.out
@@ -237,3 +237,16 @@ DROP
 -- cleanup
 DROP VIEW rg_test_monitor;
 DROP
+
+-- ----------------------------------------------------------------------
+-- Test: "CREATE INDEX CONCURRENTLY" when compiled with enable-cassert
+-- ----------------------------------------------------------------------
+
+CREATE TABLE t(a text, b text);
+CREATE
+CREATE INDEX CONCURRENTLY t_idx ON t(a, b);
+CREATE
+DROP INDEX CONCURRENTLY t_idx;
+DROP
+DROP TABLE t;
+DROP
diff --git a/src/test/isolation2/sql/resgroup/resgroup_transaction.sql 
b/src/test/isolation2/sql/resgroup/resgroup_transaction.sql
index da29d48f208..7ab6f40b33b 100644
--- a/src/test/isolation2/sql/resgroup/resgroup_transaction.sql
+++ b/src/test/isolation2/sql/resgroup/resgroup_transaction.sql
@@ -134,3 +134,12 @@ DROP FUNCTION rg_drop_func();
 
 -- cleanup
 DROP VIEW rg_test_monitor;
+
+-- ----------------------------------------------------------------------
+-- Test: "CREATE INDEX CONCURRENTLY" when compiled with enable-cassert
+-- ----------------------------------------------------------------------
+
+CREATE TABLE t(a text, b text);
+CREATE INDEX CONCURRENTLY t_idx ON t(a, b);
+DROP INDEX CONCURRENTLY t_idx;
+DROP TABLE t;


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to