Skip to content

Conversation

@NCookies
Copy link
Collaborator

@NCookies NCookies commented Jun 20, 2025

작업 내용

  • 추천에서 발생할 수 있는 연속 요청(따닥 문제) 문제는 따로 락을 걸지 않고, 유니크 제약조건을 걸어서 해결함
  • 이 문제의 경우 여러 스레드가 하나의 공유 자원을 두고 경쟁(race condition)하는 케이스가 아니기 때문
    • 단순 insert는 유니크 제약조건으로 충분히 제어 가능
  • DataIntegrityViolationException 예외 처리 코드 추가

참고 사항


코드 리뷰 전 확인 체크리스트

  • 불필요한 콘솔 로그, 주석 제거
  • 커밋 메시지 컨벤션 준수 (type : )
  • 기능 정상 동작 확인

Summary by CodeRabbit

  • 버그 수정

    • 중복 투표 시 발생하는 예외를 처리하여 앱이 실패하지 않도록 개선하였습니다.
  • 테스트

    • 동시성 환경에서 동일 사용자가 동일 토론에 여러 번 투표할 때 데이터 무결성을 검증하는 테스트가 추가되었습니다.
  • 환경설정

    • 테스트 환경을 위한 설정 파일이 추가되었습니다.

- 추천에서 발생할 수 있는 연속 요청(따닥 문제) 문제는 따로 락을 걸지 않고, 유니크 제약조건을 걸어서 해결함
- 이 문제의 경우 여러 스레드가 하나의 공유 자원을 두고 경쟁(race condition)하는 케이스가 아니기 때문
  - 단순 insert는 유니크 제약조건으로 충분히 제어 가능
- DataIntegrityViolationException 예외 처리 코드 추가
@NCookies NCookies self-assigned this Jun 20, 2025
@NCookies NCookies added the enhancement New feature or request label Jun 20, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jun 20, 2025

Walkthrough

이번 변경에서는 투표 도메인 서비스에 중복 투표 시 예외 처리를 추가하고, 동시성 상황에서 투표 데이터 무결성을 검증하는 통합 테스트가 새로 도입되었습니다. 또한, 테스트 환경을 위한 Spring Boot 설정 파일이 추가되고, 불필요한 주석이 제거되었습니다.

Changes

파일/경로 요약 변경 내용 요약
src/main/java/org/ezcode/codetest/domain/community/repository/BaseVoteRepository.java 불필요한 주석 2줄 제거
src/main/java/org/ezcode/codetest/domain/community/service/BaseVoteDomainService.java 투표 저장 시 DataIntegrityViolationException 예외 처리 및 로그 추가, @slf4j 어노테이션 추가
src/test/java/org/ezcode/codetest/application/community/service/DiscussionVoteServiceConcurrencyTest.java 동시성 투표 상황에서 데이터 무결성 보장 테스트 클래스 및 테스트 메서드 추가
src/test/resources/application-test.properties 테스트 환경을 위한 Spring Boot 애플리케이션 프로퍼티 파일 추가

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant DiscussionVoteService
    participant BaseVoteDomainService
    participant Database

    User->>DiscussionVoteService: manageVote(UP, userId, discussionId)
    DiscussionVoteService->>BaseVoteDomainService: manageVote(...)
    BaseVoteDomainService->>Database: save(vote)
    alt 정상 저장
        Database-->>BaseVoteDomainService: 저장 성공
        BaseVoteDomainService-->>DiscussionVoteService: 완료
    else 중복 투표 (DataIntegrityViolationException)
        Database-->>BaseVoteDomainService: 예외 발생
        BaseVoteDomainService->>BaseVoteDomainService: 예외 로그 기록 (중복 투표 시도)
        BaseVoteDomainService-->>DiscussionVoteService: 처리 계속
    end
    DiscussionVoteService-->>User: 완료 응답
Loading

Possibly related PRs

Suggested reviewers

  • minjee2758
  • pokerbearkr

Poem

