Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chunck Monitor always report a warn about restarting, even if restart is desactivated #4640

Open
pkernevez opened this issue Aug 6, 2024 · 0 comments
Labels
status: waiting-for-triage Issues that we did not analyse yet type: bug

Comments

@pkernevez
Copy link

Bug description
I use a RepositoryItemReader in a multi-thread scope (with a task executor)
RepositoryItemReader is thread safe, and as documented I set up : .saveState(false) and manage my state in my own code.

Environment
Java 21
SpringBoot 3.3.0
SpringBatch 5.1.2
Hibernate 6.5.2

Steps to reproduce
Run my Job and the WARN logs are showed: ItemStream was opened in a different thread. Restart data could be compromised.

Expected behavior
No warn about state when save state is disabled.

Minimal Complete Reproducible example
Please provide a failing test or a minimal complete verifiable example that reproduces the issue.
Bug reports that are reproducible will take priority in resolution over reports that are not reproducible.

My Step:

    @Bean(name = "snapshotAccountPositionStep")
    @JobScope
    public Step cobAccounts(JobRepository jobRepository,
                            PlatformTransactionManager transactionManager,
                            @Qualifier("batchThreadPool") TaskExecutor taskExecutor,
                            SnapshotAccountPositionProcessor processor,
                            @Qualifier("snapshotListener") SnapshotAccountPositionStepListener snapshotListener,
                            @Value("${job.skipLimit}") int skipLimit,
                            @Value("${job.chunkSize}") int chunkSize) {
        return new StepBuilder("snapshotAccountPositionStep", jobRepository)
                .<TSIDResult, String>chunk(chunkSize, transactionManager)
                .faultTolerant()
                .skip(JobErrorStepListener.JobProcessingException.class)
                .skipLimit(skipLimit)
                .taskExecutor(taskExecutor)
                .reader(workAccountReader(null, null, null))
                .processor(processor)
                .listener(snapshotListener)
                .listener(getPatchListener())
                .writer(accountWriter())
                .listener(getErrorListener(null, null))
                .build();
    }

My reader:

    @Bean
    @StepScope
    public RepositoryItemReader<TSIDResult> workAccountReader(CobAccountWorkRepository repository,
                                                                 @Value("${positionSnapshot.readerPageSize}") Integer readerPageSize,
                                                                 @Value("#{jobParameters['date']}") LocalDate date) {
        return new RepositoryItemReaderBuilder<TSIDResult>()
                .name("workAccountReader")
                .saveState(false)
                .repository(repository)
                .methodName("findByStatusInAndDate")
                .arguments(List.of(TO_DO, DONE), date)
                .sorts(Collections.singletonMap(date.ID, Sort.Direction.ASC))
                .pageSize(readerPageSize)
                .build();
    }
     // ChunkMonitor.java
     private ChunkMonitorData getData() {
		ChunkMonitorData data = holder.get();
		if (data == null) {
			if (streamsRegistered) {
				logger.warn("ItemStream was opened in a different thread.  Restart data could be compromised.");
			}
			data = new ChunkMonitorData(0, 0);
			holder.set(data);
		}
		return data;
	}
@pkernevez pkernevez added status: waiting-for-triage Issues that we did not analyse yet type: bug labels Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage Issues that we did not analyse yet type: bug
Projects
None yet
Development

No branches or pull requests

1 participant