{"record":{"id":"9b84243169445c15","repo":"apache/dolphinscheduler","slug":"create-environment-error","errorCode":"CREATE_ENVIRONMENT_ERROR","errorMessage":"Status.CREATE_ENVIRONMENT_ERROR","messagePattern":"Status\\.CREATE_ENVIRONMENT_ERROR","errorType":"error_code","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/EnvironmentServiceImpl.java","lineNumber":146,"sourceCode":"                    workerGroupList.stream().forEach(workerGroup -> {\n                        if (!StringUtils.isEmpty(workerGroup)) {\n                            EnvironmentWorkerGroupRelation relation = new EnvironmentWorkerGroupRelation();\n                            relation.setEnvironmentCode(env.getCode());\n                            relation.setWorkerGroup(workerGroup);\n                            relation.setOperator(loginUser.getId());\n                            relation.setCreateTime(new Date());\n                            relation.setUpdateTime(new Date());\n                            relationMapper.insert(relation);\n                            log.info(\n                                    \"Environment-WorkerGroup relation create complete, environmentName:{}, workerGroup:{}.\",\n                                    env.getName(), relation.getWorkerGroup());\n                        }\n                    });\n                }\n            }\n            return env.getCode();\n        }\n        throw new ServiceException(Status.CREATE_ENVIRONMENT_ERROR);\n    }\n\n    /**\n     * query environment paging\n     *\n     * @param pageNo page number\n     * @param searchVal search value\n     * @param pageSize page size\n     * @return environment list page\n     */\n    @Override\n    public Result queryEnvironmentListPaging(User loginUser, Integer pageNo, Integer pageSize, String searchVal) {\n        Result<Object> result = new Result();\n\n        Page<Environment> page = new Page<>(pageNo, pageSize);\n        PageInfo<EnvironmentDto> pageInfo = new PageInfo<>(pageNo, pageSize);\n        IPage<Environment> environmentIPage;\n        if (loginUser.getUserType().equals(UserType.ADMIN_USER)) {","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/EnvironmentServiceImpl.java#L128-L164","documentation":"Thrown by EnvironmentServiceImpl.createEnvironment when the environment row insert returns 0 affected rows (environmentMapper.insert(env) <= 0), meaning no environment was persisted. It is a generic 'insert failed' fallback reached after all validation and uniqueness checks passed.","triggerScenarios":"environmentMapper.insert returns 0 despite validation passing — typically a database constraint violation swallowed at the mapper level, a transaction rollback triggered by the worker-group relation inserts, or a DB connection failure during the write.","commonSituations":"Database schema drift (missing columns after upgrade); DB connection pool exhaustion under load; workerGroups JSON referencing groups that cause relation inserts to fail and roll back the surrounding @Transactional method.","solutions":["Check api-server logs and the database for constraint violations or connection errors around the insert time.","Verify the t_ds_environment schema matches the current DolphinScheduler version (run upgrade SQL scripts if the schema is stale).","Retry the create; if it persists, check datasource connectivity and pool settings in application.yaml.","Inspect the workerGroups parameter — malformed group entries can cause relation inserts to fail and roll back the whole transaction."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Pre-check DB connectivity before the call\ntry (Connection c = dataSource.getConnection()) {\n    if (!c.isValid(3)) throw new IllegalStateException(\"DB connection invalid\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    environmentService.createEnvironment(loginUser, name, config, desc, workerGroups);\n} catch (ServiceException e) {\n    if (String.valueOf(e.getMessage()).contains(\"CREATE_ENVIRONMENT_ERROR\")) {\n        // inspect server logs, then retry with backoff\n    }\n}","preventionTips":["Keep database schema in sync with the DolphinScheduler version (run upgrade scripts)","Monitor DB connection-pool saturation and constraints in api-server logs","Validate workerGroups JSON well-formedness before creating environments"],"tags":["dolphinscheduler","database","insert-failed","environment"],"backgroundTag":"database-write-failed","analyzedSha":"02eac45a1b6676e639fcbfb4be2243de5771b05d","analyzedAt":"2026-09-06T17:43:00.555Z","contentChangedAt":"2026-09-06T17:43:00.555Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}