Repository navigation
Fix false positive of table metadata consistency check - #40549
Conversation
Add the bug fix entry for the table metadata consistency check.
Table metadata consistency was checked by comparing toString() output, which depends on the collection implementation and iteration order. The PostgreSQL and openGauss loaders pass Multimap views as indexes and constraints, while the core loader passes HashMap values, so identical structures could be reported as inconsistent. Compare metadata by value instead: columns keep their JDBC ordinal order, while indexes and constraints are compared as unordered collections. Value-based equals and hashCode are restored for column, index and constraint models.
c21e5e6 to
3accf1c
Compare
terrymanu
left a comment
There was a problem hiding this comment.
Summary
This PR replaces toString() comparison with value-based comparison to eliminate false metadata inconsistency reports caused by different index and constraint iteration orders. The direction has maintainer support, but the review confirmed a missed composite-index mismatch, an existing test regression, and insufficient regression coverage.
Result
Review Result: Not Mergeable
Feedback Mode: Change Request
Review Status: Not Converged
Confirmed Blocking Issues: 3
The findings below are a confirmed subset. The current head Git object is unavailable locally, preventing the required ledger and session validation. The formal review therefore cannot be declared fully converged.
Blocking Issues
[P2] Preserve column order within composite indexes
Evidence: The Lombok equality introduced at IndexMetaData.java:35 delegates directly to columns.equals(). The encryption reviser produces a LinkedHashSet, and subsequent broadcast-table aggregation executes the new comparison. An exact-source reproduction confirmed that the candidate accepts [a,b] and [b,a], whereas the baseline aggregator rejects them.
Impact: With metadata consistency checking enabled, encrypted broadcast tables with different composite-index structures are incorrectly considered consistent.
Required Change: Compare columns within each index as an ordered sequence and add a regression test for this production path. Continue ignoring order in the outer index collection.
[P2] Update the affected sharding aggregation test fixture
Evidence: ShardingSchemaTableAggregationReviserTest.java:78 constructs metadata with null collections. The new logic throws NullPointerException while comparing the sample with itself, failing the test that expects RuleAndStorageMetaDataMismatchedException. Direct execution passed 2/3 tests with the candidate and 3/3 after substituting the baseline aggregator.
Impact: The PR introduces an existing-test regression. There is currently no evidence that normal production paths supply these null collections.
Required Change: Express the fixture’s structural mismatch using non-null collections while preserving the original exception assertion.
[P2] Add regression coverage for the new structural comparison decisions
Evidence: The cases added at SchemaTableMetaDataAggregatorTest.java:76 do not protect same-name tables with different column definitions, different column orders, different table types, or an additional index in the actual table. An existing broadcast test covers differing column counts, so column-comparison rejection is not entirely uncovered.
Impact: These new decisions lack necessary regression protection and do not satisfy the repository’s requirement for complete coverage of owned behavior.
Required Change: Add the four distinct scenarios above. One meaningful collection-size mismatch case is sufficient for the shared comparison helper; duplicate coverage is unnecessary.
Coverage
Public head: 3accf1c49196d3effdc60e2cdaab7fcba1e5bc55. All 6 changed files and relevant consumers were inspected. Checkstyle and Spotless passed for all 5 Java files, both with exit code 0. Neither configured check governs the release notes.
Exact-source JUnit verification: aggregator 8/8, sharding 2/3, broadcast 3/3. Two focused Maven test attempts timed out with exit code 124; the full build was not completed.
This assessment covers code correctness only; CI was not reviewed. Ledger and session validation remain incomplete. No repository changes or remote comments were made.
Compare composite index columns as an ordered sequence instead of relying on Collection.equals(), which ignores order for Set backed columns such as the LinkedHashSet produced by EncryptIndexReviser. The outer index and constraint collections stay order-insensitive. Replace the null collections in ShardingSchemaTableAggregationReviserTest with empty collections, and add regression cases for composite index column order, column definition, column order, table type and an additional index.
|
Addressed the three blocking items in 3c2832c. Composite index column order. Sharding fixture. Regression coverage. Added column definition ( Verification: CI has no result yet: all six workflows on @terrymanu re-review requested on |
|
All checks on 3c2832c are green: CI, CheckStyle, Spotless, License and the E2E SQL/Agent matrices (85 check runs: 83 success, 2 skipped matrix placeholders, 0 failures). @terrymanu re-review requested. |
terrymanu
left a comment
There was a problem hiding this comment.
Summary
This PR replaces string-based metadata comparison with value-based comparison, ignoring the outer ordering of indexes and constraints while preserving column and composite-index column order. The direction matches the maintainer-confirmed goal, and all 19 relevant tests pass. One regression-coverage gap and four coding-rule violations remain.
Result
Review Result: Not Mergeable
Feedback Mode: Change Request
Blocking Issues: 5
Blocking Issues
[P2] Add regression coverage for the custom hash calculation
- Evidence: IndexMetaData.java:64 introduces handwritten hash calculation, while the existing aggregation tests only verify comparison results.
- Impact: The equal-hash contract lacks regression protection when identical ordered columns are represented by List and LinkedHashSet.
- Required Change: Add focused tests for this equals/hashCode contract. Unequal objects do not need to produce different hashes.
[P2] Remove the null branch without a supporting contract
- Evidence: IndexMetaData.java:69 returns null for a null column collection. No supported production path or nullable contract was found for that state.
- Impact: This violates the default non-null contract and defensive-code rules.
- Required Change: Remove the newly introduced null branch while preserving ordered collection conversion.
[P2] Inline the test helper that only forwards constructor arguments
- Evidence: SchemaTableMetaDataAggregatorTest.java:202 forwards all four arguments unchanged and provides no shared fixture setup.
- Impact: This violates the implementation rule against unnecessary thin wrappers.
- Required Change: Invoke the existing constructor directly at the call sites.
[P2] Place the single-caller helper immediately after its caller
- Evidence: SchemaTableMetaDataAggregatorTest.java:207 is called only by the table-type test at line 166, but other tests and helpers separate them.
- Impact: This violates the declaration-order rule requiring private helpers to immediately follow their callers.
- Required Change: Move this helper immediately after the table-type test.
[P2] Remove the unnecessary line break under the explicit wrapping rule
- Evidence: The return expression at SchemaTableMetaDataAggregator.java:68 contains 235 characters in total; combining its first two lines produces only 161 characters.
- Impact: The three-line layout violates the minimum-line-break rule. Passing Spotless does not cover this manual check. This issue existed in the previous version and was missed in the previous review.
- Required Change: Combine the first two lines of the expression.
Coverage
Public head: 3c2832cf2bf438506609d80a0261c3b460bcc760. All seven changed files and relevant consumers were reviewed.
Checkstyle and Spotless covered all six Java files and passed with exit code 0. Neither check applies to the release notes. Exact-source execution against installed dependencies passed 19/19 tests. The regular Maven test attempt timed out during compilation (exit 124); the full build was not completed.
This assessment covers code correctness only; CI was not reviewed.
Add equals/hashCode contract coverage for ordered index columns, remove the null branch from the ordered comparison, inline the test helper that only forwarded constructor arguments, move the table-type helper next to its caller, and join the wrapped return expression.
|
Addressed the five blocking items in 93cf8b8. Hash contract coverage. Added Null branch. Removed Test helper inlined. Deleted the four-argument Helper placement. Line break. The first two lines of the return expression in Verification: CI for 93cf8b8 is |
|
/ci |
terrymanu
left a comment
There was a problem hiding this comment.
Correction
- Previous Finding or Conclusion: The P2 test-helper ordering issue blocked approval.
- Current Status: Withdrawn.
- Reason: The cleanup is explicitly accepted for the next PR and no longer blocks this review.
Summary
This PR fixes false metadata inconsistency reports by replacing string comparison with structural value comparison. It preserves table-column and composite-index column order while ignoring irrelevant outer ordering of indexes and constraints.
Result
Review Result: Mergeable
LGTM. No remaining blocking issues were identified within the reviewed code scope.
Evidence
- The comparison preserves meaningful metadata differences and collection multiplicity.
- Checkstyle and Spotless passed for all seven changed Java files.
- All 21 focused tests passed against the reviewed source.
Coverage
Public PR head: 93cf8b864d73baf16d38a5a008035a146a4c7185. All eight changed files were reviewed; verification results were reused for the unchanged head.
This is a code-correctness approval. CI was not reviewed, and the full build was not run.
Fixes #30939.
Changes proposed in this pull request:
SchemaTableMetaDataAggregatorinstead of comparingTableMetaData.toString().equals/hashCodeonColumnMetaData,IndexMetaDataandConstraintMetaData(present in 5.4.1, dropped when the metadata model moved todatabase/connector/core).ShardingSchemaTableAggregationReviserTestto express its structural mismatch with non-null collections.equalsis identity based, composite index column order, column definition, column order, table type and an additional index.Why
toString()is not a safe comparison:IndexMetaDataLoaderreturnsHashMap.values(), while the PostgreSQL and openGauss loaders passLinkedHashMultimap.get()views (GuavaWrappedSet) asindexesandconstraints.PostgreSQLMetaDataLoaderreadspg_indexeswithoutORDER BY.check-table-metadata-enabled: true, the check reportsRuleAndStorageMetaDataMismatchedExceptionfor identical structures.EncryptIndexReviserbuilds index columns as aLinkedHashSet, so the columns of one composite index must be compared as an ordered sequence rather than throughSet.equals().Verification:
SchemaTableMetaDataAggregatorTest(13/13),ShardingSchemaTableAggregationReviserTest(3/3) andBroadcastSchemaTableAggregationReviserTest(3/3) against the installed 5.5.4-SNAPSHOT module jars with the changed classes first on the classpath.3accf1cwithExpected RuleAndStorageMetaDataMismatchedException to be thrown, but nothing was thrownand passes on3c2832c; the null-fixture test fails withNullPointerExceptionon3accf1cand passes on3c2832c.spotless:checkwith the project Eclipse formatter config and Checkstyle 14.1.0 withsrc/resources/checkstyle.xmlreport 0 violations on the changed Java files../mvnw clean install -B -T1C -Pcheckwas not run locally (no full reactor build in this environment); the module build is left to CI.Before submitting this PR, I confirm that:
./mvnw clean install -B -T1C -Pcheck.AI assistance: DeepSeek Harness (deepseek-v4.1-flash) was used to analyze the metadata comparison path and to draft the code and test changes. Affected files:
SchemaTableMetaDataAggregator.java,ColumnMetaData.java,IndexMetaData.java,ConstraintMetaData.java,SchemaTableMetaDataAggregatorTest.java,ShardingSchemaTableAggregationReviserTest.java.