Skip to content

hotfix: 키워드 알림 이력 저장 트랜잭션 분리#2188

Merged
taejinn merged 2 commits intodevelopfrom
hotfix/2187-keyword-transaction-fix
Mar 18, 2026
Merged

hotfix: 키워드 알림 이력 저장 트랜잭션 분리#2188
taejinn merged 2 commits intodevelopfrom
hotfix/2187-keyword-transaction-fix

Conversation

@taejinn
Copy link
Contributor

@taejinn taejinn commented Mar 18, 2026

🔍 개요

  • 키워드 알림 발송 후 이력 저장 과정에서 트랜잭션 종료 이후 DB write가 수행되며 no transaction is in progress 오류 발생하던 문제 수정함
  • user_notification_status native upsert에서 audit 컬럼 누락으로 insert 실패 가능하던 부분 함께 보완함

🚀 주요 변경 내용

  • 키워드 알림 이력 저장 로직을 별도 트랜잭션(REQUIRES_NEW)으로 분리함
  • user_notification_status upsert 쿼리에 created_at, updated_at 반영함
  • 관련 단위 테스트로 트랜잭션 전파 설정 검증함

💬 참고 사항

  • 실제 원인은 커밋 이후 실행되는 리스너에서 DB write를 수행한 트랜잭션 경계 문제였음
  • 추가로 native upsert가 audit 컬럼을 직접 채우지 않아 운영 환경에서 insert 실패 가능성 있었음
  • 검증용 acceptance 테스트는 제외하고 실제 수정 코드만 반영함

✅ Checklist (완료 조건)

  • 코드 스타일 가이드 준수
  • 테스트 코드 포함됨
  • Reviewers / Assignees / Labels 지정 완료
  • 보안 및 민감 정보 검증 (API 키, 환경 변수, 개인정보 등)

Summary by CodeRabbit

  • Bug Fixes

    • Adjusted internal transaction behavior for a keyword-related operation (no user-facing API changes).
  • Data

    • Notification storage now records creation and update timestamps when inserting/updating records, improving timestamp accuracy.
  • Tests

    • Added a unit test that verifies the transaction behavior change.

Note: These are internal improvements with no direct user-facing UI changes.

@taejinn taejinn self-assigned this Mar 18, 2026
@taejinn taejinn added the 버그 정상적으로 동작하지 않는 문제상황입니다. label Mar 18, 2026
@github-actions github-actions bot added the 공통 백엔드 공통으로 작업할 이슈입니다. label Mar 18, 2026
@taejinn taejinn requested a review from DHkimgit March 18, 2026 08:01
@coderabbitai
Copy link

coderabbitai bot commented Mar 18, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b4bd4f44-3ad4-41db-aafc-fed9556be748

📥 Commits

Reviewing files that changed from the base of the PR and between 93f872f and 9f3f04a.

📒 Files selected for processing (1)
  • src/main/java/in/koreatech/koin/domain/community/keyword/repository/UserNotificationStatusRepository.java

📝 Walkthrough

Walkthrough

Changed KeywordService.createNotifiedArticleStatus to run in a new transaction (Propagation.REQUIRES_NEW). Added a unit test that reflects on the method to assert the transactional propagation. Updated repository upsert SQL to set created_at/updated_at timestamps on insert and update.

Changes

Cohort / File(s) Summary
Transaction Propagation Configuration
src/main/java/in/koreatech/koin/domain/community/keyword/service/KeywordService.java
Added Propagation import and changed the @Transactional annotation on createNotifiedArticleStatus to Propagation.REQUIRES_NEW.
Test Verification
src/test/java/in/koreatech/koin/unit/domain/community/keyword/service/KeywordServiceTest.java
Added createNotifiedArticleStatus_startsNewTransaction test that uses reflection to assert the @Transactional annotation is present and set to REQUIRES_NEW.
Upsert Timestamp Behavior
src/main/java/in/koreatech/koin/domain/community/keyword/repository/UserNotificationStatusRepository.java
Modified upsert SQL to insert created_at and updated_at (using CURRENT_TIMESTAMP) and to update updated_at on duplicate-key updates alongside last_notified_article_id.

Sequence Diagram(s)

