apache/shardingsphere · error · StorageUnitsOperateException

0

0

Error message

Can not register storage units '%s'.

What it means

Error "Can not register storage units '%s'." thrown in apache/shardingsphere.

Source

Thrown at infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/RegisterStorageUnitExecutor.java:70

    
    @Override
    public void executeUpdate(final RegisterStorageUnitStatement sqlStatement, final ContextManager contextManager) {
        checkDataSource(sqlStatement, contextManager);
        Map<String, DataSourcePoolProperties> propsMap = DataSourceSegmentsConverter.convert(database.getProtocolType(), sqlStatement.getStorageUnits());
        if (sqlStatement.isIfNotExists()) {
            Collection<String> currentStorageUnits = getCurrentStorageUnitNames(contextManager);
            Collection<String> logicalDataSourceNames = getLogicalDataSourceNames();
            propsMap.keySet().removeIf(currentStorageUnits::contains);
            propsMap.keySet().removeIf(logicalDataSourceNames::contains);
        }
        if (propsMap.isEmpty()) {
            return;
        }
        validateHandler.validate(propsMap, getExpectedPrivileges(sqlStatement));
        try {
            contextManager.getPersistServiceFacade().getModeFacade().getMetaDataManagerService().registerStorageUnits(database.getName(), propsMap);
        } catch (final ShardingSphereExternalException ex) {
            throw new StorageUnitsOperateException("register", propsMap.keySet(), ex);
        }
    }
    
    private void checkDataSource(final RegisterStorageUnitStatement sqlStatement, final ContextManager contextManager) {
        if (!sqlStatement.isIfNotExists()) {
            Collection<String> dataSourceNames = new ArrayList<>(sqlStatement.getStorageUnits().size());
            checkDuplicatedDataSourceNames(contextManager, dataSourceNames, sqlStatement);
            checkDuplicatedLogicalDataSourceNames(dataSourceNames);
        }
    }
    
    private void checkDuplicatedDataSourceNames(final ContextManager contextManager, final Collection<String> dataSourceNames, final RegisterStorageUnitStatement sqlStatement) {
        Collection<String> duplicatedDataSourceNames = new HashSet<>(sqlStatement.getStorageUnits().size(), 1F);
        for (DataSourceSegment each : sqlStatement.getStorageUnits()) {
            if (dataSourceNames.contains(each.getName()) || getCurrentStorageUnitNames(contextManager).contains(each.getName())) {
                duplicatedDataSourceNames.add(each.getName());
            }
            dataSourceNames.add(each.getName());

View on GitHub (pinned to e952770a21)

Solutions

  1. Use a storage unit name that is not already registered.
  2. Fix invalid data source properties (URL, credentials, driver) in the registration statement.
  3. Unregister the conflicting storage unit first if replacement is intended.

When it happens

Trigger: REGISTER STORAGE UNIT fails because of duplicate names or invalid data source configuration.

Common situations: Registering a storage unit with a name already in use, or with a JDBC URL/credentials that fail validation.


AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14). Data as JSON: /api/errors/f11c9e5e90e71d1b. Report an issue: GitHub.