generated from pricelees/issue-pr-template
refactor: Pending 예약 미생성 일정 처리 스케쥴링 작업에서 발생할 수 있는 문제 해결을 위한 일정 조회시 Pessimistic Lock 처리
This commit is contained in:
parent
0599409612
commit
dbc6847877
@ -154,7 +154,7 @@ class ReservationService(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun validateCanCreate(request: PendingReservationCreateRequest) {
|
private fun validateCanCreate(request: PendingReservationCreateRequest) {
|
||||||
val schedule = scheduleService.findSummaryById(request.scheduleId)
|
val schedule = scheduleService.findSummaryWithLock(request.scheduleId)
|
||||||
val theme = themeService.findInfoById(schedule.themeId)
|
val theme = themeService.findInfoById(schedule.themeId)
|
||||||
|
|
||||||
reservationValidator.validateCanCreate(schedule, theme, request)
|
reservationValidator.validateCanCreate(schedule, theme, request)
|
||||||
|
|||||||
@ -174,10 +174,16 @@ class ScheduleService(
|
|||||||
// Other-Service (API 없이 다른 서비스에서 호출)
|
// Other-Service (API 없이 다른 서비스에서 호출)
|
||||||
// ========================================
|
// ========================================
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
fun findSummaryById(id: Long): ScheduleSummaryResponse {
|
fun findSummaryWithLock(id: Long): ScheduleSummaryResponse {
|
||||||
log.info { "[ScheduleService.findDateTimeById] 일정 개요 조회 시작 : id=$id" }
|
log.info { "[ScheduleService.findDateTimeById] 일정 개요 조회 시작 : id=$id" }
|
||||||
|
|
||||||
return findOrThrow(id).toSummaryResponse()
|
val schedule: ScheduleEntity = scheduleRepository.findByIdForUpdate(id)
|
||||||
|
?: run {
|
||||||
|
log.warn { "[ScheduleService.updateSchedule] 일정 조회 실패. id=$id" }
|
||||||
|
throw ScheduleException(ScheduleErrorCode.SCHEDULE_NOT_FOUND)
|
||||||
|
}
|
||||||
|
|
||||||
|
return schedule.toSummaryResponse()
|
||||||
.also {
|
.also {
|
||||||
log.info { "[ScheduleService.findDateTimeById] 일정 개요 조회 완료: id=$id" }
|
log.info { "[ScheduleService.findDateTimeById] 일정 개요 조회 완료: id=$id" }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
package com.sangdol.roomescape.schedule.infrastructure.persistence
|
package com.sangdol.roomescape.schedule.infrastructure.persistence
|
||||||
|
|
||||||
import com.sangdol.roomescape.schedule.business.domain.ScheduleOverview
|
import com.sangdol.roomescape.schedule.business.domain.ScheduleOverview
|
||||||
|
import jakarta.persistence.LockModeType
|
||||||
import org.springframework.data.jpa.repository.JpaRepository
|
import org.springframework.data.jpa.repository.JpaRepository
|
||||||
|
import org.springframework.data.jpa.repository.Lock
|
||||||
import org.springframework.data.jpa.repository.Modifying
|
import org.springframework.data.jpa.repository.Modifying
|
||||||
import org.springframework.data.jpa.repository.Query
|
import org.springframework.data.jpa.repository.Query
|
||||||
import org.springframework.data.repository.query.Param
|
import org.springframework.data.repository.query.Param
|
||||||
@ -11,6 +13,17 @@ import java.time.LocalTime
|
|||||||
|
|
||||||
interface ScheduleRepository : JpaRepository<ScheduleEntity, Long> {
|
interface ScheduleRepository : JpaRepository<ScheduleEntity, Long> {
|
||||||
|
|
||||||
|
@Lock(value = LockModeType.PESSIMISTIC_WRITE)
|
||||||
|
@Query("""
|
||||||
|
SELECT
|
||||||
|
s
|
||||||
|
FROM
|
||||||
|
ScheduleEntity s
|
||||||
|
WHERE
|
||||||
|
s._id = :id
|
||||||
|
""")
|
||||||
|
fun findByIdForUpdate(id: Long): ScheduleEntity?
|
||||||
|
|
||||||
@Query(
|
@Query(
|
||||||
"""
|
"""
|
||||||
SELECT
|
SELECT
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user