{"record":{"id":"35cd8701a950ebf2","repo":"apache/shardingsphere","slug":"0-35cd87","errorCode":"0","errorMessage":"Can not unregister storage units '%s'.","messagePattern":"Can not unregister storage units '(.+?)'\\.","errorType":"exception","errorClass":"StorageUnitsOperateException","httpStatus":null,"severity":"error","filePath":"infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/UnregisterStorageUnitExecutor.java","lineNumber":59,"sourceCode":"\n/**\n * Unregister storage unit executor.\n */\n@Setter\npublic final class UnregisterStorageUnitExecutor implements DistSQLUpdateExecutor<UnregisterStorageUnitStatement>, DistSQLExecutorDatabaseAware {\n    \n    private ShardingSphereDatabase database;\n    \n    @Override\n    public void executeUpdate(final UnregisterStorageUnitStatement sqlStatement, final ContextManager contextManager) {\n        if (!sqlStatement.isIfExists()) {\n            checkExisted(sqlStatement.getStorageUnitNames());\n        }\n        checkInUsed(sqlStatement);\n        try {\n            contextManager.getPersistServiceFacade().getModeFacade().getMetaDataManagerService().unregisterStorageUnits(database, sqlStatement.getStorageUnitNames());\n        } catch (final ShardingSphereServerException ex) {\n            throw new StorageUnitsOperateException(\"unregister\", sqlStatement.getStorageUnitNames(), ex);\n        }\n    }\n    \n    private void checkExisted(final Collection<String> storageUnitNames) {\n        Map<String, StorageUnit> storageUnits = database.getResourceMetaData().getStorageUnits();\n        Collection<String> notExistedStorageUnits = storageUnitNames.stream().filter(each -> !storageUnits.containsKey(each)).collect(Collectors.toList());\n        ShardingSpherePreconditions.checkMustEmpty(notExistedStorageUnits, () -> new MissingRequiredStorageUnitsException(database.getName(), notExistedStorageUnits));\n    }\n    \n    private void checkInUsed(final UnregisterStorageUnitStatement sqlStatement) {\n        Map<String, Collection<Class<? extends ShardingSphereRule>>> inUsedStorageUnits = database.getRuleMetaData().getInUsedStorageUnitNameAndRulesMap();\n        Collection<String> inUsedStorageUnitNames = inUsedStorageUnits.keySet();\n        inUsedStorageUnitNames.retainAll(sqlStatement.getStorageUnitNames());\n        if (inUsedStorageUnitNames.isEmpty()) {\n            return;\n        }\n        Collection<Class<? extends ShardingSphereRule>> ignoreUsageCheckRules = getIgnoreUsageCheckRules(sqlStatement);\n        String firstResource = inUsedStorageUnitNames.iterator().next();","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/apache/shardingsphere/blob/e952770a215630a3659c75d64369168cd3e26b82/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/UnregisterStorageUnitExecutor.java#L41-L77","documentation":"Error \"Can not unregister storage units '%s'.\" thrown in apache/shardingsphere.","triggerScenarios":"UNREGISTER STORAGE UNIT fails because the named units do not exist or are still referenced by rules.","commonSituations":"Trying to drop a storage unit that sharding or single-table rules still reference, or a mistyped unit name.","solutions":["Ensure the storage units exist before unregistering them.","Remove rules or references that still use the storage units before unregistering.","Check spelling of the storage unit names."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e952770a215630a3659c75d64369168cd3e26b82","analyzedAt":"2026-08-14T13:54:53.392Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}