apache/shardingsphere · error · StorageUnitsOperateException
0
0
Error message
Can not alter storage units '%s'.
What it means
Error "Can not alter storage units '%s'." thrown in apache/shardingsphere.
Source
Thrown at infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/AlterStorageUnitExecutor.java:69
/**
* Alter storage unit executor.
*/
@Setter
public final class AlterStorageUnitExecutor implements DistSQLUpdateExecutor<AlterStorageUnitStatement>, DistSQLExecutorDatabaseAware {
private final DistSQLDataSourcePoolPropertiesValidator validateHandler = new DistSQLDataSourcePoolPropertiesValidator();
private ShardingSphereDatabase database;
@Override
public void executeUpdate(final AlterStorageUnitStatement sqlStatement, final ContextManager contextManager) {
checkBefore(sqlStatement);
Map<String, DataSourcePoolProperties> propsMap = DataSourceSegmentsConverter.convert(database.getProtocolType(), sqlStatement.getStorageUnits());
validateHandler.validate(propsMap, getExpectedPrivileges(sqlStatement));
try {
contextManager.getPersistServiceFacade().getModeFacade().getMetaDataManagerService().alterStorageUnits(database, propsMap);
} catch (final ShardingSphereExternalException ex) {
throw new StorageUnitsOperateException("alter", propsMap.keySet(), ex);
}
}
private void checkBefore(final AlterStorageUnitStatement sqlStatement) {
Collection<String> toBeAlteredStorageUnitNames = sqlStatement.getStorageUnits().stream().map(DataSourceSegment::getName).collect(Collectors.toList());
checkDuplicatedStorageUnitNames(toBeAlteredStorageUnitNames);
checkStorageUnitNameExisted(toBeAlteredStorageUnitNames);
checkDatabase(sqlStatement);
}
private void checkDuplicatedStorageUnitNames(final Collection<String> storageUnitNames) {
Collection<String> duplicatedStorageUnitNames = storageUnitNames.stream().filter(each -> storageUnitNames.stream().filter(each::equals).count() > 1L).collect(Collectors.toList());
ShardingSpherePreconditions.checkMustEmpty(duplicatedStorageUnitNames, () -> new DuplicateStorageUnitException(database.getName(), duplicatedStorageUnitNames));
}
private void checkStorageUnitNameExisted(final Collection<String> storageUnitNames) {
Collection<String> notExistedStorageUnitNames = storageUnitNames.stream().filter(each -> !database.getResourceMetaData().getStorageUnits().containsKey(each)).collect(Collectors.toList());
ShardingSpherePreconditions.checkMustEmpty(notExistedStorageUnitNames, () -> new MissingRequiredStorageUnitsException(database.getName(), notExistedStorageUnitNames));View on GitHub (pinned to e952770a21)
Solutions
- Ensure the storage units exist before altering them (SHOW STORAGE UNITS).
- Correct the storage unit names in the ALTER STORAGE UNIT statement.
- Verify the new data source properties are valid so the alter can succeed.
When it happens
Trigger: ALTER STORAGE UNIT fails because the named storage units do not exist or their new configuration is invalid.
Common situations: Misspelled storage unit name or invalid JDBC properties supplied in a DistSQL ALTER STORAGE UNIT statement.
AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14).
Data as JSON: /api/errors/5ddcd7cee1287432.
Report an issue: GitHub.