-
Notifications
You must be signed in to change notification settings - Fork 0
Step 12: 동시성 제어 고도화 (비관적락, 낙관적락, 분산락) #29
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -110,6 +114,29 @@ public Reservation reserveConcertSeat(Long concertSeatId, Long userId) { | |||
return concertQueryService.getReservation(new GetReservationByIdQuery(reservationId)); | |||
} | |||
|
|||
@Deprecated(forRemoval = false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@deprecated(forRemoval = false) 사용하신거 너무 좋은거 같습니다.
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.METHOD) | ||
public @interface DistributedLock { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
waitTime과 leaseTime은 안넣은 이유가 있으실까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
기본적으로 공통값을 가져가고 추후 변경이 필요하면 추가하는게 좋을 것 같다고 생각했어요!
수정되는 case가 비지니스가 느려져서 공통으로 설정된 값보다 커져야하는 경우일 것 같은데 이건 비지니스 속도를 올리는 방법으로 개선해야되지않을까해서 강제한 느낌도 있습니다!
|
||
@Aspect | ||
@Component | ||
@Order(Ordered.HIGHEST_PRECEDENCE + 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
order를 사용하신 이유가 있으실까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
트랜잭션 어노테이션과 같이 사용했을때 Lock 획득을 먼저하기위해서 사용했습니다. 트랜잭션 어노테이션의 순서는Ordered.HIGHEST_PRECEDENCE
이더라구여
오늘도 많이 배워갑니당.. aop 활용은 안해봤는데 현준님 코드덕에 맛보고 갑니다 👍🏼 |
요구사항
작업 내용
redis 분산락 추가 (b10f7a5, 4e7849e)
#28 에서 좌석예약, 잔액 충전, 잔액 결제(예약 내역 결제)에 대해 분석하여 적용할 락을 정했습니다.
좌석 예약 분산락 추가 및 테스트 (7d6cc14)
사용자 잔액 충전 낙관적락, 분산락 추가 및 테스트 (9a1019e)
예약 내역 결제 낙관적락, 분산락 추가 및 테스트 (62d4876)
선택 동시성 제어 방법 API에 적용 (bc3da39)
좌석 예약 - 낙관적락
잔액 충전 - 분산락, 낙관적락
잔액 결제(예약 내역 결제) - 분산락, 낙관적락
코드 구현
각 usecase 별 비관적락, 낙관적락, 분산락 구현 및 통합 + 동시성 테스트를 진행했습니다.
사실 잔액과 좌석 entity에 @Version 어노테이션에 의해 모든 동시성제어에 낙관적락이 포함되어있습니다.
하지만 비관적락과 분산락의 경우 낙관적락에 의한 충돌이 안나오고 나온다면 error로 생각하고 작성했기에 감안해서 봐주시면 좋을 것 같습니다.
리뷰포인트