Skip to content

[KYLIN-6087] Support built-in auto scheduled segment build with model-level config and scheduler - #2347

Open
Mrhs121 wants to merge 4 commits into
apache:kylin5from
Mrhs121:scs
Open

[KYLIN-6087] Support built-in auto scheduled segment build with model-level config and scheduler#2347
Mrhs121 wants to merge 4 commits into
apache:kylin5from
Mrhs121:scs

Conversation

@Mrhs121

@Mrhs121 Mrhs121 commented Feb 9, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@Mrhs121

Mrhs121 commented Feb 10, 2026

Copy link
Copy Markdown
Contributor Author

retest this please

@Mrhs121

Mrhs121 commented Feb 10, 2026

Copy link
Copy Markdown
Contributor Author

@jlfsdtc PTAL, Thanks

@jlfsdtc

jlfsdtc commented Feb 12, 2026

Copy link
Copy Markdown
Contributor

Please add "dev design" and create an Apache issue at the same time. @Mrhs121

@Mrhs121 Mrhs121 changed the title Support built-in auto scheduled segment build with model-level config and scheduler [KYLIN-6087] Support built-in auto scheduled segment build with model-level config and scheduler Feb 26, 2026
}
val parts = key.split("/", 2);
if (parts.length != 2) {
return;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

add error log, identify the abnormal key

@Getter
private final AtomicInteger schedulerModelCount = new AtomicInteger(0);

@Scheduled(cron = "*/30 * * * * ?")

@fishcus fishcus Jul 23, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is it necessary to schedule this operation every 30 minutes? or this crontab expression should be configurable.

val projectName = project.getName();
val modelManager = NDataModelManager.getInstance(KylinConfig.readSystemKylinConfig(), projectName);
for (NDataModel model : modelManager.listAllModels()) {
val segmentConfig = model.getSegmentConfig();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

skip the offline model or broken model?


private void startCron(String key, String cron) {
stopCron(key);
checkSchedulerThreadPoolSize();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

check every time of startCron or every time of schedule?

if (autoSegmentBuild == null || !autoSegmentBuild.isEnabled()) {
return;
}
if (model.isStreaming() || model.isMultiPartitionModel()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

model‘s status has been checked when walking through the model list in function reconcile,combine these into one.

JobTypeEnum[] buildJobTypes = JobTypeEnum.getJobTypeByCategory(JobTypeEnum.Category.BUILD)
.toArray(new JobTypeEnum[0]);
List<AbstractExecutable> jobs = executableManager.listExecByModelAndStatus(modelId,
ExecutableState::isProgressing, buildJobTypes);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

hasRunningBuildJob of the same segment or any segment?

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds model-level configuration and a built-in scheduler to automatically build segments on a daily schedule, and exposes the configuration through REST + Kystudio UI so users can configure/observe auto scheduled builds per model.

Changes:

  • Introduces AutoSegmentBuildConfig and wires it into SegmentConfig, project defaults, model config request/response, and open API mapping.
  • Adds AutoBuildSegmentScheduler to periodically dispatch scheduled segment build jobs using project time zones.
  • Extends ModelBuildService to support scheduler-triggered incremental segment builds with a configurable submitter, plus unit tests for validation and scheduler behavior.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/modeling-service/src/test/java/org/apache/kylin/rest/service/ModelServiceTest.java Adds tests for auto-segment-build config persistence and parameter validation.
src/modeling-service/src/main/java/org/apache/kylin/rest/service/ModelService.java Adds validation for auto_segment_build and returns/persists it in model config APIs.
src/modeling-service/src/main/java/org/apache/kylin/rest/service/ModelBuildService.java Adds scheduler entrypoint and propagates submitter into job params.
src/modeling-service/src/main/java/org/apache/kylin/rest/response/ModelConfigResponse.java Exposes auto_segment_build in REST response.
src/modeling-service/src/main/java/org/apache/kylin/rest/request/ModelConfigRequest.java Accepts auto_segment_build in REST request.
src/metadata-server/src/main/java/org/apache/kylin/rest/controller/open/OpenModelController.java Maps auto_segment_build between open API model config response/request.
src/data-loading-service/src/test/java/org/apache/kylin/rest/scheduler/AutoBuildSegmentSchedulerTest.java Adds scheduler unit tests (timezone handling, once-per-window dispatch, skip conditions).
src/data-loading-service/src/main/java/org/apache/kylin/rest/scheduler/AutoBuildSegmentScheduler.java New scheduler component that dispatches auto segment builds per project/model.
src/core-metadata/src/test/java/org/apache/kylin/metadata/cube/model/NSegmentConfigHelperTest.java Updates constructor usage due to new SegmentConfig field.
src/core-metadata/src/main/java/org/apache/kylin/metadata/project/ProjectInstance.java Adds project default auto_segment_build config inside default SegmentConfig.
src/core-metadata/src/main/java/org/apache/kylin/metadata/model/SegmentConfig.java Adds auto_segment_build field to segment config.
src/core-metadata/src/main/java/org/apache/kylin/metadata/model/AutoSegmentBuildConfig.java New config model for auto scheduled segment builds.
src/core-common/src/main/resources/kylin-defaults0.properties Adds default cron property for scheduler dispatcher.
kystudio/src/components/setting/SettingModel/SettingModel.vue Adds UI to edit/delete/display auto segment build config.
kystudio/src/components/setting/SettingModel/locales.js Adds UI strings for auto segment build.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +175 to +182
<el-form-item :label="$t('autoSegmentBuildRangeEnd')">
<el-time-picker
style="width: 180px;"
size="small"
format="HH:mm:ss"
value-format="HH:mm:ss"
v-model="modelSettingForm.autoSegmentBuild.data_range_end_time">
</el-time-picker>
Comment on lines +23 to +27
import java.time.Duration;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
Comment on lines +139 to +143
if (StringUtils.isBlank(autoSegmentBuild.getTriggerTime())) {
log.warn("Skip auto build segment because trigger_time is blank, project: {}, model: {}", project,
model.getUuid());
return;
}
Comment on lines +292 to 299
private JobInfoResponse incrementBuildSegmentsInternal(IncrementBuildSegmentParams params, String submitter,
boolean checkPermission) throws Exception {
String project = params.getProject();
aclEvaluate.checkProjectOperationPermission(project);
checkModelPermission(project, params.getModelId());
if (checkPermission) {
aclEvaluate.checkProjectOperationPermission(project);
checkModelPermission(project, params.getModelId());
}
val modelManager = getManager(NDataModelManager.class, project);
|| StringUtils.isBlank(autoSegmentBuild.getDataRangeStartTime())
|| StringUtils.isBlank(autoSegmentBuild.getDataRangeEndTime())
|| autoSegmentBuild.getLogicalDateOffsetDays() == null) {
throw new KylinException(INVALID_PARAMETER, "Invalid auto_segment_build config.");
private final AtomicBoolean dispatching = new AtomicBoolean(false);
private final AtomicReference<Instant> lastDispatchTime = new AtomicReference<>();

@Scheduled(cron = "${kylin.model.auto-segment-build.dispatcher-cron:*/30 * * * * ?}")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This indicates that kylin.model.auto-segment-build.dispatcher-cron is a system-level parameter that requires a system restart after each modification. Is it possible to adjust this parameter to the project level or model level?

return autoSegmentBuild != null && autoSegmentBuild.isEnabled() ? autoSegmentBuild : null;
}

@VisibleForTesting

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This annotation is only added to the code used for unit testing (UT), and no annotation is required for the methods employed in production code.

return scheduledTime;
}

@VisibleForTesting

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This annotation is only added to the code used for unit testing (UT), and no annotation is required for the methods employed in production code.

}
}

@VisibleForTesting

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This annotation is only added to the code used for unit testing (UT), and no annotation is required for the methods employed in production code.

return previousTime;
}

@VisibleForTesting

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This annotation is only added to the code used for unit testing (UT), and no annotation is required for the methods employed in production code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants