[REFACTOR/147] Select Square 재시도 로직, 웹소켓 설정 추가#149
Merged
Conversation
added 4 commits
January 24, 2025 16:25
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.
PR 타입
구현한 기능
테스트 결과
구현 내용 설명
Select Square 기능의 안정성과 효율성을 향상시키기 위해 다음과 같은 주요 변경 사항들을 구현했습니다.
1. 동시성 제어를 위한 비관적 락 및 고유 제약 조건 도입
selectSquare 메소드에 @transactional 어노테이션을 추가하여 트랜잭션 관리를 강화하였습니다.
UserPachinko 엔티티에 @UniqueConstraint(columnNames = {"user_id", "round"})를 설정하여 동일 사용자 및 라운드에 대한 중복 엔티티 생성을 방지하였습니다.
userpachinkoRepository.findByUserAndRoundForUpdate 메소드를 사용하여 특정 엔티티에 비관적 락을 적용함으로써 동시 접근을 효과적으로 차단하였습니다.
2. 재시도 로직(Spring Retry) 도입
Spring Retry 라이브러리를 프로젝트에 추가하고, @EnableRetry 어노테이션을 통해 재시도 기능을 활성화하였습니다.
selectSquare 메소드에 @retryable 어노테이션을 적용하여 DataIntegrityViolationException 발생 시 최대 3회까지 재시도하도록 설정하였습니다.
재시도 간 지연 시간 및 증폭 계수를 설정하여 안정적인 재시도 메커니즘을 구현하였습니다.
@recover 어노테이션을 사용한 복구 메소드를 추가하여 모든 재시도 시도가 실패한 경우 사용자에게 적절한 에러 메시지를 반환하도록 하였습니다.
3. 예외 처리 및 로깅 개선
selectSquare 메소드 내에서 발생할 수 있는 DataIntegrityViolationException을 적절히 처리하고, 재시도 로직을 통해 일시적인 충돌을 자동으로 해결할 수 있도록 구현하였습니다.
각 단계별로 상세한 로그를 추가하여 트랜잭션의 흐름과 상태를 명확히 기록하였습니다.
복구 메소드에서도 예외 발생 시 상세한 로그를 남겨 문제 발생 시 원인 파악을 용이하게 하였습니다.
4. 동시성 컬렉션 최적화
selectedSquares 컬렉션을 ConcurrentHashMap 기반의 Set으로 변경하여 높은 동시성과 성능 향상을 달성하였습니다.
viewSelectedSquares 메소드를 추가하여 읽기 전용 뷰를 제공함으로써 데이터 무결성을 유지하였습니다.
일정