Skip to content

[Improvement-17928][API] Add worker group id to environment relation#18349

Open
qiuyanjun888 wants to merge 7 commits into
apache:devfrom
qiuyanjun888:Improvement-17928
Open

[Improvement-17928][API] Add worker group id to environment relation#18349
qiuyanjun888 wants to merge 7 commits into
apache:devfrom
qiuyanjun888:Improvement-17928

Conversation

@qiuyanjun888

Copy link
Copy Markdown
Contributor

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 EnvironmentWorkerGroupRelation while keeping the existing worker group name field for compatibility.

Brief change log

  • Add workerGroupId / worker_group_id to EnvironmentWorkerGroupRelation, MyBatis mapping, base schema SQL, and upgrade SQL.
  • Backfill existing worker_group_id values in MySQL/PostgreSQL upgrade SQL by joining the legacy worker group name to t_ds_worker_group.
  • Persist workerGroupId when creating or updating environment-worker-group relations.
  • Use worker_group_id when checking environment dependencies before deleting worker groups, with legacy-name fallback only for rows whose worker_group_id is NULL.
  • Add focused DAO/API tests for persistence, create/update flows, and worker group delete dependency checks.

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=true

The focused Maven test run passed with 24 tests, 0 failures, 0 errors, and 0 skipped.

Pull Request Notice

Pull Request Notice

@ruanwenjun ruanwenjun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to upgrade the data at db

@qiuyanjun888

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I have addressed this in the latest commit: the upgrade DDL now only adds the worker_group_id column, and the existing data backfill has been moved into the matching DML upgrade scripts for both MySQL and PostgreSQL.

@qiuyanjun888 qiuyanjun888 requested a review from ruanwenjun June 15, 2026 02:23
Comment on lines +21 to +22
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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should put it into 3.5.0

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +428 to +435
private Integer getWorkerGroupId(String workerGroupName) {
List<WorkerGroup> workerGroups = workerGroupDao.queryWorkerGroupByName(workerGroupName);
if (CollectionUtils.isEmpty(workerGroups)) {
return null;
}
return workerGroups.get(0).getId();
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Can workerGroupDao.queryWorkerGroupByName return list?
  2. If the worker group is not exist, need to throw exception rather than return null.
  3. We need to use batch query, rather than query single item at a for-each.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +185 to +187
.eq("worker_group_id", workerGroup.getId())
.or(queryWrapper -> queryWrapper.isNull("worker_group_id")
.eq("worker_group", workerGroup.getName())));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The worker group name shouldn't be deprecated.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +1152 to +1153
`worker_group_id` int(11) DEFAULT NULL COMMENT 'worker group id',
`worker_group` varchar(255) NOT NULL COMMENT 'worker group name',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why worker_group is not null but worker_group_id can be null?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 *

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should avoid wild card select.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in f592c03. queryWorkerGroupByNames now selects explicit columns instead of select *.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed on the current branch: queryWorkerGroupByNames uses an explicit column list instead of a wildcard select.

Comment on lines +42 to +44
/**
* worker group name
*/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/**
* worker group name
*/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in f592c03. Removed the extra worker group name comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed on the current branch: EnvironmentWorkerGroupRelation keeps workerGroup without a deprecated marker in that area.

Comment on lines +97 to +99
/**
* test query worker groups by names
*/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/**
* test query worker groups by names
*/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in f592c03. Removed the redundant test method comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed on the current branch: WorkerGroupMapperTest covers queryWorkerGroupByNames without the suggested extra line.

@qiuyanjun888 qiuyanjun888 requested a review from SbloodyS June 16, 2026 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Improvement][API] Add workergroup id at EnvironmentWorkerGroupRelation

3 participants