Conversation
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.
관련 이슈
📌 작업 개요
fix/#65주요 변경 사항
1️⃣ Repository 레이어
DispatchRepository.java
2️⃣ Service 레이어
DispatcherService.assignDispatch()
DispatcherService.getCurrentDispatch()
3️⃣ DB 마이그레이션
20260215_fix_duplicate_assigned_dispatches.sql
4️⃣ 문서화
✨ 기타 참고 사항
프로덕션 DB 마이그레이션 실행 필요 (1회)
1. 사전 체크 (선택, 권장)
docker exec -i mobility-api-postgres psql -U user -d mobilitydb
< db-migrations/20260215_pre_migration_check.sql
2. 마이그레이션 실행 (필수)
docker exec -i mobility-api-postgres psql -U user -d mobilitydb
< db-migrations/20260215_fix_duplicate_assigned_dispatches.sql
변경 전후 비교
Before (문제 상황)
// Transporter에 락이 없어서 동시 요청 시 중복 할당 가능
Transporter transporter = transporterRepository.findById(transporterId)
.orElseThrow(() -> new GlobalException(ResultCode.NOT_FOUND_USER));
// 상태 검증 없이 바로 할당
dispatch.assignDispatch(transporter);
transporter.changeDispatchStatus(DispatchStatus.DISPATCH);
After (해결)
// 1. 비관적 락으로 동시성 제어
Transporter transporter = transporterRepository.findByIdWithPessimisticLock(transporterId)
.orElseThrow(() -> new GlobalException(ResultCode.NOT_FOUND_USER));
// 2. 상태 검증 추가
if (transporter.getDispatchStatus() == DispatchStatus.DISPATCH) {
throw new GlobalException(ResultCode.TRANSPORTER_ALREADY_DISPATCHED);
}
// 3. 안전하게 할당
dispatch.assignDispatch(transporter);
transporter.changeDispatchStatus(DispatchStatus.DISPATCH);
테스트 시나리오
기사 1번에게 배차 할당 (성공)
같은 기사에게 또 다른 배차 할당 시도 (실패해야 함)
예상 응답: {"code": 3004, "message": "이미 배차중인 오더가 있습니다."}영향 범위
Breaking Changes
없음 (기존 API 동작 유지, 에러 케이스만 추가)
롤백 방법
문제 발생 시:
docker exec -i mobility-api-postgres psql -U user -d mobilitydb
< db-migrations/20260215_rollback_duplicate_fix.sql
추가 정보
✅ 체크리스트