[REFAC#197] crawler/worker 의 lock 인프라 → internal/locks 분리 (메타 이슈 #195 단계 2) - #202
Conversation
📝 WalkthroughWalkthroughThis PR refactors the codebase to extract distributed lock infrastructure ( Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related issues
Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Review rate limit: 0/1 reviews remaining, refill in 60 minutes.Comment |
There was a problem hiding this comment.
Code Review
This pull request refactors the distributed locking infrastructure by moving ProcessingLock and IngestionLock from the crawler worker package into a new, dedicated internal/locks package. This change promotes a stage-agnostic architecture, allowing the fetcher, parser, and validator components to share the same locking logic consistently. The refactor includes updates to all dependent services, comprehensive documentation changes, and the relocation of associated tests. I have no feedback to provide as there were no review comments to evaluate.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
docs/architecture/internal/crawler/worker.md (1)
8-10: ⚡ Quick winAlign the external-systems section with the moved lock ownership.
Line 8 says lock infra moved to
internal/locks, but the external-systems table still includesIngestionLockunder crawler/worker scope, which is contradictory.Suggested doc fix
-| Redis | ProcessingLock (SETNX) / IngestionLock (SETNX) / RetryQueue (ZSET) | +| Redis | ProcessingLock (via internal/locks, SETNX) / RetryQueue (ZSET) |🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@docs/architecture/internal/crawler/worker.md` around lines 8 - 10, Update the external-systems section to reflect that lock ownership moved to internal/locks: remove the IngestionLock entry from the crawler/worker scope (or change its owner to internal/locks), and update the table row for locks to reference ProcessingLock (used as locks.ProcessingLock(stage="fetcher", url)) under internal/locks with a link to ../locks/README.md so the doc no longer contradicts the earlier statement about the moved lock infra.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@docs/architecture/internal/crawler/worker.md`:
- Around line 8-10: Update the external-systems section to reflect that lock
ownership moved to internal/locks: remove the IngestionLock entry from the
crawler/worker scope (or change its owner to internal/locks), and update the
table row for locks to reference ProcessingLock (used as
locks.ProcessingLock(stage="fetcher", url)) under internal/locks with a link to
../locks/README.md so the doc no longer contradicts the earlier statement about
the moved lock infra.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: e52b7880-7ba2-46d6-8887-445a009dfd93
📒 Files selected for processing (23)
.claude/rules/01-architecture.mdcmd/issuetracker/main.gocmd/processor/main.godocs/architecture/README.mddocs/architecture/cmd/README.mddocs/architecture/cmd/issuetracker.mddocs/architecture/cmd/processor.mddocs/architecture/internal/crawler/worker.mddocs/architecture/internal/locks/README.mddocs/architecture/internal/parser/README.mddocs/architecture/internal/processor/validate.mddocs/architecture/internal/publisher.mddocs/architecture/pkg/redis.mdinternal/crawler/worker/manager.gointernal/crawler/worker/pool.gointernal/locks/ingestion_lock.gointernal/locks/processing_lock.gointernal/parser/worker/parser_worker.gointernal/processor/validate/worker.gotest/internal/locks/ingestion_lock_test.gotest/internal/locks/processing_lock_test.gotest/internal/processor/validate/worker_test.gotest/internal/worker/processing_lock_pool_test.go
- internal/crawler/worker/{ingestion_lock,processing_lock}.go → internal/locks/
- 패키지명 worker → locks 변경 (단계 무관, fetcher/parser/validator 가 동등하게 import)
- 모든 caller import 갱신:
- cmd/{issuetracker,processor}/main.go
- internal/parser/worker/parser_worker.go (crawlerWorker import 제거)
- internal/processor/validate/worker.go (crawlerWorker import 제거)
- internal/crawler/worker/{manager,pool}.go (locks import 추가)
- 테스트 mirror 분리:
- test/internal/worker/{ingestion,processing}_lock_test.go → test/internal/locks/
- 단위 테스트 (NoopProcessingLock / ProcessingKey) 만 locks 디렉토리에 잔류
- pool 통합 테스트 (3건) 는 test/internal/worker/processing_lock_pool_test.go 로 이동 (test 헬퍼 의존)
내부 동작 / Redis 동작 / Kafka topic 변경 없음 — 디렉토리 이동 + 패키지명 + import 만.
git mv 로 history 보존.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- docs/architecture/internal/locks/README.md 신규 — ProcessingLock/IngestionLock 단일 doc - crawler/worker.md 에서 lock 관련 섹션 (ProcessingLock / IngestionLock) 제거 + locks 외부 링크 - 다른 doc (publisher.md / parser/README.md / processor/validate.md / pkg/redis.md / cmd/*.md / 최상 README.md) 의 lock 인용 위치를 internal/locks/README.md 로 갱신 - .claude/rules/01-architecture.md 디렉토리 트리에 internal/locks/ 항목 추가 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
연관 이슈
구현 내용
메타 이슈 #195 의 단계 2 —
internal/crawler/worker/의 단계 무관 lock 인프라를internal/locks/패키지로 분리. fetcher/parser/validator 모두 동등한 위치에서 import 가능한 hub 위치.코드 변경 (commit 1)
이동:
internal/crawler/worker/ingestion_lock.go→internal/locks/ingestion_lock.gointernal/crawler/worker/processing_lock.go→internal/locks/processing_lock.goworker→locks로 변경Caller import 갱신:
cmd/issuetracker/main.go—crawlerWorker유지 +locks추가 (RetryScheduler 등 다른 심볼 때문에 둘 다 필요)cmd/processor/main.go—crawlerWorker제거 +locks추가 (lock symbol만 사용)internal/parser/worker/parser_worker.go— 동일 (crawlerWorker import 제거)internal/processor/validate/worker.go— 동일internal/crawler/worker/{manager,pool}.go—locksimport 추가 (자기 패키지 내부에서 lock 사용)테스트 mirror 분리:
test/internal/worker/{ingestion,processing}_lock_test.go→test/internal/locks/processing_lock_test.go의 단위 테스트 (NoopProcessingLock_*, ProcessingKey_Determinism) 만 새 위치 잔류TestKafkaConsumerPool_ProcessingLock_*) 은 worker 패키지 헬퍼 의존이라test/internal/worker/processing_lock_pool_test.go로 별도 신설mockProcessingLock은 각자 패키지 안에서만 사용문서 변경 (commit 2)
docs/architecture/internal/locks/README.md신규 — 단일 패키지 docdocs/architecture/internal/crawler/worker.md— ProcessingLock / IngestionLock 섹션 제거 + locks 외부 링크 추가publisher.md/parser/README.md/processor/validate.md/pkg/redis.md/cmd/*.md/ 최상README.md) 의 lock 인용 위치 갱신.claude/rules/01-architecture.md디렉토리 트리에internal/locks/항목 추가변경 후 구조
CI / 머지 게이트 점검
변경 영향 범위
internal/crawler/worker/*(lock 부분 제거),internal/locks/*(신규),cmd/{issuetracker,processor}/main.go,internal/parser/worker/parser_worker.go,internal/processor/validate/worker.go,internal/crawler/worker/{manager,pool}.go(locks import), 다수 docs/architecture mdLow-Mediumgit mv로 git history 보존go build ./... && go test -race ./...28 패키지 모두 통과 (failure 0)IngestionLockinterface 그대로 동작 (구조적 의존성 영향 0)Required Status Checks
Commit LintPR Title LintLinked Issue CheckFormat CheckBuildTestLint롤백 계획
git revert2개 commit (코드 / 문서). DB / Redis / Kafka 영향 없음.TODO
internal/crawler/{core,handler,implementation,domain,rate_limiter,worker}→internal/processor/fetcher/...이동 + 메타 이슈 [REFAC] crawler → processor 정렬 — 파이프라인 단계별 디렉토리 재배치 (메타 이슈) #195 close논의 사항
RetryScheduler는 lock 과 함께 옮길지 검토했지만, 현재 fetcher worker 만 사용 + retry 발행 후의 priority topic 라우팅 책임이 있어 fetcher 영역에 잔류. 향후 parser/validator 도 retry queue 가 필요해지면 별도 sub-issue 로 단계 무관 위치로 이동 검토.CircuitBreaker/PriorityResolver는 fetcher 전용이라 잔류.🤖 Generated with Claude Code
Summary by CodeRabbit
Refactor
Tests