【问题标题】:Spring Cloud Data Flow : Value too long for column "TASK_NAME" (DeployerPartitionHandler with Spring Batch)Spring Cloud 数据流:“TASK_NAME”列的值太长(带有 Spring Batch 的 DeployerPartitionHandler)
【发布时间】:2021-06-17 14:06:08
【问题描述】:

我有一个简单的 Spring Batch Job,将 Kubernetes 作为 Spring Cloud Task 运行。此作业使用 Spring Batch Partitioning 进一步启动分区步骤作为同一 Kubernetes 集群上的任务 pod。

主要工作:(相关部分)

@Bean
public Job mainControllerJob() {
    LOGGER.info("Creating mainControllerJobbean...");
    return jobBuilderFactory.get("mainControllerJob").incrementer(new RunIdIncrementer())
                .start(testStep(null, null, null)).build();
}

@Bean
public Step testStep(StepBuilderFactory stepBuilderFactory,
        @Qualifier("testPartitioner") Partitioner partitioner, PartitionHandler partitionHandler) {
    LOGGER.info("Creating testStep");
    return stepBuilderFactory.get("testStep")
            .partitioner("testWorkerStep", partitioner).partitionHandler(partitionHandler).build();
}

@Bean
public DeployerPartitionHandler partitionHandler(@Value("${test.partion.app}") String resourceLocation,
        @Value("${test.application.name}") String applicationName, ApplicationContext context,
        TaskLauncher taskLauncher, JobExplorer jobExplorer, DockerResourceLoader dockerResourceLoader) {
    Resource resource = dockerResourceLoader.getResource(resourceLocation);
    DeployerPartitionHandler partitionHandler = new DeployerPartitionHandler(taskLauncher, jobExplorer, resource,
            "testWorkerStep", taskRepository);

    List<String> commandLineArgs = new ArrayList<>();
    commandLineArgs.add("--spring.cloud.task.initialize.enable=false");
    commandLineArgs.add("--spring.batch.initializer.enabled=false");

    commandLineArgs.addAll(Arrays.stream(applicationArguments.getSourceArgs()).filter(
            x -> !x.startsWith("--spring.profiles.active=") && !x.startsWith("--spring.cloud.task.executionid="))
            .collect(Collectors.toList()));
    commandLineArgs.addAll(applicationArguments.getNonOptionArgs());

    partitionHandler.setCommandLineArgsProvider(new PassThroughCommandLineArgsProvider(commandLineArgs));
    partitionHandler.setEnvironmentVariablesProvider(new NoOpEnvironmentVariablesProvider());
    partitionHandler.setMaxWorkers(maxWorkers);
    partitionHandler.setGridSize(gridSize);
    partitionHandler.setApplicationName(applicationName);

    return partitionHandler;
}

当上述作业在 k8 上启动子步骤(任务 pod)时,我看到子步骤出现以下异常:

 org.springframework.context.ApplicationContextException: Failed to start bean 'taskLifecycleListener'; nested exception is org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL [UPDATE TASK_EXECUTION set START_TIME = ?, TASK_NAME = ?, LAST_UPDATED = ?, PARENT_EXECUTION_ID = ? where TASK_EXECUTION_ID = ?]; 
Value too long for column """TASK_NAME"" VARCHAR(100)": "'test-app,test-app_testJob_testWorkerStep:partition5800' (106)"; 
SQL statement:
    UPDATE TASK_EXECUTION set START_TIME = ?, TASK_NAME = ?, LAST_UPDATED = ?, PARENT_EXECUTION_ID = ? where TASK_EXECUTION_ID = ? [22001-199]; nested exception is org.h2.jdbc.JdbcSQLDataException: Value too long for column """TASK_NAME"" VARCHAR(100)"

错误很明显。我需要以某种方式缩短子分区步骤的名称,使其适合内部 TASK_EXECUTION 表的列宽。

我想了解的是如何更改 Spring Batch Job 自己启动的子分区步骤的名称?

我大致了解步骤名称是由SimpleStepExecutionSplitter 创建的。但是,我看不到以编程方式覆盖此行为的方法。如何更改子步骤名称并确保这样做不会影响我的作业/步骤的可重新启动性。

【问题讨论】:

    标签: java spring spring-batch spring-cloud-dataflow spring-cloud-task


    【解决方案1】:

    工作步骤名称是步骤名称和分区名称的串联(中间有分隔符)。可以使用PartitionNameProvider 自定义分区名称。因此,如果您想控制分区名称的生成方式,则需要使您的Partitioner 实现PartitionNameProvider 接口。

    另一种选择是增加TASK_NAME 列的大小。

    【讨论】:

    • 我不明白如何使用 PartitionNameProvider 接口 (getPartitionNames(int gridSize) ) -> 这是否意味着我必须返回所有分区的名称列表,其中每个索引位置代表的名称那个分区号?另外,我想更改TASK_NAME 列的大小,但找不到让数据流服务器使用我的自定义 DDL 的方法。我在类似的行上发布了一个问题:stackoverflow.com/questions/68023823/…
    • 是的,您应该返回分区的名称。网格大小与Partitioner#partition(int gridSize) 中的值相同,基本上是分区数(但只是一个提示,因为有些用例不使用它,例如在MultiResourcePartitioner 中)。
    猜你喜欢
    • 2018-10-24
    • 2019-10-17
    • 1970-01-01
    • 2017-05-08
    • 1970-01-01
    • 2018-05-27
    • 2021-05-12
    • 2021-11-06
    • 2023-02-08
    相关资源
    最近更新 更多