fix: EgovFlatFileByteReader 가 ExecutionContext 키를 FlatFileItemReader 이름으로 등록해 재시작 상태가 섞이는 문제 수정 - #365
Open
wantaekchoi wants to merge 1 commit into
Conversation
…이름으로 등록해 재시작 상태가 섞이는 문제 수정 AbstractItemCountingItemStreamItemReader 에 넘기는 이름은 표시용이 아니라 ExecutionContext 키의 접두어다. update() 가 이 이름으로 read.count 를 쓰고 open() 이 같은 이름으로 읽어 재시작 위치를 복원한다. 이 클래스는 FlatFileItemReader 를 상속하지 않는다. 그런데 생성자가 그 이름을 넣는다. 표준 FlatFileItemReader 는 자기 생성자에서 같은 이름을 무조건 넣으므로, 한 Step 에 둘이 함께 등록되면 FlatFileItemReader.read.count 하나를 나눠 쓴다. 그러면 재시작 때 서로의 진행 위치를 읽어 건너뛰거나 같은 줄을 다시 처리한다. 같은 모듈의 EgovMyBatisPagingItemReader 와 EgovPartitionFlatFileItemWriter 는 자기 클래스 이름을 쓴다. 그 형태에 맞췄다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
수정 사유 Reason for modification
수정된 소스 내용 Modified source
EgovFlatFileByteReader는 생성자에서 자기 이름 대신FlatFileItemReader이름을 등록합니다. 같은 모듈의 다른 두 곳은 자기 클래스 이름을 씁니다.이 이름은 표시용이 아니라 재시작 상태를 저장하는 키의 접두어입니다.
ExecutionContextUserSupport.getKey(String)가name + "." + suffix를 만들고,AbstractItemCountingItemStreamItemReader의open/update가read.count를 그 키로 읽고 씁니다.그런데 표준
FlatFileItemReader는 상속 조상이 아니라 같은 부모를 둔 형제이고, 자기 생성자에서 같은 이름을 무조건 설정합니다.두 reader 가 한 Step 에 스트림으로 함께 등록되면
FlatFileItemReader.read.count하나를 공유합니다.CompositeItemStream.register는 동일 인스턴스만 걸러내므로 이름 충돌은 통과합니다. 나중에 쓴 쪽의 카운트가 앞의 것을 덮어써서, 재시작할 때 아직 처리하지 않은 레코드를 건너뜁니다.가정한 설정은 아닙니다. 이 저장소의 테스트 Job 이 평범한
FlatFileItemReader를 Step 스트림으로 명시 등록하고 있습니다.같은 모듈의
DefaultItemReader·EgovIndexFileReader도 결국FlatFileItemReader.read.count에 씁니다(DefaultItemReader.java:130,138/EgovIndexFileReader.java:108,117에서 내부FlatFileItemReader인스턴스로open/update를 위임). 다만 그쪽은 실제로FlatFileItemReader를 만들어 쓰므로 이름이 사실과 맞고, 바꾸면 영향 범위가 훨씬 넓어져 이번 수정에서는 제외했습니다.AS-IS / TO-BE
형제 두 곳의 형태에 맞췄습니다.
public EgovFlatFileByteReader() { - setName(ClassUtils.getShortName(FlatFileItemReader.class)); + setName(ClassUtils.getShortName(EgovFlatFileByteReader.class)); }FlatFileItemReader임포트는 이 한 줄에서만 쓰여 함께 제거했습니다.영향 범위
저장소 안에서 이 클래스를 참조하는 운영 코드나 XML 설정은 없습니다. README 표 한 줄과 테스트뿐입니다.
하위호환은 리뷰어 판단이 필요한 부분이라 먼저 적어 둡니다. ExecutionContext 키가
FlatFileItemReader.read.count에서EgovFlatFileByteReader.read.count로 바뀌는데, v5.0.0 FINAL(4d97ab5)은 이미origin/main의 조상이고 루트 pom 도5.0.0이므로 기존 키는 이미 배포된 키입니다. 기존 키로 저장된 미완료StepExecution을 업그레이드 후 재시작하면 새 키를 찾지 못해 처음부터 다시 읽습니다(중복 처리).open()에서 새 키가 없을 때만 구 키를 읽는 폴백을 두는 선택지가 있습니다. 릴리스 정책에 달린 문제라고 보아 이번 diff 에는 넣지 않았습니다.JUnit 테스트 JUnit tests
기존
EgovFlatFileByteReaderTest에 재시작 시나리오를 더했습니다. Step 이 실제로 쓰는CompositeItemStream에 표준FlatFileItemReader(4줄)와EgovFlatFileByteReader(고정길이 4레코드)를 등록하고, 앞의 것 1건 / 뒤의 것 3건을 읽은 뒤update()·close()하고 저장된ExecutionContext로 다시 엽니다. 리플렉션이나 스텁 없이 실제 클래스만 씁니다.충돌을 드러내는 것은 표준
FlatFileItemReader쪽 단언입니다. 1건만 처리했으므로 2번째 라인이 나와야 합니다. 앞에 있는EgovFlatFileByteReader단언은 수정 전에도 통과하며, 이번 수정이 자기 쪽 재시작을 깨지 않았는지 보는 회귀 가드입니다.수정한 한 줄만 되돌리면 실패합니다.
수정 후 모듈 전체입니다.
테스트 브라우저 Test Browser
테스트 스크린샷 또는 캡처 영상 Test screenshots or captured video
화면이 없는 실행환경 모듈이라 첨부하지 않았습니다.