fix: PracticeService complete() 트랜잭션 분리로 HikariCP 커넥션 고갈 방지#33
Draft
Jeongho0805 wants to merge 1 commit into
Draft
fix: PracticeService complete() 트랜잭션 분리로 HikariCP 커넥션 고갈 방지#33Jeongho0805 wants to merge 1 commit into
Jeongho0805 wants to merge 1 commit into
Conversation
POST /api/practice/complete 처리 시 클래스 레벨 @transactional이 save()와 rankCalculator.calculate()(집계 쿼리 2개)를 하나의 트랜잭션으로 묶어 커넥션을 장시간 점유, 풀 고갈 후 InterruptedException → CannotCreateTransactionException 연쇄 발생. complete()에 Propagation.NOT_SUPPORTED를 지정해 각 하위 작업이 자체 단기 트랜잭션을 사용하도록 분리하여 커넥션 반환 시점을 앞당긴다.
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.
변경 사항
PracticeService.complete()에@Transactional(propagation = Propagation.NOT_SUPPORTED)추가@Transactional이 적용되던complete()를 트랜잭션 없는 컨텍스트로 전환하여resultRepository.save(),rankCalculator.calculate()각각이 자체 단기 트랜잭션을 사용하도록 분리배경
Sentry 이슈 PRACTICKET-52:
POST /api/practice/complete에서CannotCreateTransactionException: Could not open JPA EntityManager for transaction발생.클래스 레벨
@Transactional로 인해complete()전체—resultRepository.save()(쓰기) +rankCalculator.calculate()내 집계 쿼리 2개(countRecordsBetterThan,countRecordsInMonth)—가 단일 트랜잭션으로 묶여 HikariCP 커넥션을 장시간 점유한다. 동시 요청이 늘어나면 풀이 고갈되고, 커넥션 대기 중인 스레드가 인터럽트되어InterruptedException→SQLException(HikariPool-1 - Interrupted during connection acquisition)→CannotCreateTransactionException연쇄가 발생한다.Propagation.NOT_SUPPORTED를 지정하면 각 하위 작업이 SpringData 내장@Transactional로 독립 실행되어 커넥션을 즉시 반환하므로 풀 고갈을 방지한다.