Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
spring批处理未处理所有记录_Spring_Spring Boot_Spring Batch_Batch Processing_Spring Batch Tasklet - Fatal编程技术网

spring批处理未处理所有记录

spring批处理未处理所有记录,spring,spring-boot,spring-batch,batch-processing,spring-batch-tasklet,Spring,Spring Boot,Spring Batch,Batch Processing,Spring Batch Tasklet,我使用SpringBatch使用RepositoryItemReader从postgresql数据库读取记录,然后将其写入主题。 我看到大约有100万条记录需要处理,但它没有处理所有的记录。 我已将阅读器的pageSize设置为10000,并与提交间隔(区块大小)相同 @Bean 公共TaskletStep broadcastProductsStep(){ 返回stepBuilderFactory.get(“广播产品”) .chunk(10000) .reader(productsReader.

我使用SpringBatch使用RepositoryItemReader从postgresql数据库读取记录,然后将其写入主题。 我看到大约有100万条记录需要处理,但它没有处理所有的记录。 我已将阅读器的pageSize设置为10000,并与提交间隔(区块大小)相同

@Bean
公共TaskletStep broadcastProductsStep(){
返回stepBuilderFactory.get(“广播产品”)
.chunk(10000)
.reader(productsReader.repositoryItemReader())
.处理器(产品处理器)
.writer(compositeItemWriter)
.容错()
.skip(异常.class)
.skipLimit(100000)
.processorNonTransactional()
.listener(新的SkipListenerProducts())
.listener(productsChunkListener)
.build();
}
@豆子
public RepositoryItemReader RepositoryItemReader(){
RepositoryItemReader repositoryReader=新的RepositoryItemReader();
试一试{
setrepositoryreader.setRepository(skuRepository);
setMethodName(“findByIsUpdatedAndStatusCodeIn”);
repositoryReader.setPageSize(10000);
repositoryReader.setSaveState(false);
列表参数=新的ArrayList();
arguments.add(Stream.of(SkuStatus.RELEASED.getValue().toString()、SkuStatus.BLOCKED.getValue().toString()、,
SkuStatus.contracted.getValue().toString())
.collect(Collectors.toList());
repositoryReader.setArguments(参数);
Map sorts=newhashmap();
排序。放置(“目录号”,排序。方向。ASC);
repositoryReader.setSort(排序);
repositoryReader.AfterPropertieSet();
}捕获(异常){
异常。printStackTrace();
}
返回存储读取器;
}
@查询(value=“SELECT*FROM CATALOG.PRODUCTS WHERE\u UPDATED=”true“和状态代码(:statusCode)”,
countQuery=“从CATALOG.PRODUCTS中选择COUNT(*),其中已更新='true'和状态代码(:statusCode)”,
nativeQuery=true)
公共页面findByIsUpdatedAndStatusCodeIn(@Param(value=“statusCode”)列表状态代码,
可寻呼(可寻呼);

问题可能是您混合了分页和读卡器查询条件的更新(已更新)

页面大小为2和6行(以db为单位)的示例

  • A是否已更新=真
  • B_UPDATED=true
  • C是否更新=真
  • D_更新=真
  • E是否更新=真
  • F_更新=真
第一个读取页=1返回行A和B

写入程序执行后(A&B的集合更新为false),我们在db中有:

  • C是否更新=真
  • D_更新=真
  • E是否更新=真
  • F_更新=真
第二次阅读将移至第2页,因此将采用E&F行,而不是C&D行

要么:

  • 不应更新“已更新”列
  • 或者创建
    RepositoryItemReader
    的子类,并在其中覆盖getPage
  • 选项2对批处理崩溃/错误更具弹性,但您必须确保在编写器中始终将is_UPDATED设置为false,否则读取器将无限循环


    如果使用多线程步骤,则选项2还需要进行更多调整。

    问题可能是您混合了分页和对读卡器查询条件的更新(已更新)

    页面大小为2和6行(以db为单位)的示例

    • A是否已更新=真
    • B_UPDATED=true
    • C是否更新=真
    • D_更新=真
    • E是否更新=真
    • F_更新=真
    第一个读取页=1返回行A和B

    写入程序执行后(A&B的集合更新为false),我们在db中有:

    • C是否更新=真
    • D_更新=真
    • E是否更新=真
    • F_更新=真
    第二次阅读将移至第2页,因此将采用E&F行,而不是C&D行

    要么:

  • 不应更新“已更新”列
  • 或者创建
    RepositoryItemReader
    的子类,并在其中覆盖getPage
  • 选项2对批处理崩溃/错误更具弹性,但您必须确保在编写器中始终将is_UPDATED设置为false,否则读取器将无限循环


    如果使用多线程步骤,选项2也需要进行更多调整。

    写入主题后是否更改“已更新”列?是的…请稍后在编写器中将其修改为false。写入主题后是否更改“已更新”列?是的…稍后在编写器中将其修改为false。非常感谢@benw。这很有帮助。@Goni_code_love,如果这真的有帮助,你可以投票决定答案。非常感谢@benw。这很有帮助。@Goni_code_love,如果这真的有帮助,你可以投票决定答案。
    @Bean
    public TaskletStep broadcastProductsStep(){
        return stepBuilderFactory.get("broadcastProducts")
                .<Product, Product> chunk(10000)
                .reader(productsReader.repositoryItemReader())
                .processor(productsProcessor)
                .writer(compositeItemWriter)                    
                .faultTolerant()
                .skip(Exception.class)                              
                .skipLimit(100000)
                .processorNonTransactional()                        
                .listener(new SkipListenerProducts())               
                .listener(productsChunkListener)
                .build();
    }
    
    
    @Bean
    public RepositoryItemReader repositoryItemReader() {
    
        RepositoryItemReader<Product> repositoryReader = new RepositoryItemReader<>();
    
        try {
            repositoryReader.setRepository(skuRepository);
            repositoryReader.setMethodName("findByIsUpdatedAndStatusCodeIn");
            repositoryReader.setPageSize(10000);
            repositoryReader.setSaveState(false);
    
            List<List<String>> arguments = new ArrayList<>();
            arguments.add(Stream.of(SkuStatus.RELEASED.getValue().toString(), SkuStatus.BLOCKED.getValue().toString(),
                    SkuStatus.DISCONTINUED.getValue().toString())
                      .collect(Collectors.toList()));
            repositoryReader.setArguments(arguments);
    
            Map sorts = new HashMap();
            sorts.put("catalog_number", Sort.Direction.ASC);
    
            repositoryReader.setSort(sorts);
            repositoryReader.afterPropertiesSet();
    
        } catch (Exception exception){
            exception.printStackTrace();
        }
    
        return repositoryReader;
    }
    
    @Query(value = "SELECT * FROM CATALOG.PRODUCTS WHERE IS_UPDATED = 'true' AND STATUS_CODE IN (:statusCode)",
           countQuery = "SELECT COUNT(*) FROM CATALOG.PRODUCTS WHERE IS_UPDATED = 'true' AND STATUS_CODE IN (:statusCode)",
           nativeQuery = true)
    public Page<Product> findByIsUpdatedAndStatusCodeIn(@Param(value = "statusCode") List<String> statusCode, 
            Pageable pageable);
    
        @Override
        public int getPage() {
            return 0;
        }