[HSC-424] 로그 feature dispatch 날짜 및 enum 매핑 보완#282
Merged
Merged
Conversation
🧪 Test Coverage Report (JaCoCo)❗ JaCoCo XML not found:
|
| @Value("${app.userlog.admin-dispatch.max-attempts:5}") | ||
| private int maxAttempts; | ||
|
|
||
| @Transactional(propagation = Propagation.REQUIRES_NEW) |
There was a problem hiding this comment.
🛡️ 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
- 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); | ||
| } | ||
| } |
There was a problem hiding this comment.
🛑 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); |
There was a problem hiding this comment.
🛑 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());
}
});
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝작업 내용
👀변경 사항
🎫 Jira Ticket
#️⃣관련 이슈