Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Apache Shardingsphere CreateTablePushDownMetaDataRefresher Refresh

From Leeroopedia


Knowledge Sources
Domains Metadata_Management, DDL_Processing
Last Updated 2026-02-10 00:00 GMT

Overview

Concrete tool for reloading table metadata from the actual database after a CREATE TABLE DDL statement, provided by the ShardingSphere mode-core module. This page documents CreateTablePushDownMetaDataRefresher as the representative example; AlterTablePushDownMetaDataRefresher and DropTablePushDownMetaDataRefresher follow similar patterns.

Description

CreateTablePushDownMetaDataRefresher implements the PushDownMetaDataRefresher<CreateTableStatement> SPI interface. When triggered after a CREATE TABLE statement, it:

  1. Extracts the table name from the SQL statement, applying database-type-specific identifier formatting.
  2. Clones the rule metadata and checks whether the table is a single table (not distributed). If so, it registers the table's data node mapping in the MutableDataNodeRuleAttribute.
  3. Invokes GenericSchemaBuilder.build() to connect to the actual database and load the complete table metadata (columns, indexes, constraints).
  4. Calls metaDataManagerPersistService.createTable() to persist the loaded table metadata to the cluster repository.

The sibling classes work similarly:

  • AlterTablePushDownMetaDataRefresher (lines 44-79): Handles ALTER TABLE including RENAME scenarios. When a rename is present, it loads the renamed table and drops the old table name.
  • DropTablePushDownMetaDataRefresher (lines 33-46): Collects all table names from the DROP TABLE statement and calls dropTables() without reloading metadata.

Usage

This refresher is invoked automatically by PushDownMetaDataRefreshEngine via SPI when a CreateTableStatement is processed. It should not be called directly.

Code Reference

Source Location

  • Repository: Apache ShardingSphere
  • File (Create): mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/pushdown/type/table/CreateTablePushDownMetaDataRefresher.java
  • Lines: 42-67
  • File (Alter): mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/pushdown/type/table/AlterTablePushDownMetaDataRefresher.java
  • Lines: 44-79
  • File (Drop): mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/pushdown/type/table/DropTablePushDownMetaDataRefresher.java
  • Lines: 33-46

Signature (CreateTablePushDownMetaDataRefresher)

public final class CreateTablePushDownMetaDataRefresher
        implements PushDownMetaDataRefresher<CreateTableStatement> {

    @Override
    public void refresh(final MetaDataManagerPersistService metaDataManagerPersistService,
                        final ShardingSphereDatabase database,
                        final String logicDataSourceName,
                        final String schemaName,
                        final DatabaseType databaseType,
                        final CreateTableStatement sqlStatement,
                        final ConfigurationProperties props) throws SQLException

    @Override
    public Class<CreateTableStatement> getType()
}

Signature (AlterTablePushDownMetaDataRefresher)

public final class AlterTablePushDownMetaDataRefresher
        implements PushDownMetaDataRefresher<AlterTableStatement> {

    @Override
    public void refresh(final MetaDataManagerPersistService metaDataManagerPersistService,
                        final ShardingSphereDatabase database,
                        final String logicDataSourceName,
                        final String schemaName,
                        final DatabaseType databaseType,
                        final AlterTableStatement sqlStatement,
                        final ConfigurationProperties props) throws SQLException

    @Override
    public Class<AlterTableStatement> getType()
}

Signature (DropTablePushDownMetaDataRefresher)

public final class DropTablePushDownMetaDataRefresher
        implements PushDownMetaDataRefresher<DropTableStatement> {

    @Override
    public void refresh(final MetaDataManagerPersistService metaDataManagerPersistService,
                        final ShardingSphereDatabase database,
                        final String logicDataSourceName,
                        final String schemaName,
                        final DatabaseType databaseType,
                        final DropTableStatement sqlStatement,
                        final ConfigurationProperties props)

    @Override
    public Class<DropTableStatement> getType()
}

Import

import org.apache.shardingsphere.mode.metadata.refresher.pushdown.type.table.CreateTablePushDownMetaDataRefresher;
import org.apache.shardingsphere.mode.metadata.refresher.pushdown.type.table.AlterTablePushDownMetaDataRefresher;
import org.apache.shardingsphere.mode.metadata.refresher.pushdown.type.table.DropTablePushDownMetaDataRefresher;

I/O Contract

Inputs (refresh - CreateTable)

Name Type Required Description
metaDataManagerPersistService MetaDataManagerPersistService Yes Service for persisting newly created table metadata
database ShardingSphereDatabase Yes Database containing resource metadata, storage units, and rule configuration
logicDataSourceName String Yes Logical data source name for single table data node registration
schemaName String Yes Target schema where the table was created
databaseType DatabaseType Yes Actual database type for identifier formatting
sqlStatement CreateTableStatement Yes Parsed CREATE TABLE statement containing the table name
props ConfigurationProperties Yes Configuration properties for the schema builder

Outputs

Name Type Description
return void No return value; table metadata is loaded from database and persisted
exception SQLException Thrown if the database cannot be queried for table metadata

Usage Examples

// This refresher is invoked automatically by PushDownMetaDataRefreshEngine.
// Direct usage is not typical, but the internal flow is:

CreateTablePushDownMetaDataRefresher refresher = new CreateTablePushDownMetaDataRefresher();

// Called by the engine after SPI lookup
refresher.refresh(metaDataManagerPersistService, database,
    logicDataSourceName, schemaName, databaseType, createTableStatement, props);

// Internally, GenericSchemaBuilder queries the actual database:
// GenericSchemaBuilder.build(Collections.singletonList(tableName),
//     database.getProtocolType(), material);

Related Pages

Implements Principle

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment