Skip to content

gpcheckcat: fix the defects the Behave suite exposes - #2182

Open
MisterRaindrop wants to merge 1 commit into
apache:mainfrom
MisterRaindrop:fix/gpcheckcat-behave-defects
Open

MisterRaindrop wants to merge 1 commit into
apache:mainfrom
MisterRaindrop:fix/gpcheckcat-behave-defects

Conversation

@MisterRaindrop

@MisterRaindrop MisterRaindrop commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Three gpcheckcat fixes that the gpMgmt Behave suite (#2170) exposes. They are in one commit, as they were in #1639. The commit message gives the full reasoning.

  1. Add the mix_distribution_policy check. This back-ports from Greenplum a check that Cloudberry was missing. It reports tables whose distribution policy mixes legacy and non-legacy hash opclasses, and it cross-checks the result against gp_use_legacy_hashops. The SQL fixtures its Behave scenarios load are added too. Greenplum's companion ao_lastrownums check is deliberately not brought over: it reads pg_attribute_encoding.lastrownums, which Cloudberry's catalog does not have.
  2. Attribute an append-optimized table's visimap to the table in the owner check. checkOwners() folds an AO table's auxiliary relations into the table, so an owner mismatch is reported, and repaired, once, on the table. It did not know the visimap relation or its index. The repair script it generated therefore also ran ALTER TABLE "pg_aoseg"."pg_aovisimap_<oid>" OWNER TO ..., and the server refuses that with permission denied: "pg_aovisimap_<oid>" is a system catalog. So gpcheckcat -R owner produced a repair that could not run.
  3. Give pg_shdescription its TableMainColumn entry. Without the entry, missing_extraneous looked shared descriptions up by oid, which pg_shdescription does not have, and it died with column "oid" does not exist.

Split out of #1639 (originally 0bfc1d7, by @tuhaihe).

One change from #1639: Greenplum's unit tests for the new check mock a psycopg2 cursor. This gpcheckcat reaches the database through PyGreSQL (conn.query() and getresult()) and never opens a cursor. As a result, three of those tests failed, and the rest passed without running the code they were meant to test. I rewrote them against conn.query() and added tests for a mixed policy, a consistent one, and a GUC that is read successfully.

What stays with #2170: in #1639 this commit also edited the Behave suite. It dropped the two ao_lastrownums scenarios, tagged the -x session GUC scenario (which Cloudberry no longer supports) @not_implemented, and added --tags ~@not_implemented to the gpcheckcat job in the workflow. Those edits apply to the suite as #2170 aligns it, so they are made in #2170.

This is one of five PRs that the remaining fixes from #1639 are grouped into, alongside #2178, #2180, #2183 (gprecoverseg) and #2184 (gprecoverseg Greenplum ports).

Test Plan

Rocky 9 build image, built from #2170's tree plus #2177 and #2178 (767f12685a4 and b971d481862, which the demo cluster needs) and #2180, with a demo cluster created the way the Behave workflow creates it. I took gpcheckcat.feature as #2170 now has it, with the edits described above, and removed the eight @needs_fix tags that point at this change. I then ran it with CI's arguments (--tags ~@extended --tags ~@not_implemented).

  • Run A has this commit reversed and the tree reinstalled into $GPHOME.
  • Run B has it applied and installed.
gpcheckcat.feature A: without B: with this PR
scenarios 59 passed, 8 failed 67 passed, 0 failed

Both runs skip one scenario, the -x one.

The eight scenarios that fail in A are the eight #2170 tags:

  • The six mix_distribution_policy scenarios (fix 1). The check does not exist without this PR.
  • "gpcheckcat should report and repair owner errors on appendonly tables and its indexes" (fix 2). The repair script fails on the visimap ALTER TABLE. I reproduced this by hand: without the fix, the repair SQL alters t, t_idx, pg_aovisimap_<oid> and pg_aovisimap_<oid>_index, and fails on the third. With it, only t and t_idx are altered and the script succeeds.
  • "gpcheckcat should discover missing attributes of pg_description and pg_shdescription catalogue table without errors" (fix 3).

Unit tests (python3 -m unittest, with PYTHONPATH set the way make -C gpMgmt/bin unitdevel sets it): test_unit_gpcheckcat passes with this PR, all 41 tests. Without it, the ten new tests error out because the functions they test do not exist. The whole gppylib unit suite, with this PR and #2180 applied together, has no new failures; the tests that fail in it fail the same way without these PRs.

#2170 tags these scenarios @needs_fix pointing at this change. Whichever PR lands second removes those tags.

Type of Change

  • Bug fix (non-breaking change)
  • New feature (non-breaking change): the mix_distribution_policy check

Checklist

  • This PR contains AI-assisted code generation

* gpcheckcat: add the mix_distribution_policy check

  Back-port from Greenplum a check Cloudberry was missing.
  mix_distribution_policy reports tables whose distribution policy mixes
  legacy and non-legacy hash opclasses, and cross-checks the result
  against the gp_use_legacy_hashops GUC so the operator is told which of
  the two states is inconsistent.

  Add the SQL fixtures the corresponding Behave scenarios load.

  Greenplum's unit tests for the check mock a psycopg2 cursor, but this
  gpcheckcat reaches the database through PyGreSQL (conn.query() and
  getresult()) and never opens a cursor, so three of them failed and the
  rest passed without exercising the code. They are rewritten against
  conn.query(), with tests added for a mixed policy, a clean one, and a
  GUC that is read successfully.

  Greenplum's companion ao_lastrownums check is deliberately not brought
  over: it reads pg_attribute_encoding.lastrownums, a column Cloudberry's
  catalog does not have, so the query errors out on every run and
  gpcheckcat reports failure on a freshly created database.

* gpcheckcat: give pg_shdescription its TableMainColumn entry

  TableMainColumn maps a catalog to the column that identifies the object
  an entry belongs to. Greenplum has a row for pg_description and one for
  pg_shdescription; Cloudberry has only the first. Without it,
  processMissingDuplicateEntryResult() falls through to getOidFromPK(),
  which looks the entry up by

      SELECT oid FROM pg_shdescription WHERE ...

  and pg_shdescription has no oid column, so missing_extraneous died with

      Execution error: ERROR:  column "oid" does not exist
      LINE 4:   SELECT oid FROM pg_shdescription

* gpcheckcat: attribute an AO table's visimap to the table in the owner check

  checkOwners() compares each relation's owner across segments, and
  folds an append-optimized table's auxiliary relations into the table
  they belong to, so a mismatch is reported, and repaired, once, on the
  table. It knew the segment relation, the block directory and the block
  directory's index, but not the visimap relation or its index. Those
  were reported as relations of their own, and the repair script tried

      ALTER TABLE "pg_aoseg"."pg_aovisimap_17032" OWNER TO "gpadmin";

  which the server refuses:

      ERROR:  permission denied: "pg_aovisimap_17032" is a system catalog

  so "gpcheckcat -R owner" on an append-optimized table whose owner
  differs on a segment produced a repair that could not run. Match the
  visimap and its index, and the block directory's index by the table it
  indexes. The repair is then the ALTER TABLE on the table itself, which
  carries its auxiliary relations with it.

  The feature-file half of this change -- dropping the two ao_lastrownums
  scenarios and tagging the -x session GUC scenario, which Cloudberry no
  longer supports -- edits the Behave suite as apache#2170 aligns it, so it goes
  with that PR.

Split out of apache#1639 (originally 0bfc1d7).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants