[Feat/#264] 카테고리 수정시 락 설정 #266
Open
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 Point
무슨 이유로 어떻게 코드를 변경했는지
카테고리 수정시 데드락 발생 -> 이전 요청이 끝나기전 다른 요청이 들어와 서로 변경하려는 category가 중복됨에 따라 데드락 발생
-> 요청이 들어오면 변경할 카테고리들을 묶어서 락 설정 -> 트랜잭션이 끝나면 락 해제 ( 중간에 요청이 들어오면 대기)
어떤 부분에 리뷰어가 집중해야 하는지
카테고리 수정은 유저마다 이뤄지므로 분산락과 같은 전체적인 락보다 select for update를 사용하여 사용자별로 락을 거는것이 더 효율적이라고 생각되어 이렇게 수정해보았습니다~~
개발하면서 어떤 점이 궁금했는지
‼️ 머지 되기전에 yml 업데이트 필요
현재 락 timeout을 yml에 (노션에 수정해놓음 ) 전체적으로 5초로 설정해놓았는데 나중에 개별적으로 시간설정할수있도록 수정하면 좋을것같습니다. 5초는 괜찮을까요...?
📸 결과물 스크린샷
테스트 코드 실행 결과 ( 로그 있는 버전 - 지금은 로그 없앰)

트랜잭션1이 수행중일때 트랜잭션2가 들어오면 대기상태 -> 차례로 로직이 수행됨
🛠️ 테스트
🚀 API Endpoint