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 276d6a855ad8c6aa05522491e98a5fdba3187507
Author: Nihal Jain <[email protected]>
AuthorDate: Wed Nov 2 13:44:42 2022 +0530

    Add numsegments check for gpcheckcat
    
    For a partitioned table to have a correct distribution policy, the 
numsegments value for all root, middle and leaf level partitions must be equal. 
This commit adds this check for gpcheckcat. Readable external partitions are 
excluded from this check.
    
    Sample log output for numsegments check failure:
    20221103:11:36:30:098659 gpcheckcat:jnihal-a01:jnihal-[INFO]:-[FAIL] 
partition numsegments check
    20221103:11:36:30:098659 gpcheckcat:jnihal-a01:jnihal-[ERROR]:-partition 
numsegments check found 1 issue(s)
    [ERROR]: child partition(s) have different numsegments value from the root 
partition. Check the gpcheckcat log for details.
    20221103:11:36:30:098659 gpcheckcat:jnihal-a01:jnihal-[ERROR]:-The 
following tables have different numsegments value:
    20221103:11:36:30:098659 gpcheckcat:jnihal-a01:jnihal-[ERROR]:---------
    20221103:11:36:30:098659 gpcheckcat:jnihal-a01:jnihal-[ERROR]:-  table | 
affected child | parent numsegments value | child numsegments value
    20221103:11:36:30:098659 gpcheckcat:jnihal-a01:jnihal-[ERROR]:-  
------+----------------+--------------------------+------------------------
    20221103:11:36:30:098659 gpcheckcat:jnihal-a01:jnihal-[ERROR]:-  
public.sales_1_prt_10 | public.sales_1_prt_10_2_prt_asia | 3 | 1
---
 gpMgmt/bin/gpcheckcat                            | 63 ++++++++++++++++++++++++
 gpMgmt/test/behave/mgmt_utils/gpcheckcat.feature | 17 +++++++
 2 files changed, 80 insertions(+)

diff --git a/gpMgmt/bin/gpcheckcat b/gpMgmt/bin/gpcheckcat
index da0d56479b..8da2a0298a 100755
--- a/gpMgmt/bin/gpcheckcat
+++ b/gpMgmt/bin/gpcheckcat
@@ -563,6 +563,69 @@ def checkPartitionIntegrity():
     err = []
     db = connect()
 
+    # Check for the numsegments value of parent and child partition from the 
gp_distribution_policy table
+    qry = '''
+    select inhparent::regclass, inhrelid::regclass, parent.numsegments as 
numsegments_parent, child.numsegments as numsegments_child
+    from pg_inherits inner join pg_partitioned_table on (pg_inherits.inhparent 
= pg_partitioned_table.partrelid)
+                     inner join gp_distribution_policy parent on 
(parent.localoid = inhparent)
+                     inner join gp_distribution_policy child on 
(child.localoid = inhrelid)
+    where parent.numsegments is distinct from child.numsegments
+          and not (inhrelid in (select ftrelid from 
pg_catalog.pg_foreign_table) and child.numsegments = NULL);
+    '''
+    try:
+        curs = db.query(qry)
+        cols = ('inhparent', 'inhrelid', 'numsegments_parent', 
'numsegments_child')
+        col_names = {
+            'inhparent': 'table',
+            'inhrelid': 'affected child',
+            'numsegments_parent': 'parent numsegments value',
+            'numsegments_child': 'child numsegments value',
+        }
+
+        err = []
+        for row in curs.dictresult():
+            err.append([GV.cfg[GV.coordinator_dbid], cols, row])
+
+        if not err:
+            logger.info('[OK] partition numsegments check')
+        else:
+            err_count = len(err)
+            GV.checkStatus = False
+            setError(ERROR_REMOVE)
+            logger.info('[FAIL] partition numsegments check')
+            logger.error('partition numsegments check found %d issue(s)' % 
err_count)
+            if err_count > 100:
+                logger.error(qry)
+
+            myprint(
+                '[ERROR]: child partition(s) have different numsegments value '
+                'from the root partition. Check the gpcheckcat log for 
details.'
+            )
+            logger.error('The following tables have different numsegments 
value (showing at most 100 rows):')
+
+            # report at most 100 rows, for brevity
+            err = err[:100]
+
+            for index, e in enumerate(err):
+                cfg = e[0]
+                col = e[1]
+                row = e[2]
+
+                if index == 0:
+                    logger.error("--------")
+                    logger.error("  " + " | ".join(map(col_names.get, col)))
+                    logger.error("  " + "-+-".join(['-' * len(col_names[x]) 
for x in col]))
+
+                logger.error("  " + " | ".join([str(row[x]) for x in col]))
+
+            if err_count > 100:
+                logger.error(" ...")
+
+    except Exception as e:
+        setError(ERROR_NOREPAIR)
+        myprint('[ERROR] executing test: checkPartitionIntegrity')
+        myprint('  Execution error: ' + str(e))
+
     # Check for the distribution policy of parent and child partitions based 
on the following conditions:
     #   1. If a root is randomly distributed, then all middle, leaf level 
partitions must also be randomly distributed
     #   2. If a root is hash distributed, then middle level should be same as 
root and
diff --git a/gpMgmt/test/behave/mgmt_utils/gpcheckcat.feature 
b/gpMgmt/test/behave/mgmt_utils/gpcheckcat.feature
index 8645f720db..0baa0278c7 100644
--- a/gpMgmt/test/behave/mgmt_utils/gpcheckcat.feature
+++ b/gpMgmt/test/behave/mgmt_utils/gpcheckcat.feature
@@ -232,6 +232,23 @@ Feature: gpcheckcat tests
         And gpcheckcat should not print "Failed test\(s\) that are not 
reported here: part_integrity" to stdout
         And the user runs "dropdb policy_db"
 
+    Scenario: gpcheckcat should report when parent and child partitions have 
different numsegments value
+        Given database "policy_db" is dropped and recreated
+        And the user runs "psql policy_db -f 
test/behave/mgmt_utils/steps/data/gpcheckcat/create_multilevel_partition.sql"
+        Then psql should return a return code of 0
+        When the user runs "gpcheckcat -R part_integrity policy_db"
+        Then gpcheckcat should return a return code of 0
+        And gpcheckcat should not print "child partition\(s\) have different 
numsegments value from the root partition" to stdout
+        And gpcheckcat should not print "Failed test\(s\) that are not 
reported here: part_integrity" to stdout
+
+        And the user runs sql "set allow_system_table_mods=true; update 
gp_distribution_policy set numsegments = '1' where 
localoid='sales_1_prt_2'::regclass::oid;" in "policy_db" on all the segments
+        Then psql should return a return code of 0
+        When the user runs "gpcheckcat -R part_integrity policy_db"
+        Then gpcheckcat should return a return code of 1
+        And gpcheckcat should print "child partition\(s\) have different 
numsegments value from the root partition" to stdout
+        And gpcheckcat should print "Failed test\(s\) that are not reported 
here: part_integrity" to stdout
+        And the user runs "dropdb policy_db"
+
     Scenario: gpcheckcat foreign key check should report missing catalog 
entries. Also test missing_extraneous for the same case.
         Given database "fkey_db" is dropped and recreated
         And the path "gpcheckcat.repair.*" is removed from current working 
directory


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

Reply via email to