sequenceDiagram
    participant Listener as EventListener (AFTER_COMMIT)
    participant Service as KeywordService.createNotifiedArticleStatus
    participant TX as TransactionManager
    participant Repo as UserNotificationStatusRepository
    participant DB as Database

    Listener->>Service: invoke createNotifiedArticleStatus()
    Note right of Service: Method annotated with\n@Transactional(propagation=REQUIRES_NEW)
    Service->>TX: begin new transaction
    TX->>Repo: call upsertLastNotifiedArticleId(...)
    Repo->>DB: execute upsert (insert timestamps / on duplicate update updated_at)
    DB-->>Repo: result
    Repo-->>TX: return
    TX->>TX: commit
    TX-->>Service: transaction committed
    Service-->>Listener: return
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through code with a careful squeak,
Started fresh transactions for the moments they’re weak,
Timestamps now recorded with each upsert and cheer,
Tests peek at annotations to make things clear,
A tiny rabbit's fix — no more transaction fear! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title in Korean accurately describes the main change: separating the keyword notification history storage transaction, which directly addresses the transaction boundary issue documented in issue #2187.
Linked Issues check ✅ Passed The PR fully implements the requirements from issue #2187: adding Propagation.REQUIRES_NEW to createNotifiedArticleStatus to handle DB writes after transaction commit, updating upsert SQL with audit columns, and verifying the transaction propagation via unit tests.
Out of Scope Changes check ✅ Passed All changes are directly in scope: the transactional annotation change, upsert query audit column updates, and corresponding test validation all address the documented transaction boundary issue from #2187.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch hotfix/2187-keyword-transaction-fix
📝 Coding Plan
  • Generate coding plan for human review comments

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link

github-actions bot commented Mar 18, 2026

Unit Test Results

691 tests  +1   688 ✔️ +1   1m 23s ⏱️ -2s
169 suites ±0       3 💤 ±0 
169 files   ±0       0 ±0 

Results for commit 9f3f04a. ± Comparison against base commit e41a0cf.

♻️ This comment has been updated with latest results.

@taejinn taejinn requested review from dh2906 and kih1015 March 18, 2026 08:06
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.

🧹 Nitpick comments (1)
src/test/java/in/koreatech/koin/unit/domain/community/keyword/service/KeywordServiceTest.java (1)

115-123: Good annotation guard; consider one runtime transaction-behavior test too.

This reflection test protects config drift, but it won’t catch cases where transactional advice is not applied at runtime. A small integration test (outer rollback + inner createNotifiedArticleStatus commit assertion) would verify actual REQUIRES_NEW behavior end-to-end.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/test/java/in/koreatech/koin/unit/domain/community/keyword/service/KeywordServiceTest.java`
around lines 115 - 123, Add a runtime integration test in KeywordServiceTest
that verifies createNotifiedArticleStatus actually runs in a new transaction:
write a test method that starts an outer `@Transactional` test transaction, call
KeywordService.createNotifiedArticleStatus(...) to persist a notified-article
record, then force the outer transaction to roll back (e.g., by throwing or
marking rollback) and finally query the repository to assert the
notified-article persisted (committed) despite the outer rollback; reference
KeywordService.createNotifiedArticleStatus and the repository used to read
persisted status to locate where to add this end-to-end REQUIRES_NEW behavior
check.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@src/test/java/in/koreatech/koin/unit/domain/community/keyword/service/KeywordServiceTest.java`:
- Around line 115-123: Add a runtime integration test in KeywordServiceTest that
verifies createNotifiedArticleStatus actually runs in a new transaction: write a
test method that starts an outer `@Transactional` test transaction, call
KeywordService.createNotifiedArticleStatus(...) to persist a notified-article
record, then force the outer transaction to roll back (e.g., by throwing or
marking rollback) and finally query the repository to assert the
notified-article persisted (committed) despite the outer rollback; reference
KeywordService.createNotifiedArticleStatus and the repository used to read
persisted status to locate where to add this end-to-end REQUIRES_NEW behavior
check.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e765b18b-0ed1-436f-8404-c0ff7469081c

📥 Commits

Reviewing files that changed from the base of the PR and between e41a0cf and 93f872f.

📒 Files selected for processing (2)
  • src/main/java/in/koreatech/koin/domain/community/keyword/service/KeywordService.java
  • src/test/java/in/koreatech/koin/unit/domain/community/keyword/service/KeywordServiceTest.java

Copy link
Contributor

@dh2906 dh2906 left a comment

Choose a reason for hiding this comment

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

고생하셨습니당

@taejinn taejinn merged commit 627b78a into develop Mar 18, 2026
11 checks passed
@taejinn taejinn deleted the hotfix/2187-keyword-transaction-fix branch March 18, 2026 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

공통 백엔드 공통으로 작업할 이슈입니다. 버그 정상적으로 동작하지 않는 문제상황입니다.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[공통] 키워드 알림 발송 오류

3 participants