🐰
동시성의 바람 속 투표가 춤추네,
예외는 조용히 로그 속에 숨고,
토끼는 깡충, 테스트 성공에 환호해!
설정 파일도 새로 생기고,
주석은 깔끔하게 정리됐네.
오늘도 무결성은 안전하게!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0f2afbb and a1fc72e.

📒 Files selected for processing (1)
  • src/main/java/org/ezcode/codetest/domain/community/service/BaseVoteDomainService.java (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/org/ezcode/codetest/domain/community/service/BaseVoteDomainService.java
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/test/java/org/ezcode/codetest/application/community/service/DiscussionVoteServiceConcurrencyTest.java (1)

85-85: Thread.sleep 사용을 더 안정적인 방법으로 교체

하드코딩된 Thread.sleep(500)은 테스트를 불안정하게 만들 수 있습니다. 모든 스레드가 완료된 후 추가 대기가 필요한 이유를 명확히 하거나, 더 안정적인 동기화 방법을 사용하는 것을 권장합니다.

비동기 작업 완료를 기다려야 한다면 다음과 같은 방법을 고려해보세요:

-Thread.sleep(500);
+// 필요한 경우에만 사용하고, 이유를 명시
+// 예: DB 트랜잭션 완료 대기가 필요한 경우

또는 @DirtiestContext나 적절한 트랜잭션 관리를 통해 해결할 수 있습니다.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e41c128 and d7f70da.

📒 Files selected for processing (4)
  • src/main/java/org/ezcode/codetest/domain/community/repository/BaseVoteRepository.java (0 hunks)
  • src/main/java/org/ezcode/codetest/domain/community/service/BaseVoteDomainService.java (2 hunks)
  • src/test/java/org/ezcode/codetest/application/community/service/DiscussionVoteServiceConcurrencyTest.java (1 hunks)
  • src/test/resources/application-test.properties (1 hunks)
💤 Files with no reviewable changes (1)
  • src/main/java/org/ezcode/codetest/domain/community/repository/BaseVoteRepository.java
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (4)
src/main/java/org/ezcode/codetest/domain/community/service/BaseVoteDomainService.java (1)

10-10: 로깅 관련 의존성 추가 확인됨

DataIntegrityViolationException 처리를 위한 import와 @slf4j 어노테이션이 적절히 추가되었습니다.

Also applies to: 13-13, 15-15

src/test/resources/application-test.properties (1)

1-108: 테스트 환경 설정이 포괄적으로 잘 구성됨

모든 필요한 외부 시스템 연동 설정이 환경변수를 통해 적절히 구성되어 있습니다. 특히 동시성 테스트를 위한 실제 데이터베이스 연결 설정이 포함되어 있어 테스트 목적에 부합합니다.

몇 가지 확인사항:

  • JPA의 ddl-auto=update 설정이 테스트에 적합한지 검토 (create-drop을 고려할 수도 있음)
  • 디버그 로깅이 많이 활성화되어 있어 테스트 성능에 영향을 줄 수 있음
src/test/java/org/ezcode/codetest/application/community/service/DiscussionVoteServiceConcurrencyTest.java (2)

51-97: 동시성 테스트 로직이 잘 구현됨

CountDownLatch를 사용한 동기화와 예외 처리가 적절하게 구현되어 있습니다. 특히 DataIntegrityViolationException과 ObjectOptimisticLockingFailureException을 모두 고려한 점이 좋습니다.

테스트가 데이터 정합성을 올바르게 검증하고 있으며, 동시성 문제 해결 방식이 효과적으로 테스트되고 있습니다.


65-65: ```shell
#!/bin/bash

DiscussionVoteService 클래스 내 manageVoteOnDiscussion 메서드 시그니처 확인

rg -n "manageVoteOnDiscussion" -n src


</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

- 동시성 문제 해결이 된 것을 확인했으므로 더 이상 사용되지 않음
Copy link
Collaborator

@thezz9 thezz9 left a comment

Choose a reason for hiding this comment

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

좋은 해결 방법인 거 같습니다

@pokerbearkr pokerbearkr merged commit b72f9fd into dev Jun 20, 2025
2 checks passed
@pokerbearkr pokerbearkr deleted the feature/vote-concurrency branch June 20, 2025 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants