refactor(worker): split worker.c into focused worker-private modules#4
Merged
Conversation
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.
Summary
Split the monolithic
src/worker.c(2367 lines) into six focused modules undersrc/worker/andsrc/utils/, shrinking it to 525 lines (−78%). Behavior unchanged — six atomic, bisect-friendly commits.Why
worker.chad grown to mix worker lifecycle, the batch dispatch pipeline, circuit breaker SPI, retry math, dispatcher connection pooling, and periodic maintenance — all in one translation unit. This goes against the Clean Architecture discipline the rest of the tree already follows (core/,queue/,dispatchers/,config/,utils/), makes unit tests nearly impossible, and slows navigation for contributors and AI agents alike. Goal: preserve behavior exactly while extracting single-responsibility modules with minimal public surface.New modules
src/utils/retry_policy.{h,c}src/worker/dispatcher_cache.{h,c}before_shmem_exithooksrc/worker/maintenance.{h,c}src/worker/batch_types.hMessageBatchInfostructsrc/worker/circuit_breaker.{h,c}cb_try_half_open_transition,cb_update_after_dispatchSPI wrapperssrc/worker/batch_processor.{h,c}FOR UPDATE SKIP LOCKED), per-endpoint dispatch, status bookkeeping, DLQ archive, local stats flushworker.c now contains
Entry points (
ulak_worker_main,ulak_database_worker_main), signal handlers, the main loop, DSM param plumbing, and the startup stale-recovery call. 525 lines total.Commits (bisect-friendly)
refactor(worker): extract retry policy helpers into utils/retry_policyrefactor(worker): extract dispatcher cache into src/worker/dispatcher_cacherefactor(worker): extract periodic maintenance into src/worker/maintenancerefactor(worker): extract MessageBatchInfo and circuit breaker SPI wrappersrefactor(worker): extract batch processor into src/worker/batch_processorrefactor(worker): trim unused includes from worker.cValidation
Runs executed locally on PostgreSQL 18 inside the
ulak-postgresDocker container, with all protocols enabled (ENABLE_KAFKA=1 ENABLE_MQTT=1 ENABLE_REDIS=1 ENABLE_AMQP=1 ENABLE_NATS=1):make installcheck— 27/27 regress passed on every commitmake installcheck-isolation— 12/12 isolation passed on every commit (includingcircuit_breaker*,skip_locked,retry_visibility,dlq_concurrent_redrive)make installcheck-tap— 13/13 TAP passed (worker startup, SIGHUP reload, stale recovery)make formatmake lintmake hooks-runNot yet run locally — relying on CI
-fsanitize=address,undefined) — CI runs this on all 5 PG versionscppcheck+clang-tidy --warnings-as-errorsmake test-e2e(non-HTTP protocol produce/flush paths)The memory-context plumbing (batch context ownership transfer to
batch_processor.c) is the highest-risk change; CI's sanitizer runs on the matrix are the belt-and-suspenders check.Checklist