Skip to content

Fix[#31]: 데일리 가중치 스케줄러와 사용자 가중치 동시 업데이트 시 업데이트 누락 방지#32

Merged
likerhythm merged 8 commits intodevelopfrom
fix/daily-weight-scheduler-concurrency-bug
Aug 4, 2025
Merged

Fix[#31]: 데일리 가중치 스케줄러와 사용자 가중치 동시 업데이트 시 업데이트 누락 방지#32
likerhythm merged 8 commits intodevelopfrom
fix/daily-weight-scheduler-concurrency-bug

Conversation

@likerhythm
Copy link
Collaborator

확인 사항

  • 💯 테스트는 잘 통과했나요?
  • 🏗️ 빌드는 성공했나요?
  • 🧹 불필요한 코드는 제거했나요?
  • 💭 이슈는 등록했나요?
  • 🏷️ 라벨은 등록했나요?

작업 내용

데일리 가중치 스케줄러가 사용자 가중치를 업데이트할 때 $set 연산자가 아닌 $inc 연산자를 사용하게 함으로써 데일리 가중치 스케줄러 이외의 요청에 의해 사용자 가중치가 업데이트 될 경우 해당 업데이트가 누락되는 문제를 해결했습니다.

시퀀스 다이어 그램

주의사항

현재 파악하기론 더 이상 $set 연산자를 사용하는 메서드가 없기 때문에 동시성 문제가 발생하지 않을 것으로 예상되지만, DB를 두 개 이상으로 확장할 경우 추가적인 문제가 발생할 수 있습니다. 이 경우 트랜잭션을 사용하는 게 적합하다고 생각합니다만 공식 문서에서는 DB에 저장되는 데이터의 형태를 적절하게 설계하면 트랜잭션 없이도 동시성 문제를 해결할 수 있다고 하며 이를 권고합니다. 이를 권고하는 이유는 MongoDB를 사용하는 이유 자체가 트랜잭션을 최소화하여 시스템의 성능을 높이는 게 목적이기 때문입니다.

Closes #31

@likerhythm likerhythm self-assigned this Aug 2, 2025
@likerhythm likerhythm changed the title Fix[#31]: 데일리 가중치 스케줄러와 사용자 가중치 동시 업데이트로 인한 업데이트 누락 방지 Fix[#31]: 데일리 가중치 스케줄러와 사용자 가중치 동시 업데이트 시 업데이트 누락 방지 Aug 2, 2025
Copy link
Contributor

@ghkdwldus0807 ghkdwldus0807 left a comment

Choose a reason for hiding this comment

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

수고하셨습니다!!
리뷰 확인해주시면 감사드리겠습니다😊

results = await cursor.to_list(length=None)
return results

async def reset_weight(self, user_id: int, genre: str, weight: float):
Copy link
Contributor

Choose a reason for hiding this comment

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

P1: reset_weight 메서드가 UserWeightRepository에서 제거되었는데
daily_wieght_resizer.py의 실패 로그 재시도 부분(124줄)에서 사용되고 있습니다! 확인 부탁드립니다

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

미처 확인하지 못한 부분이네요. 반영 완료했습니다!

filter = {"user_id": user_id, "name": genre}
update = {"$set": {"weight": weight}}
async def update_user_weight(self, user_id: int, meta_info_name: str, diff: float):
filter = {"user_id": user_id, "name": meta_info_name}
Copy link
Contributor

Choose a reason for hiding this comment

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

P2 : 한 가지 우려 되는 부분이 있습니다...!
현재 user_id + meta_info_name 조합으로 필터링하고 있는데 meta_info_name 자체가 unique하다는 보장이 없는 것으로 알고있습니다.
동일한 이름을 가진 서로 다른 메타 정보(예 - 감독, 배우 등)가 존재할 수 있기 때문에
해당 조합만으로는 정확한 문서를 식별하지 못해 데이터 무결성이 깨질 수 있는 위험이 있어 보입니다!

이 부분을 보완하기 위해 (user_id, meta_type, meta_info_name)을 기준으로 필터링하는 방식은 어떨까요?

Copy link
Collaborator Author

@likerhythm likerhythm Aug 3, 2025

Choose a reason for hiding this comment

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

좋은 리뷰 감사합니다. meta_type으로 구분하더라도 이름이 같은 배우 등 구분할 수 없는 경우도 있다고 생각해서 meta_info_id로 구분하겠습니다!

@likerhythm likerhythm merged commit e42de9f into develop Aug 4, 2025
1 check passed
@likerhythm likerhythm deleted the fix/daily-weight-scheduler-concurrency-bug branch August 4, 2025 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Fix] 데일리 가중치 스케줄러와 사용자 가중치 동시 업데이트 시 업데이트 누락 방지

2 participants

Comments