Repository navigation
feat(batchrouter): introduce isolation levels and concurrency limiters - #3248
Merged
Merged
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #3248 +/- ##
==========================================
+ Coverage 52.03% 52.53% +0.50%
==========================================
Files 321 327 +6
Lines 53191 53242 +51
==========================================
+ Hits 27677 27970 +293
+ Misses 23864 23634 -230
+ Partials 1650 1638 -12
☔ View full report in Codecov by Sentry. |
atzoum
force-pushed
the
refactor.batchrouterWorkers
branch
from
April 26, 2023 11:28
dd1df6f to
a65b5b9
Compare
atzoum
force-pushed
the
refactor.batchrouterWorkers
branch
9 times, most recently
from
May 3, 2023 18:23
8306547 to
cfd5163
Compare
atzoum
force-pushed
the
refactor.batchrouterWorkers
branch
from
May 4, 2023 07:26
cfd5163 to
1cc9965
Compare
atzoum
force-pushed
the
refactor.batchrouterWorkers
branch
3 times, most recently
from
May 5, 2023 11:17
0653460 to
3a783ef
Compare
atzoum
requested review from
BonapartePC,
Sidddddarth,
achettyiitr,
cisse21,
fracasula,
koladilip,
lvrach,
pChondros and
saurav-malani
May 5, 2023 12:05
atzoum
force-pushed
the
refactor.batchrouterWorkers
branch
from
May 10, 2023 05:44
0779771 to
74f0771
Compare
cisse21
approved these changes
May 10, 2023
pChondros
approved these changes
May 10, 2023
atzoum
force-pushed
the
refactor.batchrouterWorkers
branch
8 times, most recently
from
May 11, 2023 07:00
e933141 to
3b182e2
Compare
atzoum
force-pushed
the
refactor.batchrouterWorkers
branch
from
May 11, 2023 07:01
3b182e2 to
ef91440
Compare
1 task done
Closed
Merged
This was referenced May 19, 2023
achettyiitr
added a commit
that referenced
this pull request
Sep 24, 2026
There were no tests for warehouseServiceFailedTime, warehouseServiceMaxRetryTime or updateJobStatus, which is how the zero-timestamp abort survived since #3248. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012YX6Cdjs6iKeJCtzm9udju
achettyiitr
added a commit
that referenced
this pull request
Sep 29, 2026
…tamp (#7426) Linear: [INT-7231](https://linear.app/rudderstack/issue/INT-7231/batch-router-aborts-warehouse-jobs-with-410-on-a-zero-failure) ## Problem `warehouseServiceFailedTime` gates whether jobs waiting on a failing warehouse service are retried or aborted with `410`. It is meant to give them `BatchRouter.warehouseServiceMaxRetryTime` (default 3h) before giving up. In practice it can abort them on their first attempt. Three things combine (`router/batchrouter/handle.go`): 1. **The field is shared.** `Factory.New(destType)` creates one `Handle` per destType, so a single `warehouseServiceFailedTime` describes "is the warehouse service failing" for every destination of that destType in the process. 2. **Any success zeroes it.** The `else if isWarehouse` arm resets it to `time.Time{}` on every warehouse batch that is not a ping failure — including all the successful ones. 3. **The check re-read the shared field** after setting it, rather than using the value it had just written. `updateJobStatus` runs under `BatchRouter.Limiter.upload.limit` (default **200**) concurrent goroutines on the same `Handle`, so a concurrent success can zero the field between the write and the read. `time.Since(time.Time{})` is roughly 2,025 years, which exceeds any retry window, so the guard aborts unconditionally when it reads a zero. ## Production impact `entusmtprod` / `enterprise-rudder`, 2026-09-23. A workspace migration edited `Warehouse.degradedWorkspaceIDs` three times in 40 minutes. That key is read with the non-reloadable getter and the operator sets `shutdownOnNonReloadableConfigChange: true`, so the shared warehouse service restarted three times. `pingWarehouse` POSTs to `/v1/process` failed during the restarts: ``` dial tcp 172.20.230.47:80: connect: connection refused context deadline exceeded (Client.Timeout exceeded while awaiting headers) ``` - **173 destinations across 108 workspaces**, 210,301 events, got `500`, retried, and delivered once the service returned — the whole cycle took about two minutes. - **4 destinations lost 1,499 events** to terminal `410` aborts. The sampled reporting row shows `firstAttemptedAt 2026-09-23T20:02:37.175Z`, and the abort counter reads its final value by `20:03:00Z` — **aborted 23 seconds after the job's first attempt**, on attempt one. Neither retry policy can produce that. `retryLimitReached` needs `AttemptNum >= 128` **and** `time.Since(firstAttemptedAt) > retryTimeWindow` (24h on this cluster), and it is gated on `!notifyWarehouseErr` so it was never evaluated. The warehouse branch needs 3 hours. The only way to get 23 seconds is a comparison against the zero time. During the failing two-minute window `generate_staging_files` shows ~2,576 batch completions in `entusmtprod` — roughly 20 calls per second into this code path, most of them successes zeroing the field. ## Change Capture the failure start under the same lock that sets it, and check that local copy: ```go var warehouseServiceFailedSince time.Time if isWarehouse && notifyWarehouseErr { brt.warehouseServiceFailedTimeMu.Lock() if brt.warehouseServiceFailedTime.IsZero() { brt.warehouseServiceFailedTime = time.Now() } warehouseServiceFailedSince = brt.warehouseServiceFailedTime brt.warehouseServiceFailedTimeMu.Unlock() } ``` and move the decision into a named method that refuses to abort on a zero: ```go func (brt *Handle) warehouseServiceRetryLimitReached(failedSince time.Time) bool { if failedSince.IsZero() { return false } return time.Since(failedSince) > brt.warehouseServiceMaxRetryTime.Load() } ``` The zero check is deliberately belt-and-braces: with the capture in place the guard should never see a zero, but if it ever does the safe direction is to retry, not to discard customer data. ## Verification ``` go test ./router/batchrouter/ -run TestWarehouseServiceRetryLimitReached -race -count=1 ok github.com/rudderlabs/rudder-server/router/batchrouter ``` The test fails without the fix — removing the `IsZero` guard produces: ``` --- FAIL: TestWarehouseServiceRetryLimitReached/zero_failedSince_never_aborts Should be false a zero failure start must not abort: it is year 1 and exceeds every retry window ``` `go build ./router/...` and `go vet ./router/batchrouter/` are clean. There were **no existing tests** for `warehouseServiceFailedTime`, `warehouseServiceMaxRetryTime` or `updateJobStatus`, which is how this survived since #3248 (May 2023). ## Deliberately not in this PR The field is still shared across every destination of a destType, so one destination's success still clears the failure clock for the others. That means the 3-hour window can struggle to accumulate on a busy shared namespace and the guard will under-abort. That is the safe direction, and fixing it properly means keying the state by destination — a larger change worth doing separately. ## Not proven The exact interleaving for those four destinations is deduced, not observed: nothing logs or counts the reset. It is the only remaining mechanism after ruling out `retryLimitReached` (arithmetically impossible at 23s), a configuration override (no override in the operator or devops repos), the drainer path (emits `drained_events`, which is absent for these destinations), and `degradedWorkspaceIDs` (only filters config; the degraded workspace itself had zero aborts, and none of the four was ever on the list). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_012YX6Cdjs6iKeJCtzm9udju --------- Co-authored-by: Claude Opus 5 <[email protected]>
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.
Description
Introducing isolation strategies in batchrouter, following the pattern we are already using in processor.
The following isolation modes are now supported in batchrouter:
none- a single worker retrieves and processes jobs for all workspaces & destinationsworkspace- using a separate worker per workspace (default mode in multi-tenant deployments)destination- using a separate worker per destination (default mode in non-multi-tenant deployments)To avoid proliferation of busy goroutines, we are introducing 3 limiters:
read- for reading jobs from jobsdb (limit: 20 goroutines/destType)process- for controlling concurrency while processing jobs grouped by destination (limit: 20 goroutines/destType)upload- for controlling concurrency while uploading files grouped by source & destination (limit: 50 goroutines/destType)Upload frequency adaptations
In the new design, upload frequency is still honoured, but only as long as jobsdb's read limits are not being reached (limited by the number of events and/or total payload size). If a worker detects that jobsdb's limits are reached, it disregards upload frequency restrictions, until the backlog is flushed.
Side-effects of upload frequency adaptations in the context of isolation modes:
none: destinations with sparse jobs will be processed more frequently when limits are reached for any other destination.workspace: destinations with sparse jobs will be processed more frequently when limits are reached for any other destination beloning to the same workspace.destination: none, only destinations with large backlog will be processed more frequently when limits are reached.Performance
Similarly to what has already been observed in processor, both isolation modes (
workspace&destination) perform equally well withnoneup to a cardinality of 200. After that, throughput starts deteriorating, which is an acceptable toll to pay, taking into consideration the other advantages associated with isolation (i.e. one customer/destination not affecting the other).The relevant benchmark can be found inside
batchrouter_isolation_test.goand a visualisation of one execution of this benchmark is available here.Other notable changes
workerpool, so that it can be shared between processor and batchrouter.Initfunction from the package.unionjobsdbmetadatawhich is a faster version ofunionjobsdb, since it doesn't include the payloads in the resultsets.Notion Ticket
Link
Security