Overview
Concrete tool for determining whether a DDL statement requires metadata refresh and orchestrating the refresh pipeline, provided by the ShardingSphere mode-core module.
Description
PushDownMetaDataRefreshEngine is the entry point for the metadata refresh workflow after DDL execution. It maintains a static set of 13 supported DDL statement classes (SUPPORTED_REFRESH_TYPES) covering table, view, index, and schema DDL operations. The class exposes two primary methods:
- isNeedRefresh() performs a constant-time HashSet lookup to check if the current SQL statement class belongs to the supported DDL types.
- refresh() orchestrates the full refresh pipeline: it looks up a type-specific PushDownMetaDataRefresher via the SPI mechanism, resolves the schema name and database type from route units, and delegates to the refresher to reload metadata from the actual database and persist the changes.
The engine is constructed with an SQLStatementContext and is designed as a final class with constructor injection via @RequiredArgsConstructor.
Usage
Use this class after a DDL statement has been executed against the backend database. First call isNeedRefresh() to check whether metadata refresh is needed. If it returns true, call refresh() with the persistence service, database, configuration properties, and route units.
Code Reference
Source Location
- Repository: Apache ShardingSphere
- File:
mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/pushdown/PushDownMetaDataRefreshEngine.java
- Lines: 56-103
Signature
public final class PushDownMetaDataRefreshEngine {
public boolean isNeedRefresh()
public void refresh(final MetaDataManagerPersistService metaDataManagerPersistService,
final ShardingSphereDatabase database,
final ConfigurationProperties props,
final Collection<RouteUnit> routeUnits) throws SQLException
}
Import
import org.apache.shardingsphere.mode.metadata.refresher.pushdown.PushDownMetaDataRefreshEngine;
I/O Contract
Inputs (Constructor)
| Name |
Type |
Required |
Description
|
| sqlStatementContext |
SQLStatementContext |
Yes |
The context wrapping the parsed SQL statement to evaluate for metadata refresh
|
Inputs (isNeedRefresh)
| Name |
Type |
Required |
Description
|
| (none) |
|
|
Uses the sqlStatementContext provided at construction time
|
Outputs (isNeedRefresh)
| Name |
Type |
Description
|
| return |
boolean |
True if the SQL statement class is in the supported DDL types set; false otherwise
|
Inputs (refresh)
| Name |
Type |
Required |
Description
|
| metaDataManagerPersistService |
MetaDataManagerPersistService |
Yes |
Service for persisting metadata changes to the repository
|
| database |
ShardingSphereDatabase |
Yes |
The database whose metadata may need refreshing
|
| props |
ConfigurationProperties |
Yes |
System configuration properties
|
| routeUnits |
Collection<RouteUnit> |
Yes |
The route units from query execution, used to determine data source and database type
|
Outputs (refresh)
| Name |
Type |
Description
|
| return |
void |
No return value; metadata is refreshed as a side effect
|
| exception |
SQLException |
Thrown if the metadata reload from the database fails
|
Usage Examples
// After DDL execution, check and refresh metadata
PushDownMetaDataRefreshEngine refreshEngine = new PushDownMetaDataRefreshEngine(sqlStatementContext);
if (refreshEngine.isNeedRefresh()) {
refreshEngine.refresh(metaDataManagerPersistService, database, props, routeUnits);
}
Related Pages
Implements Principle
Uses Heuristic
Page Connections
Double-click a node to navigate. Hold to expand connections.