terrymanu commented on issue #30939:
URL:
https://github.com/apache/shardingsphere/issues/30939#issuecomment-3641614132
## Problem Understanding
- In 5.4.1 (JDBC) with check-table-metadata-enabled on, aggregating
multiple physical tables for a logic table throws a metadata consistency error
even though the physical table structures look identical. Master still
misjudges this scenario.
## Root Cause
- Consistency check still relies on TableMetaData toString/reference
comparison, but TableMetaData and its members have no value-based
equals/hashCode. When identical structures are loaded as different instances or
use different collection implementations/orders (e.g.,
WrappedSet), comparison returns false and triggers a false positive.
## Analysis
- Check entry: SchemaTableMetaDataAggregator.checkUniformed (master) uses
sample.toString().equals(each.toString()). Lacking value comparison means
multi-shard identical tables are deemed inconsistent.
- Config reference (default is off): check-table-metadata-enabled
(https://shardingsphere.apache.org/document/current/en/user-manual/common-config/props/#check-table-metadata-enabled).
With it enabled, the above comparison path runs and currently misfires.
- Usage note: keep the property off in daily use (default) and only enable
briefly during schema-change windows to reduce false positives.
## Conclusion
- This remains a real defect on master caused by missing content-based
comparison.
- Temporary workaround: keep check-table-metadata-enabled: false, or
enable only briefly during change windows.
- Fix suggestion: add value-semantics comparison for metadata models or
switch the check to field-by-field comparison instead of toString/reference.
Example approach:
```java
// Illustrative idea: use field-level comparison instead of
toString/reference
private boolean isSame(TableMetaData a, TableMetaData b) {
return a.getName().equals(b.getName())
&& columnsEqual(a.getColumns(), b.getColumns())
&& indexesEqual(a.getIndexes(), b.getIndexes())
&& constraintsEqual(a.getConstraints(), b.getConstraints())
&& a.getType() == b.getType();
}
```
- We warmly invite community contributors to submit a PR implementing
value-based comparison plus unit tests to ensure no false positives when the
check is enabled.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]