Skip to content
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

Lock으로 사용자 기준 특정 기능 동시 실행 막기 #112

Merged
merged 1 commit into from
Nov 6, 2023

Conversation

cire0304
Copy link
Collaborator

@cire0304 cire0304 commented Nov 5, 2023

완료작업

사용자 기준, 특정 기능 동시 실행을 막을 수 있는, Lock 개발

배경

동일한 사용자가 사용자 쿠폰 발급을 동시에 요청했을 경우, DB의 유니크 키 제약조건에 의해 예외가 발생하였습니다.
위의 이유로, 같은 사용자가 같은 기능을 동시에 실행하지 못하도록 코드를 개발하였습니다.

@cire0304 cire0304 added the FEAT 기능 구현 label Nov 5, 2023
@cire0304 cire0304 requested a review from f-lab-kane November 5, 2023 12:56
@cire0304 cire0304 self-assigned this Nov 5, 2023
Copy link
Collaborator

@f-lab-kane f-lab-kane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cire0304 님 수고하셨습니다.

mysql inno db engine을 사용하고 계시고 해당 환경에 insert 구문을 수행하고 트랜잭션이 완료되지 않아 commit을 수행하지 않은 상태라면 이미 레코드 수준에서 lock이 걸린 상태가 됩니다. 늦게 진입한 트랜잭션은 wait 상태가 되고 먼저 수행되던 트랜잭션이 완료되어 commit을 찍는순간 뒤에 진입한 트랜잭션이 수행되고 유니크 키 제약조건에 의해 dup 에러가 발생할거에요.

이미 db 수준에서도 동시성 제어를 하고 있기 때문에 응용수준에서 별도의 lock은 불필요 할 수도 있지만 db 리소스가 아닌 응용서버의 리소스를 사용하여 처리한다는 부분에서 좋은 방향이라 생각됩니다 👍

@cire0304 cire0304 merged commit e2c83cb into develop Nov 6, 2023
@cire0304 cire0304 deleted the feature/#59 branch November 6, 2023 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants