You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudberry.apache.org by yj...@apache.org on 2025/01/16 11:24:55 UTC

(cloudberry) branch main updated (af40a37985 -> 1cbba02378)

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

yjhjstz pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git


    from af40a37985 fix cherry-pick
     new 696aba727e Fix the version argument to ArgumentParser is deprecated. (#15948)
     new 611de07d9f Fix the warning of pg_basebackup(). (#15784)
     new 9a608506f8 gpcheckcat shouldn't throw dependency error for pg_subscription and pg_transform
     new 733e71cf85 Remove dead code updateRoleForRecoveredSegs()
     new 2b4399c89f Remove deprecated distutils (#15986)
     new 123fcde8fc Fix flaky test for crash_recovery_dtm
     new 57496bd335 Fix threading.Thread.getName() is deprecated (#15996)
     new 6c0f027ccd Add gp_stat_progress_dtx_recovery for observability
     new 1cbba02378 Revert "Only super user can set the GUC gp_resource_group_bypass."

The 9 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 gpMgmt/bin/gpload.py                               |  4 +-
 gpMgmt/bin/gppylib/gparray.py                      | 34 ----------
 gpMgmt/bin/gppylib/gpcatalog.py                    |  4 +-
 gpMgmt/bin/gpsd                                    |  1 -
 gpMgmt/test/behave/mgmt_utils/gpcheckcat.feature   | 12 +++-
 src/backend/catalog/system_views.sql               | 16 +++++
 src/backend/cdb/cdbdtxrecovery.c                   | 68 +++++++++++++++++++-
 .../gporca/scripts/convert_minirepro_5_to_6.py     |  3 +-
 .../gporca/scripts/get_debug_event_counters.py     |  3 +-
 src/backend/utils/adt/pgstatfuncs.c                |  2 +
 src/backend/utils/init/postinit.c                  |  2 +-
 src/backend/utils/misc/faultinjector.c             |  4 +-
 src/backend/utils/misc/guc_gp.c                    |  2 +-
 src/include/commands/progress.h                    | 15 +++++
 src/include/utils/backend_progress.h               |  3 +-
 .../isolation2/expected/crash_recovery_dtm.out     | 73 +++++++++++++++++++++-
 .../expected/resgroup/resgroup_bypass.out          |  6 --
 .../expected/segwalrep/dtx_recovery_wait_lsn.out   | 39 ++++++++++--
 src/test/isolation2/expected/setup.out             |  2 +-
 src/test/isolation2/sql/crash_recovery_dtm.sql     | 25 +++++++-
 .../isolation2/sql/resgroup/resgroup_bypass.sql    |  5 --
 .../sql/segwalrep/dtx_recovery_wait_lsn.sql        | 16 ++++-
 src/test/isolation2/sql/setup.sql                  |  2 +-
 src/test/regress/expected/profile.out              |  2 +-
 24 files changed, 271 insertions(+), 72 deletions(-)


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


(cloudberry) 06/09: Fix flaky test for crash_recovery_dtm

Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 123fcde8fc64780e7f17e2f962a314e5341e7cdb
Author: Marbin Tan <tm...@vmware.com>
AuthorDate: Fri Jul 14 09:15:37 2023 -0700

    Fix flaky test for crash_recovery_dtm
    
    We might be hitting a race condition where we are suspending
    `after_orphaned_check` on before suspending on `before_orphaned_check`,
    which may cause the `gp_inject_fault_infinite` of
    `before_orphaned_check` to never get triggered.
    
    Reorder the fault injection to fix the issue.
    
    Co-authored-by: Huansong Fu <fu...@gmail.com>
---
 src/test/isolation2/expected/crash_recovery_dtm.out | 5 +++++
 src/test/isolation2/sql/crash_recovery_dtm.sql      | 2 ++
 2 files changed, 7 insertions(+)

diff --git a/src/test/isolation2/expected/crash_recovery_dtm.out b/src/test/isolation2/expected/crash_recovery_dtm.out
index a75313ead3..7ada74a348 100644
--- a/src/test/isolation2/expected/crash_recovery_dtm.out
+++ b/src/test/isolation2/expected/crash_recovery_dtm.out
@@ -325,6 +325,11 @@ server closed the connection unexpectedly
 -------------------------------
  Success:                      
 (1 row)
+19: SELECT gp_inject_fault_infinite('after_orphaned_check', 'suspend', dbid) from gp_segment_configuration where role = 'p' and content = -1;
+ gp_inject_fault_infinite 
+--------------------------
+ Success:                 
+(1 row)
 
 -- let prepare finish else dtx recovery can not abort the prepared transaction.
 19: SELECT gp_inject_fault_infinite('before_xlog_xact_prepare', 'reset', dbid) from gp_segment_configuration where role = 'p' and content = 1;
diff --git a/src/test/isolation2/sql/crash_recovery_dtm.sql b/src/test/isolation2/sql/crash_recovery_dtm.sql
index 517b3fe183..3c7ce2f043 100644
--- a/src/test/isolation2/sql/crash_recovery_dtm.sql
+++ b/src/test/isolation2/sql/crash_recovery_dtm.sql
@@ -157,6 +157,8 @@ select pg_reload_conf();
    from gp_segment_configuration where role = 'p' and content = -1;
 19: SELECT gp_wait_until_triggered_fault('before_orphaned_check', 1, dbid)
    from gp_segment_configuration where role = 'p' and content = -1;
+19: SELECT gp_inject_fault_infinite('after_orphaned_check', 'suspend', dbid)
+   from gp_segment_configuration where role = 'p' and content = -1;
 
 -- let prepare finish else dtx recovery can not abort the prepared transaction.
 19: SELECT gp_inject_fault_infinite('before_xlog_xact_prepare', 'reset', dbid)


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


(cloudberry) 02/09: Fix the warning of pg_basebackup(). (#15784)

Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 611de07d9f9f6d7b027d7ed73554bae095b255b2
Author: Zhang Hao <hz...@vmware.com>
AuthorDate: Tue Jul 11 17:42:23 2023 +0800

    Fix the warning of pg_basebackup(). (#15784)
    
    When an error occurs in pg_basebackup(), its detail can not be
    printed properly. Instead, the following error will be raised:
    
    ```
    +ERROR:  TypeError: can only concatenate str (not "bytes") to str
    +CONTEXT:  Traceback (most recent call last):
    +  PL/Python function "pg_basebackup", line 26, in <module>
    +    results = str(e) + "\ncommand output: " + e.output
    +PL/Python function "pg_basebackup"
    ```
    This problem is caused by that e.output is a bytes array and
    cannot contact str.
    
    The solution is to change e.output to e.output.decode().
---
 src/test/isolation2/expected/setup.out | 2 +-
 src/test/isolation2/sql/setup.sql      | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/test/isolation2/expected/setup.out b/src/test/isolation2/expected/setup.out
index 7834efcea9..0abedc3b4a 100644
--- a/src/test/isolation2/expected/setup.out
+++ b/src/test/isolation2/expected/setup.out
@@ -116,7 +116,7 @@ if slotname is not None: cmd += ' --slot %s' % (slotname)
 if force_overwrite: cmd += ' --force-overwrite' 
 if xlog_method == 'stream': cmd += ' --wal-method stream' elif xlog_method == 'fetch': cmd += ' --wal-method fetch' else: plpy.error('invalid xlog method') 
 cmd += ' --no-verify-checksums' 
-try: # Unset PGAPPNAME so that the pg_stat_replication.application_name is not affected if os.getenv('PGAPPNAME') is not None: os.environ.pop('PGAPPNAME') results = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True).replace(b'.', b'').decode() except subprocess.CalledProcessError as e: results = str(e) + "\ncommand output: " + str(e.output) 
+try: # Unset PGAPPNAME so that the pg_stat_replication.application_name is not affected if os.getenv('PGAPPNAME') is not None: os.environ.pop('PGAPPNAME') results = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True).replace(b'.', b'').decode() except subprocess.CalledProcessError as e: results = str(e) + "\ncommand output: " + (e.output.decode()) 
 return results $$ language plpython3u;
 CREATE
 
diff --git a/src/test/isolation2/sql/setup.sql b/src/test/isolation2/sql/setup.sql
index 9d6c0cc245..88daf6db96 100644
--- a/src/test/isolation2/sql/setup.sql
+++ b/src/test/isolation2/sql/setup.sql
@@ -352,7 +352,7 @@ create or replace function pg_basebackup(host text, dbid int, port bigint, creat
             os.environ.pop('PGAPPNAME')
         results = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True).replace(b'.', b'').decode()
     except subprocess.CalledProcessError as e:
-        results = str(e) + "\ncommand output: " + str(e.output)
+        results = str(e) + "\ncommand output: " + (e.output.decode())
 
     return results
 $$ language plpython3u;


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


(cloudberry) 09/09: Revert "Only super user can set the GUC gp_resource_group_bypass."

Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 1cbba02378bfdf07b7e733cddd31f522c04cd9a4
Author: Zhenghua Lyu <ka...@gmail.com>
AuthorDate: Sat Jul 29 20:36:21 2023 +0800

    Revert "Only super user can set the GUC gp_resource_group_bypass."
    
    This reverts commit 85d943910c74b48e606515fc18a7d4a99e197dbc.
    
    Bypass resgroup still will put proc into cgroup and use a small
    value of query memory so it will not impact system too much. Revert
    previous commit let other application like GPCC can work easily.
---
 src/backend/utils/misc/guc_gp.c                           | 2 +-
 src/test/isolation2/expected/resgroup/resgroup_bypass.out | 6 ------
 src/test/isolation2/sql/resgroup/resgroup_bypass.sql      | 5 -----
 3 files changed, 1 insertion(+), 12 deletions(-)

diff --git a/src/backend/utils/misc/guc_gp.c b/src/backend/utils/misc/guc_gp.c
index b131fbb537..f816a4b9b2 100644
--- a/src/backend/utils/misc/guc_gp.c
+++ b/src/backend/utils/misc/guc_gp.c
@@ -2840,7 +2840,7 @@ struct config_bool ConfigureNamesBool_gp[] =
 	},
 
 	{
-		{"gp_resource_group_bypass", PGC_SUSET, RESOURCES,
+		{"gp_resource_group_bypass", PGC_USERSET, RESOURCES,
 			gettext_noop("If the value is true, the query in this session will not be limited by resource group."),
 			NULL
 		},
diff --git a/src/test/isolation2/expected/resgroup/resgroup_bypass.out b/src/test/isolation2/expected/resgroup/resgroup_bypass.out
index 090be7983d..5cff41d745 100644
--- a/src/test/isolation2/expected/resgroup/resgroup_bypass.out
+++ b/src/test/isolation2/expected/resgroup/resgroup_bypass.out
@@ -19,12 +19,6 @@ SET ROLE role_bypass;
 SET
 CREATE TABLE t_bypass(a int) distributed by (a);
 CREATE
-
--- gp_resource_group_bypass can only be set by super user
--- below set statement will error out
-set gp_resource_group_bypass = 1;
-ERROR:  permission denied to set parameter "gp_resource_group_bypass"
-
 RESET ROLE;
 RESET
 
diff --git a/src/test/isolation2/sql/resgroup/resgroup_bypass.sql b/src/test/isolation2/sql/resgroup/resgroup_bypass.sql
index d4d97fbd6b..19c50771f7 100644
--- a/src/test/isolation2/sql/resgroup/resgroup_bypass.sql
+++ b/src/test/isolation2/sql/resgroup/resgroup_bypass.sql
@@ -12,11 +12,6 @@ CREATE ROLE role_bypass RESOURCE GROUP rg_bypass;
 
 SET ROLE role_bypass;
 CREATE TABLE t_bypass(a int) distributed by (a);
-
--- gp_resource_group_bypass can only be set by super user
--- below set statement will error out
-set gp_resource_group_bypass = 1;
-
 RESET ROLE;
 
 -- Session1: pure-catalog query will be unassigned and bypassed.


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


(cloudberry) 05/09: Remove deprecated distutils (#15986)

Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 2b4399c89f53e0a1988bcea165e930715c482d04
Author: Yongtao Huang <99...@users.noreply.github.com>
AuthorDate: Fri Jul 14 09:43:08 2023 +0800

    Remove deprecated distutils (#15986)
    
    Long log:
    
    The `distutils `module was deprecated in Python 3.10 and is scheduled for removal in Python 3.12.
    At the same time, it is also dead code.
    
    Signed-off-by: Yongtao Huang <yo...@vmware.com>
---
 gpMgmt/bin/gpsd | 1 -
 1 file changed, 1 deletion(-)

diff --git a/gpMgmt/bin/gpsd b/gpMgmt/bin/gpsd
index fe877a38de..bffbc02065 100755
--- a/gpMgmt/bin/gpsd
+++ b/gpMgmt/bin/gpsd
@@ -10,7 +10,6 @@ import pwd
 import sys
 import re
 from contextlib import closing
-from distutils.version import LooseVersion
 from optparse import OptionParser
 import pgdb
 from gppylib.utils import formatInsertValuesList, Escape


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


(cloudberry) 07/09: Fix threading.Thread.getName() is deprecated (#15996)

Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 57496bd335ef35bf37a16e7e2eb5ca320ac00534
Author: Yongtao Huang <99...@users.noreply.github.com>
AuthorDate: Sun Jul 16 10:52:16 2023 +0800

    Fix threading.Thread.getName() is deprecated (#15996)
    
    Long log:
    
    Module threading.Thread.getName() is deprecated since python 3.10.
    Deprecated getter/setter API for
    [name](https://docs.python.org/3/library/threading.html#threading.Thread.name);
    use it directly as a property instead.
    
    Take a simple example in python 3.10:
    ```
    import threading
    import time
    
    def run(n):
        print("task", n)
        time.sleep(1)
        print('1s')
        time.sleep(1)
        print('0s')
        time.sleep(1)
    
    if __name__ == '__main__':
        t1 = threading.Thread(target=run, args=("t1",))
        t1.start()
        print(t1.getName())
        print(t1.name)
    ```
    
    The result is shown as below:
    ```
    $ python main.py
    task t1
    /hoem/gpadmin/main.py:15: DeprecationWarning: getName() is deprecated, get the name attribute instead
      print(t1.getName())
    Thread-1 (run)
    Thread-1 (run)
    1s
    0s
    ```
    
    Signed-off-by: Yongtao Huang <yo...@vmware.com>
---
 gpMgmt/bin/gpload.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gpMgmt/bin/gpload.py b/gpMgmt/bin/gpload.py
index 9813f7d305..9ac5fb4577 100755
--- a/gpMgmt/bin/gpload.py
+++ b/gpMgmt/bin/gpload.py
@@ -832,8 +832,8 @@ class CatThread(threading.Thread):
         except Exception as e:
             # close fd so that not block the worker thread because of stdout/stderr pipe not finish/closed.
             self.fd.close()
-            sys.stderr.write("\n\nWarning: gpfdist log halt because Log Thread '%s' got an exception: %s \n" % (self.getName(), str(e)))
-            self.gpload.log(self.gpload.WARN, "gpfdist log halt because Log Thread '%s' got an exception: %s" % (self.getName(), str(e)))
+            sys.stderr.write("\n\nWarning: gpfdist log halt because Log Thread '%s' got an exception: %s \n" % (self.name, str(e)))
+            self.gpload.log(self.gpload.WARN, "gpfdist log halt because Log Thread '%s' got an exception: %s" % (self.name, str(e)))
             raise
 
 def cli_help():


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


(cloudberry) 04/09: Remove dead code updateRoleForRecoveredSegs()

Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 733e71cf854f7cc56b181fa892e9526d845a6603
Author: Ashwin Agrawal <aa...@vmware.com>
AuthorDate: Thu Jul 13 15:38:03 2023 +0530

    Remove dead code updateRoleForRecoveredSegs()
    
    Reviewed-by: Soumyadeep Chakraborty <so...@gmail.com>
---
 gpMgmt/bin/gppylib/gparray.py | 34 ----------------------------------
 1 file changed, 34 deletions(-)

diff --git a/gpMgmt/bin/gppylib/gparray.py b/gpMgmt/bin/gppylib/gparray.py
index 18e66d9717..ea101bed78 100755
--- a/gpMgmt/bin/gppylib/gparray.py
+++ b/gpMgmt/bin/gppylib/gparray.py
@@ -1444,40 +1444,6 @@ class GpArray:
         prefix = self.coordinator.datadir[start_last_dir:start_dir_content]
         return prefix
 
-    # --------------------------------------------------------------------
-    # If we've got recovered segments, and we have a matched-pair, we
-    # can update the catalog to "rebalance" back to our original primary.
-    def updateRoleForRecoveredSegs(self, dbURL):
-        """
-        Marks the segment role to match the configured preferred_role.
-        """
-
-        # walk our list of segments, checking to make sure that
-        # both members of the peer-group are in our recovered-list,
-        # save their content-id.
-        recovered_contents = []
-        for segPair in self.segmentPairs:
-            if segPair.primaryDB:
-                if segPair.primaryDB.dbid in self.recoveredSegmentDbids:
-                    if segPair.mirrorDB and segPair.mirrorDB.dbid in self.recoveredSegmentDbids:
-                        recovered_contents.append((segPair.primaryDB.content, segPair.primaryDB.dbid, segPair.mirrorDB.dbid))
-
-        with closing(dbconn.connect(dbURL, True, allowSystemTableMods = True)) as conn:
-            for (content_id, primary_dbid, mirror_dbid) in recovered_contents:
-                sql = "UPDATE gp_segment_configuration SET role=preferred_role where content = %d" % content_id
-                dbconn.executeUpdateOrInsert(conn, sql, 2)
-
-                # NOTE: primary-dbid (right now) is the mirror.
-                sql = "INSERT INTO gp_configuration_history VALUES (now(), %d, 'Reassigned role for content %d to MIRROR')" % (primary_dbid, content_id)
-                dbconn.executeUpdateOrInsert(conn, sql, 1)
-
-                # NOTE: mirror-dbid (right now) is the primary.
-                sql = "INSERT INTO gp_configuration_history VALUES (now(), %d, 'Reassigned role for content %d to PRIMARY')" % (mirror_dbid, content_id)
-                dbconn.executeUpdateOrInsert(conn, sql, 1)
-
-                # We could attempt to update the segments-array.
-                # But the caller will re-read the configuration from the catalog.
-
     # --------------------------------------------------------------------
     def addExpansionSeg(self, content, preferred_role, dbid, role,
                         hostname, address, port, datadir):


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


(cloudberry) 01/09: Fix the version argument to ArgumentParser is deprecated. (#15948)

Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 696aba727e129ec2abd92489bd5f7e860a6323f7
Author: Yongtao Huang <99...@users.noreply.github.com>
AuthorDate: Mon Jul 10 16:27:43 2023 +0800

    Fix the version argument to ArgumentParser is deprecated. (#15948)
    
    The "version" argument to ArgumentParser is deprecated.
    Please refer to https://bugs.launchpad.net/yade/+bug/1134422
    
    Take a short example:
    ```
    import argparse
    parser = argparse.ArgumentParser(version='1.0')
    ```
    the error result is shown as below:
    ```
    $ python3 main.py
    Traceback (most recent call last):
      File "main.py", line 2, in <module>
        parser = argparse.ArgumentParser(version='1.0')
    TypeError: __init__() got an unexpected keyword argument 'version'
    ```
    
    **Solution**: use `parser.add_argument()` to fix it.
    
    Signed-off-by: Yongtao Huang <yo...@vmware.com>
---
 src/backend/gporca/scripts/convert_minirepro_5_to_6.py | 3 ++-
 src/backend/gporca/scripts/get_debug_event_counters.py | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/backend/gporca/scripts/convert_minirepro_5_to_6.py b/src/backend/gporca/scripts/convert_minirepro_5_to_6.py
index df0fdb77a8..f32cc396ad 100755
--- a/src/backend/gporca/scripts/convert_minirepro_5_to_6.py
+++ b/src/backend/gporca/scripts/convert_minirepro_5_to_6.py
@@ -85,8 +85,9 @@ def convert_insert_statement(infile, outfile):
 
 
 def parseargs():
-	parser = argparse.ArgumentParser(description=_help, version='1.0')
+	parser = argparse.ArgumentParser(description=_help)
 
+	parser.add_argument('--version', action='version', version='1.0')
 	parser.add_argument("filepath", help="Path to minirepro file")
 
 	args = parser.parse_args()
diff --git a/src/backend/gporca/scripts/get_debug_event_counters.py b/src/backend/gporca/scripts/get_debug_event_counters.py
index b27851df1b..41a5b0ea41 100755
--- a/src/backend/gporca/scripts/get_debug_event_counters.py
+++ b/src/backend/gporca/scripts/get_debug_event_counters.py
@@ -172,8 +172,9 @@ def processLogFile(logFileLines, allruns):
 
 
 def parseargs():
-	parser = argparse.ArgumentParser(description=_help, version='1.0')
+	parser = argparse.ArgumentParser(description=_help)
 
+	parser.add_argument('--version', action='version', version='1.0')
 	parser.add_argument("--logFile", default="",
 						help="GPDB log file saved from a run with debug event counters enabled (default is to search "
 							 "GPDB master log directory)")


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


(cloudberry) 08/09: Add gp_stat_progress_dtx_recovery for observability

Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 6c0f027ccd278c56d8270d2347a7d6691246f85e
Author: Marbin Tan <tm...@vmware.com>
AuthorDate: Wed Jun 28 12:41:57 2023 -0700

    Add gp_stat_progress_dtx_recovery for observability
    
    dtx recovery may take time sometimes and will leave you in the dark with
    how far the recovery has progressed.
    `gp_stat_progress_dtx_recovery` is a view that shows progress
    of the current dtx recovery.
    
    There are 5 main phases (excluding initializing):
    1. recovering commited distributed transactions
    2. gathering in-doubt transactions
    3. aborting in-doubt transactions
    4. gathering in-doubt orphaned transactions
    5. managing in-doubt orphaned transactions
    
    `gp_stat_progress_dtx_recovery` will be shown with column:
    phase
    recover_commited_dtx_total
    recover_commited_dtx_completed
    in_doubt_tx_total
    in_doubt_tx_in_progress
    in_doubt_tx_aborted
    
    The wording of "managing" is used instead of "aborting" for in-doubt
    orphaned transactions to make it slightly ambigious. There is a chance
    an in-doubt transaction is already an on going transaction and there
    will be no need to dispatch a dtx abort command.
---
 src/backend/catalog/system_views.sql               | 16 +++++
 src/backend/cdb/cdbdtxrecovery.c                   | 68 +++++++++++++++++++++-
 src/backend/utils/adt/pgstatfuncs.c                |  2 +
 src/backend/utils/init/postinit.c                  |  2 +-
 src/backend/utils/misc/faultinjector.c             |  4 +-
 src/include/commands/progress.h                    | 15 +++++
 src/include/utils/backend_progress.h               |  3 +-
 .../isolation2/expected/crash_recovery_dtm.out     | 68 +++++++++++++++++++++-
 .../expected/segwalrep/dtx_recovery_wait_lsn.out   | 39 +++++++++++--
 src/test/isolation2/sql/crash_recovery_dtm.sql     | 23 +++++++-
 .../sql/segwalrep/dtx_recovery_wait_lsn.sql        | 16 ++++-
 src/test/regress/expected/profile.out              |  2 +-
 12 files changed, 243 insertions(+), 15 deletions(-)

diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
index 7ec1293af3..8cfaa58ac5 100644
--- a/src/backend/catalog/system_views.sql
+++ b/src/backend/catalog/system_views.sql
@@ -1741,6 +1741,22 @@ CREATE VIEW pg_stat_progress_copy AS
     FROM pg_stat_get_progress_info('COPY') AS S
         LEFT JOIN pg_database D ON S.datid = D.oid;
 
+CREATE VIEW gp_stat_progress_dtx_recovery AS
+    SELECT
+        CASE S.param1 WHEN 0 THEN 'initializing'
+                      WHEN 1 THEN 'recovering commited distributed transactions'
+                      WHEN 2 THEN 'gathering in-doubt transactions'
+                      WHEN 3 THEN 'aborting in-doubt transactions'
+                      WHEN 4 THEN 'gathering in-doubt orphaned transactions'
+                      WHEN 5 THEN 'managing in-doubt orphaned transactions'
+                      END AS phase,
+        S.param2 AS recover_commited_dtx_total, -- total commited transactions found to recover
+        S.param3 AS recover_commited_dtx_completed, -- recover completed, this is always 0 after startup.
+        S.param4 AS in_doubt_tx_total,  -- total in doubt tx found, used in startup and non-startup phase
+        S.param5 AS in_doubt_tx_in_progress, -- in-progress in-doubt tx, this is always 0 for startup
+        S.param6 AS in_doubt_tx_aborted -- aborted in-doubt tx, this can be >0 for both
+    FROM pg_stat_get_progress_info('DTX RECOVERY') AS S;
+
 CREATE VIEW pg_user_mappings AS
     SELECT
         U.oid       AS umid,
diff --git a/src/backend/cdb/cdbdtxrecovery.c b/src/backend/cdb/cdbdtxrecovery.c
index 7a6f6c5d01..186b01ff21 100644
--- a/src/backend/cdb/cdbdtxrecovery.c
+++ b/src/backend/cdb/cdbdtxrecovery.c
@@ -19,6 +19,7 @@
 #include "utils/ps_status.h"
 #include "postmaster/bgworker.h"
 #include "pgstat.h"
+#include "commands/progress.h"
 #include "storage/ipc.h"
 #include "storage/latch.h"
 #include "storage/lwlock.h"
@@ -53,6 +54,10 @@ volatile int *shmNumCommittedGxacts;
 
 static volatile sig_atomic_t got_SIGHUP = false;
 
+static int64 in_doubt_tx_in_progress = 0;
+static int64 in_doubt_tx_aborted = 0;
+static int64 in_doubt_tx_total = 0;
+
 typedef struct InDoubtDtx
 {
 	char		gid[TMGIDSIZE];
@@ -190,6 +195,11 @@ recoverInDoubtTransactions(void)
 		 "Going to retry commit notification for distributed transactions (count = %d)",
 		 *shmNumCommittedGxacts);
 
+	pgstat_progress_update_param(PROGRESS_DTX_RECOVERY_PHASE,
+								 PROGRESS_DTX_RECOVERY_PHASE_STARTUP_RECOVER_COMMITTED_DTX);
+	pgstat_progress_update_param(PROGRESS_DTX_RECOVERY_COMITTED_DTX_TOTAL,
+								 *shmNumCommittedGxacts);
+
 	for (i = 0; i < *shmNumCommittedGxacts; i++)
 	{
 		DistributedTransactionId gxid = shmCommittedGxidArray[i];
@@ -204,16 +214,27 @@ recoverInDoubtTransactions(void)
 		doNotifyCommittedInDoubt(gid);
 
 		RecordDistributedForgetCommitted(gxid);
+
+		pgstat_progress_update_param(PROGRESS_DTX_RECOVERY_COMITTED_DTX_COMPLETED,
+									 i+1);
 	}
 
+	SIMPLE_FAULT_INJECTOR("post_progress_recovery_comitted");
+
 	*shmNumCommittedGxacts = 0;
 
+
+	pgstat_progress_update_param(PROGRESS_DTX_RECOVERY_PHASE,
+								 PROGRESS_DTX_RECOVERY_PHASE_STARTUP_GATHER_IN_DOUBT_TX);
+
 	/*
 	 * Any in-doubt transctions found will be for aborted
 	 * transactions. Gather in-doubt transactions and issue aborts.
 	 */
 	htab = gatherRMInDoubtTransactions(0, true);
 
+	pgstat_progress_update_param(PROGRESS_DTX_RECOVERY_PHASE,
+								 PROGRESS_DTX_RECOVERY_PHASE_STARTUP_ABORT_IN_DOUBT_TX);
 	/*
 	 * go through and resolve any remaining in-doubt transactions that the
 	 * RM's have AFTER recoverDTMInDoubtTransactions.  ALL of these in doubt
@@ -351,6 +372,9 @@ gatherRMInDoubtTransactions(int prepared_seconds, bool raiseError)
 				elog(DEBUG3, "Found in-doubt transaction with GID: %s on remote RM", gid);
 
 				strncpy(lastDtx->gid, gid, TMGIDSIZE);
+
+				pgstat_progress_update_param(PROGRESS_DTX_RECOVERY_IN_DOUBT_TX_TOTAL,
+											 ++in_doubt_tx_total);
 			}
 		}
 	}
@@ -388,6 +412,9 @@ abortRMInDoubtTransactions(HTAB *htab)
 		elog(DTM_DEBUG3, "Aborting in-doubt transaction with gid = %s", entry->gid);
 
 		doAbortInDoubt(entry->gid);
+
+		pgstat_progress_update_param(PROGRESS_DTX_RECOVERY_IN_DOUBT_TX_ABORTED,
+									 ++in_doubt_tx_aborted);
 	}
 }
 
@@ -414,10 +441,19 @@ abortOrphanedTransactions(HTAB *htab)
 
 		dtxDeformGid(entry->gid, &gxid);
 
-		if (!IsDtxInProgress(gxid))
+		if (IsDtxInProgress(gxid))
+		{
+			pgstat_progress_update_param(PROGRESS_DTX_RECOVERY_IN_DOUBT_TX_IN_PROGRESS,
+										 ++in_doubt_tx_in_progress);
+			SIMPLE_FAULT_INJECTOR("post_in_doubt_tx_in_progress");
+		}
+		else
 		{
 			elog(LOG, "Aborting orphaned transactions with gid = %s", entry->gid);
 			doAbortInDoubt(entry->gid);
+
+			pgstat_progress_update_param(PROGRESS_DTX_RECOVERY_IN_DOUBT_TX_ABORTED,
+										 ++in_doubt_tx_aborted);
 		}
 	}
 }
@@ -536,6 +572,14 @@ DtxRecoveryStartRule(Datum main_arg)
 	return (Gp_role == GP_ROLE_DISPATCH);
 }
 
+static void
+ResetInDoubtStatProgress()
+{
+	in_doubt_tx_total = 0;
+	in_doubt_tx_aborted = 0;
+	in_doubt_tx_in_progress = 0;
+}
+
 static void
 AbortOrphanedPreparedTransactions()
 {
@@ -546,9 +590,15 @@ AbortOrphanedPreparedTransactions()
 		return;
 #endif
 
+	pgstat_progress_update_param(PROGRESS_DTX_RECOVERY_PHASE,
+								 PROGRESS_DTX_RECOVERY_PHASE_GATHER_IN_DOUBT_TX);
+
 	StartTransactionCommand();
 	htab = gatherRMInDoubtTransactions(gp_dtx_recovery_prepared_period, false);
 
+	pgstat_progress_update_param(PROGRESS_DTX_RECOVERY_PHASE,
+								 PROGRESS_DTX_RECOVERY_PHASE_ABORT_IN_DOUBT_TX);
+
 	/* in case an error happens somehow. */
 	if (htab != NULL)
 	{
@@ -629,6 +679,9 @@ DtxRecoveryMain(Datum main_arg)
 	/* Connect to postgres */
 	BackgroundWorkerInitializeConnection(DB_FOR_COMMON_ACCESS, NULL, 0);
 
+	/* initialize progress */
+	pgstat_progress_start_command(PROGRESS_COMMAND_DTX_RECOVERY, InvalidOid);
+
 	/*
 	 * Do dtx recovery process.  It is possible that *shmDtmStarted is true
 	 * here if we terminate after this code block, e.g. due to error and then
@@ -646,6 +699,8 @@ DtxRecoveryMain(Datum main_arg)
 		set_ps_display("");
 	}
 
+	pgstat_progress_end_command();
+
 	/* Fetch the gxid batch in advance. */
 	bumpGxid();
 
@@ -690,7 +745,18 @@ DtxRecoveryMain(Datum main_arg)
 			 * cases so that it could respond promptly for gxid bumping given
 			 * the abort operation might be time-consuming.
 			 */
+
+			/*
+			 * The total amount of in doubt transactions are calculated per iteration
+			 * and are destroyed after use. Keeping the old statistics may be confusing,
+			 * so clear it up.
+			 */
+			ResetInDoubtStatProgress();
+			pgstat_progress_start_command(PROGRESS_COMMAND_DTX_RECOVERY, InvalidOid);
+
 			AbortOrphanedPreparedTransactions();
+
+			pgstat_progress_end_command();
 		}
 
 		rc = WaitLatch(&MyProc->procLatch,
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 242fdbc3cb..89621072f8 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -504,6 +504,8 @@ pg_stat_get_progress_info(PG_FUNCTION_ARGS)
 		cmdtype = PROGRESS_COMMAND_BASEBACKUP;
 	else if (pg_strcasecmp(cmd, "COPY") == 0)
 		cmdtype = PROGRESS_COMMAND_COPY;
+	else if (pg_strcasecmp(cmd, "DTX RECOVERY") == 0)
+		cmdtype = PROGRESS_COMMAND_DTX_RECOVERY;
 	else
 		ereport(ERROR,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c
index 6163eff945..a335f3fdef 100644
--- a/src/backend/utils/init/postinit.c
+++ b/src/backend/utils/init/postinit.c
@@ -1251,7 +1251,7 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username,
 	 * report this backend in the PgBackendStatus array, meanwhile, we do not
 	 * want users to see auxiliary background worker like fts in pg_stat_* views.
 	 */
-	if (!bootstrap && !amAuxiliaryBgWorker())
+	if (!bootstrap && (!amAuxiliaryBgWorker() || IsDtxRecoveryProcess()))
 		pgstat_bestart();
 
 	/* 
diff --git a/src/backend/utils/misc/faultinjector.c b/src/backend/utils/misc/faultinjector.c
index 3aa202dc41..df456b3bb0 100644
--- a/src/backend/utils/misc/faultinjector.c
+++ b/src/backend/utils/misc/faultinjector.c
@@ -277,7 +277,9 @@ checkBgProcessSkipFault(const char* faultName)
 	{
 		/* dtx recovery process */
 		 if (0 != strcmp("before_orphaned_check", faultName) &&
-				0 != strcmp("after_orphaned_check", faultName))
+				0 != strcmp("after_orphaned_check", faultName) &&
+				0 != strcmp("post_in_doubt_tx_in_progress", faultName) &&
+				0 != strcmp("post_progress_recovery_comitted", faultName))
 		{
 			elog(LOG, "skipped fault '%s' in dtx recovery process", faultName);
 			return true;
diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h
index 990f8b8e6f..f18e63bd7a 100644
--- a/src/include/commands/progress.h
+++ b/src/include/commands/progress.h
@@ -155,4 +155,19 @@
 #define PROGRESS_COPY_TYPE_PIPE 3
 #define PROGRESS_COPY_TYPE_CALLBACK 4
 
+/* Progress parameters for DTX recovery */
+#define PROGRESS_DTX_RECOVERY_PHASE 0
+#define PROGRESS_DTX_RECOVERY_COMITTED_DTX_TOTAL 1
+#define PROGRESS_DTX_RECOVERY_COMITTED_DTX_COMPLETED 2
+#define PROGRESS_DTX_RECOVERY_IN_DOUBT_TX_TOTAL 3
+#define PROGRESS_DTX_RECOVERY_IN_DOUBT_TX_IN_PROGRESS 4
+#define PROGRESS_DTX_RECOVERY_IN_DOUBT_TX_ABORTED 5
+
+/* Phases of DTX recovery */
+#define PROGRESS_DTX_RECOVERY_PHASE_STARTUP_RECOVER_COMMITTED_DTX 1
+#define PROGRESS_DTX_RECOVERY_PHASE_STARTUP_GATHER_IN_DOUBT_TX 2
+#define PROGRESS_DTX_RECOVERY_PHASE_STARTUP_ABORT_IN_DOUBT_TX 3
+#define PROGRESS_DTX_RECOVERY_PHASE_GATHER_IN_DOUBT_TX 4
+#define PROGRESS_DTX_RECOVERY_PHASE_ABORT_IN_DOUBT_TX 5
+
 #endif
diff --git a/src/include/utils/backend_progress.h b/src/include/utils/backend_progress.h
index 53bddf665b..8458625c89 100644
--- a/src/include/utils/backend_progress.h
+++ b/src/include/utils/backend_progress.h
@@ -27,7 +27,8 @@ typedef enum ProgressCommandType
 	PROGRESS_COMMAND_CLUSTER,
 	PROGRESS_COMMAND_CREATE_INDEX,
 	PROGRESS_COMMAND_BASEBACKUP,
-	PROGRESS_COMMAND_COPY
+	PROGRESS_COMMAND_COPY,
+	PROGRESS_COMMAND_DTX_RECOVERY
 } ProgressCommandType;
 
 #define PGSTAT_NUM_PROGRESS_PARAM	20
diff --git a/src/test/isolation2/expected/crash_recovery_dtm.out b/src/test/isolation2/expected/crash_recovery_dtm.out
index 7ada74a348..31b1e86391 100644
--- a/src/test/isolation2/expected/crash_recovery_dtm.out
+++ b/src/test/isolation2/expected/crash_recovery_dtm.out
@@ -216,6 +216,11 @@ ALTER
 -----------------
  Success:        
 (1 row)
+11: select gp_inject_fault_infinite('before_orphaned_check', 'suspend', dbid) FROM gp_segment_configuration WHERE content=-1 AND role='p';
+ gp_inject_fault_infinite 
+--------------------------
+ Success:                 
+(1 row)
 -- statement to trigger fault after writing prepare record
 12&: DELETE FROM QE_panic_test_table;  <waiting ...>
 11: SELECT gp_wait_until_triggered_fault('end_prepare_two_phase', 1, dbid) from gp_segment_configuration where role='p' and content=0;
@@ -229,9 +234,26 @@ ALTER
  OK     
 (1 row)
 12<:  <... completed>
-ERROR:  Error on receive from seg0 127.0.0.1:7002 pid=25361: server closed the connection unexpectedly
+ERROR:  Error on receive from seg0 127.0.0.1:7002 pid=5600: server closed the connection unexpectedly
 	This probably means the server terminated abnormally
 	before or while processing the request.
+
+11: SELECT gp_wait_until_triggered_fault('before_orphaned_check', 1, dbid) from gp_segment_configuration where role = 'p' and content = -1;
+ gp_wait_until_triggered_fault 
+-------------------------------
+ Success:                      
+(1 row)
+11: select * from gp_stat_progress_dtx_recovery;
+ phase        | recover_commited_dtx_total | recover_commited_dtx_completed | in_doubt_tx_total | in_doubt_tx_in_progress | in_doubt_tx_aborted 
+--------------+----------------------------+--------------------------------+-------------------+-------------------------+---------------------
+ initializing | 0                          | 0                              | 0                 | 0                       | 0                   
+(1 row)
+11: SELECT gp_inject_fault_infinite('before_orphaned_check', 'reset', dbid) from gp_segment_configuration where role='p' and content=-1;
+ gp_inject_fault_infinite 
+--------------------------
+ Success:                 
+(1 row)
+
 13: SELECT count(*) from QE_panic_test_table;
  count 
 -------
@@ -363,6 +385,22 @@ server closed the connection unexpectedly
 --------------------------
  Success:                 
 (1 row)
+-- verify orphaned prepared transacion is aborted
+19: SELECT gp_wait_until_triggered_fault('after_orphaned_check', 1, dbid) from gp_segment_configuration where role = 'p' and content = -1;
+ gp_wait_until_triggered_fault 
+-------------------------------
+ Success:                      
+(1 row)
+19: select * from gp_stat_progress_dtx_recovery;
+ phase                                   | recover_commited_dtx_total | recover_commited_dtx_completed | in_doubt_tx_total | in_doubt_tx_in_progress | in_doubt_tx_aborted 
+-----------------------------------------+----------------------------+--------------------------------+-------------------+-------------------------+---------------------
+ managing in-doubt orphaned transactions | 0                          | 0                              | 1                 | 0                       | 1                   
+(1 row)
+19: SELECT gp_inject_fault_infinite('after_orphaned_check', 'reset', dbid) from gp_segment_configuration where role = 'p' and content = -1;
+ gp_inject_fault_infinite 
+--------------------------
+ Success:                 
+(1 row)
 19: DROP TABLE master_reset;
 DROP
 19: ALTER SYSTEM RESET gp_dtx_recovery_interval;
@@ -412,6 +450,11 @@ CREATE
 --------------------------
  Success:                 
 (1 row)
+20: SELECT gp_inject_fault_infinite('post_in_doubt_tx_in_progress', 'suspend', dbid) from gp_segment_configuration where role = 'p' and content = -1;
+ gp_inject_fault_infinite 
+--------------------------
+ Success:                 
+(1 row)
 
 -- run two phase query.
 21: INSERT INTO test_retry_abort SELECT generate_series(1,10);
@@ -428,6 +471,22 @@ ERROR:  fault triggered, fault name:'dtm_broadcast_prepare' fault type:'error'
 -------
  1     
 (1 row)
+-- verify in-doubt transaction is in progress
+20: SELECT gp_wait_until_triggered_fault('post_in_doubt_tx_in_progress', 1, dbid) from gp_segment_configuration where role = 'p' and content = -1;
+ gp_wait_until_triggered_fault 
+-------------------------------
+ Success:                      
+(1 row)
+20: select * from gp_stat_progress_dtx_recovery;
+ phase                                   | recover_commited_dtx_total | recover_commited_dtx_completed | in_doubt_tx_total | in_doubt_tx_in_progress | in_doubt_tx_aborted 
+-----------------------------------------+----------------------------+--------------------------------+-------------------+-------------------------+---------------------
+ managing in-doubt orphaned transactions | 0                          | 0                              | 1                 | 1                       | 0                   
+(1 row)
+19: SELECT gp_inject_fault_infinite('post_in_doubt_tx_in_progress', 'reset', dbid) from gp_segment_configuration where role = 'p' and content = -1;
+ gp_inject_fault_infinite 
+--------------------------
+ Success:                 
+(1 row)
 
 -- dtx recovery ready to handle the orphaned prepared transaction.
 20: SELECT gp_inject_fault_infinite('before_orphaned_check', 'suspend', dbid) from gp_segment_configuration where role = 'p' and content = -1;
@@ -440,7 +499,7 @@ ERROR:  fault triggered, fault name:'dtm_broadcast_prepare' fault type:'error'
 -------------------------------
  Success:                      
 (1 row)
-20: SELECT gp_inject_fault_infinite('after_orphaned_check', 'skip', dbid) from gp_segment_configuration where role = 'p' and content = -1;
+20: SELECT gp_inject_fault_infinite('after_orphaned_check', 'suspend', dbid) from gp_segment_configuration where role = 'p' and content = -1;
  gp_inject_fault_infinite 
 --------------------------
  Success:                 
@@ -468,6 +527,11 @@ ERROR:  fault triggered, fault name:'dtm_broadcast_prepare' fault type:'error'
  transaction | gid | prepared | owner | database 
 -------------+-----+----------+-------+----------
 (0 rows)
+20: select * from gp_stat_progress_dtx_recovery;
+ phase                                   | recover_commited_dtx_total | recover_commited_dtx_completed | in_doubt_tx_total | in_doubt_tx_in_progress | in_doubt_tx_aborted 
+-----------------------------------------+----------------------------+--------------------------------+-------------------+-------------------------+---------------------
+ managing in-doubt orphaned transactions | 0                          | 0                              | 1                 | 0                       | 1                   
+(1 row)
 
 -- cleanup
 20: ALTER SYSTEM RESET gp_dtx_recovery_interval;
diff --git a/src/test/isolation2/expected/segwalrep/dtx_recovery_wait_lsn.out b/src/test/isolation2/expected/segwalrep/dtx_recovery_wait_lsn.out
index a410a91b75..ce415fc5f9 100644
--- a/src/test/isolation2/expected/segwalrep/dtx_recovery_wait_lsn.out
+++ b/src/test/isolation2/expected/segwalrep/dtx_recovery_wait_lsn.out
@@ -7,6 +7,8 @@
 
 1: create table t_wait_lsn(a int);
 CREATE
+5: create table t_wait_lsn2(a int);
+CREATE
 
 -- suspend segment 0 before performing 'COMMIT PREPARED'
 2: select gp_inject_fault_infinite('finish_prepared_start_of_function', 'suspend', dbid) from gp_segment_configuration where content=0 and role='p';
@@ -15,7 +17,8 @@ CREATE
  Success:                 
 (1 row)
 1&: insert into t_wait_lsn values(2),(1);  <waiting ...>
-2: select gp_wait_until_triggered_fault('finish_prepared_start_of_function', 1, dbid) from gp_segment_configuration where content=0 and role='p';
+5&: insert into t_wait_lsn2 values(2),(1);  <waiting ...>
+2: select gp_wait_until_triggered_fault('finish_prepared_start_of_function', 2, dbid) from gp_segment_configuration where content=0 and role='p';
  gp_wait_until_triggered_fault 
 -------------------------------
  Success:                      
@@ -37,7 +40,7 @@ CREATE
 0U: select count(*) from pg_prepared_xacts;
  count 
 -------
- 1     
+ 2     
 (1 row)
 
 -- stop mirror
@@ -69,7 +72,30 @@ server closed the connection unexpectedly
 	This probably means the server terminated abnormally
 	before or while processing the request.
 
--- wait for master finish crash recovery
+-- potential flakiness: there is a chance where the coordinator
+-- recovers fast enough (from the panic above) that we end up fault injecting too late.
+-1U: select gp_inject_fault_infinite('post_progress_recovery_comitted', 'suspend', dbid) FROM gp_segment_configuration WHERE content=-1 AND role='p';
+ gp_inject_fault_infinite 
+--------------------------
+ Success:                 
+(1 row)
+-1U: select gp_wait_until_triggered_fault('post_progress_recovery_comitted', 1, dbid) from gp_segment_configuration where content=-1 and role='p';
+ gp_wait_until_triggered_fault 
+-------------------------------
+ Success:                      
+(1 row)
+-1U: select * from gp_stat_progress_dtx_recovery;
+ phase                                        | recover_commited_dtx_total | recover_commited_dtx_completed | in_doubt_tx_total | in_doubt_tx_in_progress | in_doubt_tx_aborted 
+----------------------------------------------+----------------------------+--------------------------------+-------------------+-------------------------+---------------------
+ recovering commited distributed transactions | 2                          | 2                              | 0                 | 0                       | 0                   
+(1 row)
+-1U: select gp_inject_fault_infinite('post_progress_recovery_comitted', 'reset', dbid) from gp_segment_configuration where content=-1 and role='p';
+ gp_inject_fault_infinite 
+--------------------------
+ Success:                 
+(1 row)
+
+-- wait for coordinator finish crash recovery
 -1U: select wait_until_standby_in_state('streaming');
  wait_until_standby_in_state 
 -----------------------------
@@ -85,8 +111,11 @@ server closed the connection unexpectedly
 -------
  2     
 (1 row)
-
 1<:  <... completed>
+server closed the connection unexpectedly
+	This probably means the server terminated abnormally
+	before or while processing the request.
+5<:  <... completed>
 server closed the connection unexpectedly
 	This probably means the server terminated abnormally
 	before or while processing the request.
@@ -121,6 +150,8 @@ server closed the connection unexpectedly
 (1 row)
 4: drop table t_wait_lsn;
 DROP
+4: drop table t_wait_lsn2;
+DROP
 
 4: select gp_inject_fault('walrecv_skip_flush', 'reset', dbid) from gp_segment_configuration where content=0;
  gp_inject_fault 
diff --git a/src/test/isolation2/sql/crash_recovery_dtm.sql b/src/test/isolation2/sql/crash_recovery_dtm.sql
index 3c7ce2f043..46c58c6c3c 100644
--- a/src/test/isolation2/sql/crash_recovery_dtm.sql
+++ b/src/test/isolation2/sql/crash_recovery_dtm.sql
@@ -113,12 +113,18 @@ select pg_reload_conf();
 11: SELECT gp_request_fts_probe_scan();
 11: SELECT gp_inject_fault('end_prepare_two_phase', 'infinite_loop', dbid)
     from gp_segment_configuration where role='p' and content=0;
+11: select gp_inject_fault_infinite('before_orphaned_check', 'suspend', dbid) FROM gp_segment_configuration WHERE content=-1 AND role='p';
 -- statement to trigger fault after writing prepare record
 12&: DELETE FROM QE_panic_test_table;
 11: SELECT gp_wait_until_triggered_fault('end_prepare_two_phase', 1, dbid)
     from gp_segment_configuration where role='p' and content=0;
 11: SELECT pg_ctl(datadir, 'restart') from gp_segment_configuration where role = 'p' and content = 0;
 12<:
+
+11: SELECT gp_wait_until_triggered_fault('before_orphaned_check', 1, dbid) from gp_segment_configuration where role = 'p' and content = -1;
+11: select * from gp_stat_progress_dtx_recovery;
+11: SELECT gp_inject_fault_infinite('before_orphaned_check', 'reset', dbid) from gp_segment_configuration where role='p' and content=-1;
+
 13: SELECT count(*) from QE_panic_test_table;
 13: SELECT * FROM gp_dist_random('pg_prepared_xacts');
 13: SELECT gp_inject_fault('fts_probe', 'reset', dbid)
@@ -176,6 +182,12 @@ select pg_reload_conf();
 -- with required lock of the drop operation.
 19: SELECT gp_inject_fault_infinite('before_orphaned_check', 'reset', dbid)
    from gp_segment_configuration where role = 'p' and content = -1;
+-- verify orphaned prepared transacion is aborted
+19: SELECT gp_wait_until_triggered_fault('after_orphaned_check', 1, dbid)
+   from gp_segment_configuration where role = 'p' and content = -1;
+19: select * from gp_stat_progress_dtx_recovery;
+19: SELECT gp_inject_fault_infinite('after_orphaned_check', 'reset', dbid)
+   from gp_segment_configuration where role = 'p' and content = -1;
 19: DROP TABLE master_reset;
 19: ALTER SYSTEM RESET gp_dtx_recovery_interval;
 19: ALTER SYSTEM RESET gp_dtx_recovery_prepared_period;
@@ -201,6 +213,8 @@ select pg_reload_conf();
    from gp_segment_configuration where role = 'p' and content = -1;
 20: SELECT gp_inject_fault_infinite('finish_prepared_start_of_function', 'error', dbid)
    from gp_segment_configuration where role = 'p' and content = 0;
+20: SELECT gp_inject_fault_infinite('post_in_doubt_tx_in_progress', 'suspend', dbid)
+   from gp_segment_configuration where role = 'p' and content = -1;
 
 -- run two phase query.
 21: INSERT INTO test_retry_abort SELECT generate_series(1,10);
@@ -209,13 +223,19 @@ select pg_reload_conf();
 -- transaction on seg0.
 20: SELECT * from test_retry_abort;
 0U: SELECT count(*) from pg_prepared_xacts;
+-- verify in-doubt transaction is in progress
+20: SELECT gp_wait_until_triggered_fault('post_in_doubt_tx_in_progress', 1, dbid)
+   from gp_segment_configuration where role = 'p' and content = -1;
+20: select * from gp_stat_progress_dtx_recovery;
+19: SELECT gp_inject_fault_infinite('post_in_doubt_tx_in_progress', 'reset', dbid)
+   from gp_segment_configuration where role = 'p' and content = -1;
 
 -- dtx recovery ready to handle the orphaned prepared transaction.
 20: SELECT gp_inject_fault_infinite('before_orphaned_check', 'suspend', dbid)
    from gp_segment_configuration where role = 'p' and content = -1;
 20: SELECT gp_wait_until_triggered_fault('before_orphaned_check', 1, dbid)
    from gp_segment_configuration where role = 'p' and content = -1;
-20: SELECT gp_inject_fault_infinite('after_orphaned_check', 'skip', dbid)
+20: SELECT gp_inject_fault_infinite('after_orphaned_check', 'suspend', dbid)
    from gp_segment_configuration where role = 'p' and content = -1;
 
 -- kick off abort prepared on seg0 and then dtx recovery will abort that one.
@@ -228,6 +248,7 @@ select pg_reload_conf();
 20: SELECT gp_wait_until_triggered_fault('after_orphaned_check', 1, dbid)
    from gp_segment_configuration where role = 'p' and content = -1;
 0U: SELECT * from pg_prepared_xacts;
+20: select * from gp_stat_progress_dtx_recovery;
 
 -- cleanup
 20: ALTER SYSTEM RESET gp_dtx_recovery_interval;
diff --git a/src/test/isolation2/sql/segwalrep/dtx_recovery_wait_lsn.sql b/src/test/isolation2/sql/segwalrep/dtx_recovery_wait_lsn.sql
index e9e61f2d0d..8cd7666e23 100644
--- a/src/test/isolation2/sql/segwalrep/dtx_recovery_wait_lsn.sql
+++ b/src/test/isolation2/sql/segwalrep/dtx_recovery_wait_lsn.sql
@@ -6,11 +6,13 @@
 -- while the 'dtx recovery' process is hanging recovering distributed transactions.
 
 1: create table t_wait_lsn(a int);
+5: create table t_wait_lsn2(a int);
 
 -- suspend segment 0 before performing 'COMMIT PREPARED'
 2: select gp_inject_fault_infinite('finish_prepared_start_of_function', 'suspend', dbid) from gp_segment_configuration where content=0 and role='p';
 1&: insert into t_wait_lsn values(2),(1);
-2: select gp_wait_until_triggered_fault('finish_prepared_start_of_function', 1, dbid) from gp_segment_configuration where content=0 and role='p';
+5&: insert into t_wait_lsn2 values(2),(1);
+2: select gp_wait_until_triggered_fault('finish_prepared_start_of_function', 2, dbid) from gp_segment_configuration where content=0 and role='p';
 
 -- let walreceiver on mirror 0 skip WAL flush
 2: select gp_inject_fault_infinite('walrecv_skip_flush', 'skip', dbid) from gp_segment_configuration where content=0 and role='m';
@@ -32,7 +34,14 @@
 -- end_matchsubs
 3: select 1;
 
--- wait for master finish crash recovery
+-- potential flakiness: there is a chance where the coordinator
+-- recovers fast enough (from the panic above) that we end up fault injecting too late.
+-1U: select gp_inject_fault_infinite('post_progress_recovery_comitted', 'suspend', dbid) FROM gp_segment_configuration WHERE content=-1 AND role='p';
+-1U: select gp_wait_until_triggered_fault('post_progress_recovery_comitted', 1, dbid) from gp_segment_configuration where content=-1 and role='p';
+-1U: select * from gp_stat_progress_dtx_recovery;
+-1U: select gp_inject_fault_infinite('post_progress_recovery_comitted', 'reset', dbid) from gp_segment_configuration where content=-1 and role='p';
+
+-- wait for coordinator finish crash recovery
 -1U: select wait_until_standby_in_state('streaming');
 
 -- wait for FTS to 'sync off' the mirror, meanwhile, dtx recovery process will
@@ -40,8 +49,8 @@
 -- the query should succeed finally since dtx recovery process is able to quit.
 -- this's what we want to test.
 4: select count(*) from t_wait_lsn;
-
 1<:
+5<:
 
 !\retcode gpfts -R 1 -A -D;
 !\retcode gprecoverseg -a;
@@ -51,5 +60,6 @@
 4: select pg_sleep(10);
 4: select count(*) from t_wait_lsn;
 4: drop table t_wait_lsn;
+4: drop table t_wait_lsn2;
 
 4: select gp_inject_fault('walrecv_skip_flush', 'reset', dbid) from gp_segment_configuration where content=0;
diff --git a/src/test/regress/expected/profile.out b/src/test/regress/expected/profile.out
index b7fcbd6602..9c2c203602 100644
--- a/src/test/regress/expected/profile.out
+++ b/src/test/regress/expected/profile.out
@@ -5,7 +5,7 @@
 SELECT COUNT(*) FROM pg_stat_activity;
  count 
 -------
-     8
+     9
 (1 row)
 
 -- Display pg_authid, pg_roles, pg_profile and pg_password_history catalog


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


(cloudberry) 03/09: gpcheckcat shouldn't throw dependency error for pg_subscription and pg_transform

Posted by yj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 9a608506f8126f5578099464d90c92f7bbfcc477
Author: Huansong Fu <fu...@gmail.com>
AuthorDate: Mon Jul 10 07:21:04 2023 -0700

    gpcheckcat shouldn't throw dependency error for pg_subscription and pg_transform
    
    Objects in these two catalogs do not have pg_depend nor pg_shdepend entries. We should
    ignore the dependency check for them like a few others.
    
    Fix https://github.com/greenplum-db/gpdb/issues/12016
---
 gpMgmt/bin/gppylib/gpcatalog.py                  |  4 +++-
 gpMgmt/test/behave/mgmt_utils/gpcheckcat.feature | 12 +++++++++---
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/gpMgmt/bin/gppylib/gpcatalog.py b/gpMgmt/bin/gppylib/gpcatalog.py
index 45a4ae7e4b..dc95de34e8 100644
--- a/gpMgmt/bin/gppylib/gpcatalog.py
+++ b/gpMgmt/bin/gppylib/gpcatalog.py
@@ -83,7 +83,9 @@ DEPENDENCY_EXCLUSION = [
     'pg_resourcetype',
     'pg_resqueue',
     'pg_resqueuecapability',
-    'pg_tablespace'
+    'pg_subscription',
+    'pg_tablespace',
+    'pg_transform'
     ]
 
 # ============================================================================
diff --git a/gpMgmt/test/behave/mgmt_utils/gpcheckcat.feature b/gpMgmt/test/behave/mgmt_utils/gpcheckcat.feature
index ee65155a02..4df8489209 100644
--- a/gpMgmt/test/behave/mgmt_utils/gpcheckcat.feature
+++ b/gpMgmt/test/behave/mgmt_utils/gpcheckcat.feature
@@ -633,17 +633,23 @@ Feature: gpcheckcat tests
         Then gpcheckcat should return a return code of 3
         And the user runs "dropdb mis_attr_db"
 
-    Scenario: gpcheckcat should not report dependency error from pg_default_acl
+    Scenario: gpcheckcat should not report dependency error from pg_default_acl, pg_subscription and pg_transform
         Given database "check_dependency_error" is dropped and recreated
         And the user runs "psql -d check_dependency_error -c "CREATE ROLE foo; ALTER DEFAULT PRIVILEGES FOR ROLE foo REVOKE EXECUTE ON FUNCTIONS FROM PUBLIC;""
         Then psql should return a return code of 0
-        When the user runs "gpcheckcat check_dependency_error"
+        And the user runs "psql -d check_dependency_error -c "CREATE SUBSCRIPTION foo CONNECTION '' PUBLICATION bar WITH (connect = false, slot_name = NONE);""
+        Then psql should return a return code of 0
+        And the user runs "psql -d check_dependency_error -c "CREATE TRANSFORM FOR int LANGUAGE SQL (FROM SQL WITH FUNCTION prsd_lextype(internal), TO SQL WITH FUNCTION int4recv(internal));""
+        Then psql should return a return code of 0
+        When the user runs "gpcheckcat -R dependency check_dependency_error"
         Then gpcheckcat should return a return code of 0
         And gpcheckcat should not print "SUMMARY REPORT: FAILED" to stdout
         And gpcheckcat should not print "has a dependency issue on oid" to stdout
         And gpcheckcat should print "Found no catalog issue" to stdout
+        And the user runs "psql -d check_dependency_error -c "DROP SUBSCRIPTION foo""
+        And the user runs "psql -d check_dependency_error -c "DROP TRANSFORM FOR int LANGUAGE SQL""
         And the user runs "dropdb check_dependency_error"
-        And the user runs "psql -c "DROP ROLE foo""
+        And the user runs "psql -d postgres -c "DROP ROLE foo""
 
 
 ########################### @concourse_cluster tests ###########################


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org