Skip to content

[HSC-424] 로그 feature dispatch 날짜 및 enum 매핑 보완#282

Merged
tkv00 merged 2 commits into
mainfrom
perf/HSC-424
Apr 1, 2026
Merged

[HSC-424] 로그 feature dispatch 날짜 및 enum 매핑 보완#282
tkv00 merged 2 commits into
mainfrom
perf/HSC-424

Conversation

@tkv00
Copy link
Copy Markdown
Contributor

@tkv00 tkv00 commented Apr 1, 2026

📝작업 내용


👀변경 사항


🎫 Jira Ticket

  • Jira Ticket: HSC-424

#️⃣관련 이슈


@tkv00 tkv00 added 🐛 fix 기능에 대한 버그 수정 🗂️ area: BE 백엔드 영역 🔥 priority: P0 즉시 처리 필요(서비스/데모 블로커) 🏷️ release 릴리즈 준비/버전 태깅/릴리즈 노트/릴리즈 브랜치 작업 release:patch 버전 patch bump: X.Y.(Z+1) deploy:api-server 배포 대상: customer-api labels Apr 1, 2026
@github-actions github-actions Bot added Customer Team ⚡ perf 성능 개선(쿼리/캐시/병목 제거 등) 🚑 hotfix 프로덕션 긴급 수정(우회/긴급 패치 포함) labels Apr 1, 2026
@github-actions github-actions Bot changed the title 로그 feature dispatch 날짜 및 enum 매핑 보완 [HSC-424] 로그 feature dispatch 날짜 및 enum 매핑 보완 Apr 1, 2026
@tkv00 tkv00 merged commit 613fac5 into main Apr 1, 2026
9 of 10 checks passed
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 1, 2026

🧪 Test Coverage Report (JaCoCo)

❗ JaCoCo XML not found: ./build/reports/jacoco/test/jacocoTestReport.xml

  • Ensure Gradle args include: jacocoTestReport
  • Expected XML: build/reports/jacoco/test/jacocoTestReport.xml

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

이번 PR은 로그 처리 로직의 시간대 상수를 공통화하고 Outbox 저장 로직을 별도 서비스로 분리하는 리팩토링을 수행합니다. 리뷰 결과, REQUIRES_NEW 전파 속성 사용에 따른 트랜잭션 원자성 결여, 트랜잭션 내 예외 처리 미흡으로 인한 UnexpectedRollbackException 발생 가능성, 그리고 배치 처리 시 개별 항목에 대한 예외 처리 누락 등의 문제가 발견되어 수정이 필요합니다.

@Value("${app.userlog.admin-dispatch.max-attempts:5}")
private int maxAttempts;

@Transactional(propagation = Propagation.REQUIRES_NEW)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

🛡️ Code Review Report

1. 🔍 요약

Outbox 패턴의 트랜잭션 원자성 보장 및 예외 처리 방식에 대한 개선이 필요합니다. 특히 REQUIRES_NEW 사용으로 인한 데이터 불일치 가능성과 트랜잭션 내 예외 처리 시 발생하는 UnexpectedRollbackException 문제를 해결해야 합니다.

2. 🛑 Blocking Issues (Must Fix)

  • [위반 규칙]: Application Layer Transaction Boundaries (Style Guide Line 43)
  • [문제 이유]: Propagation.REQUIRES_NEW를 사용하면 비즈니스 트랜잭션이 롤백되더라도 로그 저장 트랜잭션은 독립적으로 커밋됩니다. 이는 실제 수행되지 않은 작업에 대한 로그가 Admin 서비스로 전송되는 결과를 초래하여 데이터 정합성을 깨뜨립니다.
  • [해결 제안]: 기본 전파 속성인 REQUIRED를 사용하여 비즈니스 트랜잭션과 원자성을 유지하도록 수정하세요.
Suggested change
@Transactional(propagation = Propagation.REQUIRES_NEW)
@Transactional
References
  1. Application Layer (UseCase) handles transaction boundaries. @transactional is allowed here. (link)

Comment on lines +40 to +54
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void store(UserLogAdminDispatchOutbox row) {
try {
repository.saveAndFlush(row);
customerMetrics.recordAdminLogFeatureOutbox("stored");
} catch (DataIntegrityViolationException e) {
customerMetrics.recordAdminLogFeatureOutbox("duplicate");
log.debug("[UserLog][Outbox] duplicate event_id={} memberId={} eventName={}",
row.getEventId(), row.getMemberId(), row.getEventName());
} catch (Exception e) {
customerMetrics.recordAdminLogFeatureOutbox("store_error");
log.warn("[UserLog][Outbox] store failed event_id={} memberId={} eventName={}",
row.getEventId(), row.getMemberId(), row.getEventName(), e);
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

🛑 Blocking Issue: 트랜잭션 내 예외 처리 및 UnexpectedRollbackException

  • [문제 이유]: @Transactional 메서드 내부에서 런타임 예외(DataIntegrityViolationException)를 catch하고 다시 던지지 않으면, 트랜잭션은 이미 rollback-only로 마킹된 상태에서 커밋을 시도하게 되어 UnexpectedRollbackException이 발생합니다. 이로 인해 호출부의 fallback 로직(forEach)이 첫 번째 실패 건에서 중단되어 나머지 데이터 처리가 불가능해집니다.
  • [해결 제안]: store 메서드 내부의 try-catch를 제거하고, 예외 처리를 트랜잭션 경계 밖인 UserLogAdminDispatchOutboxService로 이동시키세요.
    @Transactional
    public void store(UserLogAdminDispatchOutbox row) {
        repository.saveAndFlush(row);
        customerMetrics.recordAdminLogFeatureOutbox("stored");
    }

} catch (DataIntegrityViolationException e) {
log.warn("[UserLog][Outbox] batch store fallback. size={}", rows.size(), e);
rows.forEach(this::storeRow);
rows.forEach(stateService::store);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

🛑 Blocking Issue: Fallback 로직의 예외 전파 차단

  • [문제 이유]: stateService.store(row) 호출 시 발생하는 예외(특히 UnexpectedRollbackException)가 forEach 루프 내부에서 처리되지 않습니다. 중복 데이터 등으로 인해 한 건이라도 실패하면 전체 루프가 중단되고 나머지 로그들이 저장되지 못합니다.
  • [해결 제안]: 루프 내부에서 개별적으로 예외를 처리하여 실패한 건을 제외한 나머지 데이터는 정상적으로 저장될 수 있도록 보장해야 합니다.
            rows.forEach(row -> {
                try {
                    stateService.store(row);
                } catch (Exception e) {
                    log.warn("[UserLog][Outbox] individual store failed. event_id={}", row.getEventId());
                }
            });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🗂️ area: BE 백엔드 영역 Customer Team deploy:api-server 배포 대상: customer-api 🐛 fix 기능에 대한 버그 수정 🚑 hotfix 프로덕션 긴급 수정(우회/긴급 패치 포함) ⚡ perf 성능 개선(쿼리/캐시/병목 제거 등) 🔥 priority: P0 즉시 처리 필요(서비스/데모 블로커) release:patch 버전 patch bump: X.Y.(Z+1) 🏷️ release 릴리즈 준비/버전 태깅/릴리즈 노트/릴리즈 브랜치 작업

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant