[Improvement-17928][API] Add worker group id to environment relation#18349
[Improvement-17928][API] Add worker group id to environment relation#18349qiuyanjun888 wants to merge 7 commits into
Conversation
ruanwenjun
left a comment
There was a problem hiding this comment.
Need to upgrade the data at db
|
Thanks for the review. I have addressed this in the latest commit: the upgrade DDL now only adds the |
| ALTER TABLE `t_ds_environment_worker_group_relation` | ||
| ADD COLUMN `worker_group_id` int(11) DEFAULT NULL COMMENT 'worker group id'; No newline at end of file |
There was a problem hiding this comment.
Addressed in 05ef512. I moved the worker_group_id upgrade scripts from 3.4.1_schema to 3.5.0_schema for both MySQL and PostgreSQL. The 3.4.1 upgrade scripts are no longer changed in this PR.
There was a problem hiding this comment.
Addressed on the current branch: the MySQL worker_group_id upgrade DDL/DML is under sql/upgrade/3.5.0_schema, and the 3.4.1 MySQL DDL no longer contains this change.
| private Integer getWorkerGroupId(String workerGroupName) { | ||
| List<WorkerGroup> workerGroups = workerGroupDao.queryWorkerGroupByName(workerGroupName); | ||
| if (CollectionUtils.isEmpty(workerGroups)) { | ||
| return null; | ||
| } | ||
| return workerGroups.get(0).getId(); | ||
| } | ||
|
|
There was a problem hiding this comment.
- Can
workerGroupDao.queryWorkerGroupByNamereturn list? - If the worker group is not exist, need to throw exception rather than return null.
- We need to use batch query, rather than query single item at a for-each.
There was a problem hiding this comment.
Addressed in 05ef512. EnvironmentServiceImpl now parses the worker groups once and loads them with workerGroupDao.queryWorkerGroupByNames(...). Missing worker groups now throw WORKER_GROUP_NOT_EXIST instead of returning null.
There was a problem hiding this comment.
Addressed on the current branch: WorkerGroupDao/Mapper returns a list, EnvironmentServiceImpl performs a single queryWorkerGroupByNames batch lookup, maps results by name, and throws WORKER_GROUP_NOT_EXIST when any requested worker group is missing.
| .eq("worker_group_id", workerGroup.getId()) | ||
| .or(queryWrapper -> queryWrapper.isNull("worker_group_id") | ||
| .eq("worker_group", workerGroup.getName()))); |
There was a problem hiding this comment.
The worker group name shouldn't be deprecated.
There was a problem hiding this comment.
Addressed in 05ef512. The worker group dependency check now checks both worker_group_id and worker_group name, so worker_group is still treated as valid data rather than deprecated fallback only.
There was a problem hiding this comment.
Addressed on the current branch: workerGroup remains a non-deprecated compatibility field, and worker group deletion dependency checks match environment relations by worker_group_id or by worker_group name.
| `worker_group_id` int(11) DEFAULT NULL COMMENT 'worker group id', | ||
| `worker_group` varchar(255) NOT NULL COMMENT 'worker group name', |
There was a problem hiding this comment.
Why worker_group is not null but worker_group_id can be null?
There was a problem hiding this comment.
Addressed in 05ef512. The base schema now defines worker_group_id as NOT NULL. For upgrades, DDL adds it nullable first, DML backfills it from t_ds_worker_group, and then the column is changed to NOT NULL for MySQL and PostgreSQL.
| where name = #{name} | ||
| </select> | ||
| <select id="queryWorkerGroupByNames" resultType="org.apache.dolphinscheduler.dao.entity.WorkerGroup"> | ||
| select * |
There was a problem hiding this comment.
You should avoid wild card select.
There was a problem hiding this comment.
Fixed in f592c03. queryWorkerGroupByNames now selects explicit columns instead of select *.
There was a problem hiding this comment.
Addressed on the current branch: queryWorkerGroupByNames uses an explicit column list instead of a wildcard select.
| /** | ||
| * worker group name | ||
| */ |
There was a problem hiding this comment.
| /** | |
| * worker group name | |
| */ |
There was a problem hiding this comment.
Fixed in f592c03. Removed the extra worker group name comment.
There was a problem hiding this comment.
Addressed on the current branch: EnvironmentWorkerGroupRelation keeps workerGroup without a deprecated marker in that area.
| /** | ||
| * test query worker groups by names | ||
| */ |
There was a problem hiding this comment.
| /** | |
| * test query worker groups by names | |
| */ |
There was a problem hiding this comment.
Fixed in f592c03. Removed the redundant test method comment.
There was a problem hiding this comment.
Addressed on the current branch: WorkerGroupMapperTest covers queryWorkerGroupByNames without the suggested extra line.
Was this PR generated or assisted by AI?
YES. This pull request was assisted by Hermes Agent / OpenAI Codex for code changes, focused tests, and local verification. The scope and final submission were directed by the contributor.
Purpose of the pull request
Closes #17928.
This pull request adds a stable worker group id to
EnvironmentWorkerGroupRelationwhile keeping the existing worker group name field for compatibility.Brief change log
workerGroupId/worker_group_idtoEnvironmentWorkerGroupRelation, MyBatis mapping, base schema SQL, and upgrade SQL.worker_group_idvalues in MySQL/PostgreSQL upgrade SQL by joining the legacy worker group name tot_ds_worker_group.workerGroupIdwhen creating or updating environment-worker-group relations.worker_group_idwhen checking environment dependencies before deleting worker groups, with legacy-name fallback only for rows whoseworker_group_idisNULL.Verify this pull request
This change added tests and can be verified as follows:
git diff --check./mvnw -pl dolphinscheduler-dao,dolphinscheduler-api spotless:check -DskipTests -DskipITs -Djacoco.skip=true./mvnw -pl dolphinscheduler-dao,dolphinscheduler-api test -Dtest=EnvironmentWorkerGroupRelationMapperTest,EnvironmentServiceTest,WorkerGroupServiceTest -DskipITs -Dspotless.check.skip=true -Dcheckstyle.skip=true -Djacoco.skip=trueThe focused Maven test run passed with 24 tests, 0 failures, 0 errors, and 0 skipped.
Pull Request Notice
Pull Request Notice