Implementation:Apache Shardingsphere MetaDataManagerPersistService Contract
| Knowledge Sources | |
|---|---|
| Domains | Persistence, SPI |
| Last Updated | 2026-02-10 00:00 GMT |
Overview
MetaDataManagerPersistService defines the SPI interface contract for all metadata persistence operations including database, schema, table, view, storage unit, and rule configuration management.
Description
MetaDataManagerPersistService is an interface in the mode/core module that declares methods for creating, dropping, altering, and renaming databases, schemas, tables, and views. It also provides methods for registering, altering, and unregistering storage units, as well as altering and removing rule configurations at both database and global levels. Implementations of this interface handle how configuration changes are initiated and persisted in different modes (standalone vs. cluster).
Usage
Use this interface as an SPI contract when implementing mode-specific metadata persistence. Standalone and cluster modes each provide their own implementation. Invoke these methods when processing DistSQL commands or DDL operations that require metadata changes to be persisted.
Code Reference
Source Location
- Repository: Apache_Shardingsphere
- File: MetaDataManagerPersistService.java
- Lines: 1-189
Signature
public interface MetaDataManagerPersistService {
void createDatabase(String databaseName);
void dropDatabase(ShardingSphereDatabase database);
void createSchema(ShardingSphereDatabase database, String schemaName);
void renameSchema(ShardingSphereDatabase database, String schemaName, String renameSchemaName);
void dropSchema(ShardingSphereDatabase database, Collection<String> schemaNames);
void createTable(ShardingSphereDatabase database, String schemaName, ShardingSphereTable table);
void dropTables(ShardingSphereDatabase database, String schemaName, Collection<String> tableNames);
void alterTables(ShardingSphereDatabase database, String schemaName, Collection<ShardingSphereTable> alteredTables);
void alterViews(ShardingSphereDatabase database, String schemaName, Collection<ShardingSphereView> alteredViews);
void dropViews(ShardingSphereDatabase database, String schemaName, Collection<String> droppedViews);
void registerStorageUnits(String databaseName, Map<String, DataSourcePoolProperties> toBeRegisteredProps);
void alterStorageUnits(ShardingSphereDatabase database, Map<String, DataSourcePoolProperties> toBeUpdatedProps);
void unregisterStorageUnits(ShardingSphereDatabase database, Collection<String> toBeDroppedStorageUnitNames);
void alterSingleRuleConfiguration(ShardingSphereDatabase database, RuleMetaData ruleMetaData);
void alterRuleConfiguration(ShardingSphereDatabase database, RuleConfiguration toBeAlteredRuleConfig);
void removeRuleConfigurationItem(ShardingSphereDatabase database, RuleConfiguration toBeRemovedRuleItemConfig);
void removeRuleConfiguration(ShardingSphereDatabase database, RuleConfiguration toBeRemovedRuleConfig, String ruleType);
void alterGlobalRuleConfiguration(RuleConfiguration globalRuleConfig);
void alterProperties(Properties props);
}
Import
import org.apache.shardingsphere.mode.persist.service.MetaDataManagerPersistService;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| databaseName | String | Yes | Name of the database to create or target |
| database | ShardingSphereDatabase | Yes | Database object for operations requiring existing database context |
| schemaName | String | Yes | Schema name for schema/table/view operations |
| table | ShardingSphereTable | Yes | Table metadata for create operations |
| toBeRegisteredProps | Map<String, DataSourcePoolProperties> | Yes | Storage unit properties for registration |
| toBeAlteredRuleConfig | RuleConfiguration | Yes | Rule configuration to alter |
| props | Properties | Yes | System properties to alter |
Outputs
| Name | Type | Description |
|---|---|---|
| void | void | All methods are void; side effects are persisted to the repository |
Usage Examples
// Create a new database via the persist service
metaDataManagerPersistService.createDatabase("new_database");
// Register storage units
Map<String, DataSourcePoolProperties> props = new HashMap<>();
props.put("ds_0", dataSourcePoolProperties);
metaDataManagerPersistService.registerStorageUnits("my_database", props);
// Alter a rule configuration
metaDataManagerPersistService.alterRuleConfiguration(database, shardingRuleConfig);