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

[fix] 스케줄러 의도대로 동작하지 않는 버그 수정 (#143) #144

Merged
merged 2 commits into from
Aug 23, 2024

Conversation

win-luck
Copy link
Collaborator

@win-luck win-luck commented Aug 22, 2024

#️⃣ 연관 이슈

📝 작업 내용

자정에 발동하는 스케줄러가 호출하는 메서드 registerWinners()에 버그가 있어 수정하였습니다.
구체적으로, 선착순 이벤트의 결과에 대한 정보를 순회하던 중 당첨자가 존재하지 않는 선착순 이벤트를 감지하는 경우 return; 문으로 인해 이후 모든 선착순 이벤트 결과 이관 기능이 동작하지 않는 버그가 있었습니다.
return문을 continue로 대체하여 문제를 해결하였고, 로컬에서 테스트 결과 정상적으로 Redis to DB 동작이 실행되는 것을 검증하였습니다.

관련 이미지 및 자료

2024-08-22 23:53:24 [http-nio-8080-exec-6] INFO  h.s.o.comment.service.CommentService - fetching comments of the-ㅏona
Hibernate: select ef1_0.id,ef1_0.frame_id,ef1_0.name from event_frame ef1_0 where ef1_0.frame_id=?
Hibernate: select fe1_0.id,fe1_0.end_time,fe1_0.event_metadata_id,fe1_0.participant_count,fe1_0.prize_info,fe1_0.start_time from fcfs_event fe1_0 where fe1_0.start_time between ? and ?
Hibernate: select em1_0.id,em1_0.description,em1_0.end_time,em1_0.event_frame_id,em1_0.event_id,em1_0.event_type,em1_0.name,em1_0.start_time,em1_0.status,em1_0.url from event_metadata em1_0 where em1_0.id=?
2024-08-23 00:01:00 [scheduling-1] INFO  h.s.o.e.f.service.FcfsManageService - Registered FCFS event: 4
Hibernate: select em1_0.id,em1_0.description,em1_0.end_time,em1_0.event_frame_id,em1_0.event_id,em1_0.event_type,em1_0.name,em1_0.start_time,em1_0.status,em1_0.url from event_metadata em1_0 where em1_0.id=?
2024-08-23 00:01:00 [scheduling-1] INFO  h.s.o.e.f.service.FcfsManageService - Registered FCFS event: 25
2024-08-23 00:01:00 [scheduling-1] INFO  h.s.o.e.f.service.FcfsManageService - Today's FCFS events were registered in Redis

보시다시피 실제 prod 환경에서 자정 정각에 Redis to DB 메서드가 동작하지 않고, 이후 1분이 될 때 DB to Redis만 동작하고 있던 것을 확인하실 수 있습니다.

@win-luck win-luck added the fix 버그 및 오류 수정 label Aug 22, 2024
@win-luck win-luck requested a review from blaxsior August 22, 2024 15:31
@win-luck win-luck self-assigned this Aug 22, 2024
Copy link
Collaborator Author

@win-luck win-luck left a comment

Choose a reason for hiding this comment

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

낙관적으로 바라봤던 메서드였는데 아니나다를까 자정에 딱 잡아냈네요.. 이제라도 알아채서 다행입니다..

Comment on lines -57 to 66
for(String fcfsId : fcfsIds) {
String eventId = fcfsId.replace(":count", "").replace("fcfs:", "");
Set<String> userIds = stringRedisTemplate.opsForZSet().range(FcfsUtil.winnerFormatting(eventId), 0, -1);
// 당첨자 관련 정보 조합하여 Entity 생성
log.info("keys for FCFS Events: {}", fcfsKeys);
for(String key : fcfsKeys) {
String fcfsEventId = key.replace(":count", "").replace("fcfs:", "");
Set<String> userIds = stringRedisTemplate.opsForZSet().range(FcfsUtil.winnerFormatting(fcfsEventId), 0, -1);
if(userIds == null || userIds.isEmpty()) {
return;
log.info("No winners in FCFS Event {}", fcfsEventId);
continue;
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

기존 return;으로 인해 운이 좋지 않게도 앞 순번의 선착순 이벤트의 당첨자가 없는 경우 메서드 자체가 종료되어 버리기에 뒤에 서있던 다른 선착순 이벤트의 결과 정보가 DB로 이동하지 못하고 붕 떠버리고 있었습니다.

continue로 바꾸어 뒷 순번 이벤트 결과도 저장할 수 있도록 고친 결과 정상 동작합니다.

Copy link
Collaborator

Choose a reason for hiding this comment

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

시연 이전에 예외를 찾을 수 있어서 다행이네요. 생각보다 심각한 버그일 수 있었는데 수정해서 다행입니다.

Comment on lines -64 to +74
FcfsEvent event = fcfsEventRepository.findById(Long.parseLong(eventId))
FcfsEvent event = fcfsEventRepository.findById(Long.parseLong(fcfsEventId))
.orElseThrow(() -> new FcfsEventException(ErrorCode.FCFS_EVENT_NOT_FOUND));

List<EventUser> users = eventUserRepository.findAllByUserId(userIds.stream().toList());
List<FcfsEventWinningInfo> winningInfos = users
.stream()
.map(user -> FcfsEventWinningInfo.of(event, user, getTimeFromScore(stringRedisTemplate.opsForZSet().score(FcfsUtil.winnerFormatting(eventId), user.getUserId()))))
.map(user -> FcfsEventWinningInfo.of(event, user, getTimeFromScore(stringRedisTemplate.opsForZSet().score(FcfsUtil.winnerFormatting(fcfsEventId), user.getUserId()))))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

그 외 eventId라는 표현이 모호하다고 생각하여 fcfsEventId로 표현을 명확하게 다듬었습니다.

@win-luck win-luck changed the title [fix] 자정 Redis to DB 스케줄러 의도대로 동작하지 않는 버그 수정 (#143) [fix] 스케줄러 의도대로 동작하지 않는 버그 수정 (#143) Aug 22, 2024
Copy link
Collaborator

@blaxsior blaxsior left a comment

Choose a reason for hiding this comment

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

고생하셨습니다.

@win-luck win-luck merged commit dd75b82 into dev Aug 23, 2024
1 check passed
@win-luck win-luck deleted the feature/143-fix-scheduler branch August 23, 2024 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix 버그 및 오류 수정
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[fix] 스케줄러 의도대로 동작하지 않는 버그 수정 (#143)
2 participants