apache/shardingsphere · error · StorageUnitsOperateException

0

0

Error message

Can not unregister storage units '%s'.

What it means

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

Source

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

/**
 * Unregister storage unit executor.
 */
@Setter
public final class UnregisterStorageUnitExecutor implements DistSQLUpdateExecutor<UnregisterStorageUnitStatement>, DistSQLExecutorDatabaseAware {
    
    private ShardingSphereDatabase database;
    
    @Override
    public void executeUpdate(final UnregisterStorageUnitStatement sqlStatement, final ContextManager contextManager) {
        if (!sqlStatement.isIfExists()) {
            checkExisted(sqlStatement.getStorageUnitNames());
        }
        checkInUsed(sqlStatement);
        try {
            contextManager.getPersistServiceFacade().getModeFacade().getMetaDataManagerService().unregisterStorageUnits(database, sqlStatement.getStorageUnitNames());
        } catch (final ShardingSphereServerException ex) {
            throw new StorageUnitsOperateException("unregister", sqlStatement.getStorageUnitNames(), ex);
        }
    }
    
    private void checkExisted(final Collection<String> storageUnitNames) {
        Map<String, StorageUnit> storageUnits = database.getResourceMetaData().getStorageUnits();
        Collection<String> notExistedStorageUnits = storageUnitNames.stream().filter(each -> !storageUnits.containsKey(each)).collect(Collectors.toList());
        ShardingSpherePreconditions.checkMustEmpty(notExistedStorageUnits, () -> new MissingRequiredStorageUnitsException(database.getName(), notExistedStorageUnits));
    }
    
    private void checkInUsed(final UnregisterStorageUnitStatement sqlStatement) {
        Map<String, Collection<Class<? extends ShardingSphereRule>>> inUsedStorageUnits = database.getRuleMetaData().getInUsedStorageUnitNameAndRulesMap();
        Collection<String> inUsedStorageUnitNames = inUsedStorageUnits.keySet();
        inUsedStorageUnitNames.retainAll(sqlStatement.getStorageUnitNames());
        if (inUsedStorageUnitNames.isEmpty()) {
            return;
        }
        Collection<Class<? extends ShardingSphereRule>> ignoreUsageCheckRules = getIgnoreUsageCheckRules(sqlStatement);
        String firstResource = inUsedStorageUnitNames.iterator().next();

View on GitHub (pinned to e952770a21)

Solutions

  1. Ensure the storage units exist before unregistering them.
  2. Remove rules or references that still use the storage units before unregistering.
  3. Check spelling of the storage unit names.

When it happens

Trigger: UNREGISTER STORAGE UNIT fails because the named units do not exist or are still referenced by rules.

Common situations: Trying to drop a storage unit that sharding or single-table rules still reference, or a mistyped unit name.


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