menghaoranss opened a new pull request, #38690:
URL: https://github.com/apache/shardingsphere/pull/38690

   
   Changes proposed in this pull request:
   
   This PR refines metadata reload and persistence behavior after storage 
unit/rule changes, and updates related tests in `mode/core`, 
`mode/type/cluster/core`, and `mode/type/standalone/core`.
   
   ## Motivation
   The previous reload flow could persist schema/table metadata too early in 
some paths.  
   If step-1 operations failed (for example during storage-unit unload), 
in-memory schema tables and registry-persisted schema tables could become 
inconsistent across nodes.
   
   This PR enforces a safer sequencing:
   1. apply storage/rule changes,
   2. rebuild schema index from updated runtime metadata,
   3. compare old/new schema tables and persist deltas in the second stage.
   
   ## Main Functional Changes
   
   ### 1) Core metadata reload flow (`mode/core`)
   - Refined `MetaDataContextsFactory` related rebuild entry points.
   - Removed/cleaned obsolete checked-exception behavior on changed-database 
creation path.
   - Kept `ContextManager` reload call-site semantics that still require the 
non-registry direct reload behavior (the existing `false` path expectation).
   
   ### 2) Cluster persistence path (`mode/type/cluster/core`)
   - In `ClusterMetaDataManagerPersistService`, adjusted persistence behavior 
to rely on rebuilt schema index in the reload stage instead of unsafe direct 
full-database persistence ordering.
   - Ensured schema/table persistence is aligned with post-update rebuild 
results.
   
   ### 3) Standalone persistence path (`mode/type/standalone/core`)
   - Aligned standalone behavior with the same staged schema persistence 
principle.
   - `StandaloneMetaDataManagerPersistService` uses rebuilt schema index in 
reload-related persistence paths consistently.
   
   ## Test Fixes
   
   ### `mode/core` tests
   - Updated exception expectations after checked-exception path cleanup.
   - Fixed tests around metadata/rule refresh:
     - `MetaDataContextsFactoryTest`
     - `DatabaseRuleConfigurationManagerTest`
     - related `ContextManager` / `StorageUnitManager` tests impacted by reload 
semantics.
   
   ### `mode/type/standalone/core` tests
   - Fixed `StandaloneMetaDataManagerPersistServiceTest` for schema-index 
rebuild prerequisites:
     - added valid protocol type in mock database where needed,
     - added rule attributes stubs (`RuleAttributes`) where rebuild path 
requires them,
     - replaced fragile deep-stub metadata path with concrete 
`ShardingSphereMetaData` + `ConfigurationProperties` in affected cases.
   
   ### `mode/type/cluster/core` tests
   - Fixed 
`ClusterMetaDataManagerPersistServiceTest.assertAlterRuleConfiguration`:
     - provided protocol type (`MySQL`) for schema rebuild,
     - provided non-null rule attributes,
     - provided concrete metadata props context to avoid NPE during schema 
rebuild material creation.
   
   ## Behavior/Consistency Impact
   - Reduces risk of divergence between:
     - in-memory schema/table metadata of running nodes, and
     - registry-persisted schema/table metadata loaded by newly started nodes.
   - Keeps rule/storage update + metadata persistence ordering deterministic.
   
   ## Verification
   Targeted tests executed for impacted areas, including:
   - `DatabaseRuleConfigurationManagerTest`
   - `MetaDataContextsFactoryTest`
   - `StandaloneMetaDataManagerPersistServiceTest`
   - `StandaloneContextManagerBuilderTest`
   - `StandalonePersistServiceFacadeBuilderTest`
   - `StandaloneProcessPersistServiceTest`
   - `ClusterMetaDataManagerPersistServiceTest#assertAlterRuleConfiguration`
   
   All targeted runs passed in the validated environment after fixes.
   
   ---
   
   Before committing this PR, I'm sure that I have checked the following 
options:
   - [ ] My code follows the [code of 
conduct](https://shardingsphere.apache.org/community/en/involved/conduct/code/) 
of this project.
   - [ ] I have self-reviewed the commit code.
   - [ ] I have (or in comment I request) added corresponding labels for the 
pull request.
   - [ ] I have passed maven check locally : `./mvnw clean install -B -T1C 
-Dmaven.javadoc.skip -Dmaven.jacoco.skip -e`.
   - [ ] I have made corresponding changes to the documentation.
   - [ ] I have added corresponding unit tests for my changes.
   - [ ] I have updated the Release Notes of the current development version. 
For more details, see [Update Release 
Note](https://shardingsphere.apache.org/community/en/involved/contribute/contributor/)
   


-- 
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]

Reply via email to