Skip to content

chore(jobsdb): disable no results cache state filter optimization - #6964

Merged
atzoum merged 4 commits into
masterfrom
chore.jobsdbStateOptimization
May 25, 2026
Merged

atzoum merged 4 commits into
masterfrom
chore.jobsdbStateOptimization

Conversation

@atzoum

@atzoum atzoum commented May 16, 2026 •

Copy link
Copy Markdown
Contributor

🔒 Scanned for secrets using gitleaks 8.30.1

Description

Makes the per-state noResultsCache optimization in jobsdb configurable, and disables it by default.

The optimization has two parts in getJobsDS:

  1. Read-side pruning — stateFilters are narrowed against the cache before querying, skipping states the cache reported as empty for the current (ds, partitions, workspace, customVals, params) key.
  2. Write-side commit predicate — when a queried state is absent from the result set and no limit was reached, a "no jobs of state X" entry is committed to the cache.

Both are now gated behind a single reloadable flag noResultsCacheStateOptimization:

  • JobsDB.<tablePrefix>.noResultsCacheStateOptimization
  • JobsDB.noResultsCacheStateOptimization

Default is false (optimization disabled).

Also fixes a variable-shadowing bug in getJobsDS where the outer payloadSize was never updated due to an inner shadow, making the post-loop payloadSize >= PayloadSizeLimit check dead code. As a result, LimitsReached was wrongly reported as false when the payload limit was reached at the boundary (exact total) or when a single oversize job exhausted the budget alone. This is one of the concrete mechanisms that can poison the noResultsCache — see the reasoning below.

Reasoning

We suspect the per-state optimization is the root cause of noResultsCache being populated with stale entries, which in turn leads to out-of-order processing: a state that actually has jobs is wrongly cached as empty, so subsequent reads skip those jobs from one dataset and process later jobs from another dataset first.

The write-side commit predicate (!ok && !limitsReached) assumes that when a state is missing from the result set and limits were not reached, we have exhaustively scanned the dataset for that state. This invariant can be broken by silent row-dropping filters that are not part of the cache key, or incorrect calculation of when limits are reached, and the resulting cache entry then poisons later reads.

The payloadSize shadowing bug fixed in this PR is a concrete instance of the second class: at the payload-budget boundary limitsReached was wrongly returned as false, so a state missing from the result set (e.g. because the budget was exhausted before any state-X row appeared) would satisfy (!ok && !limitsReached) and get committed to the cache as "no jobs for this state" — a stale entry that subsequent reads would honour, skipping real jobs and triggering out-of-order processing.

Disabling the per-state optimization by default keeps only the coarser len(jobList) == 0 commit path, which can only record "no rows at all" results and is therefore not vulnerable to per-state misattribution.

The optimization can be re-enabled per-deployment via the reloadable flag while we investigate and harden the invariants.

Linear Ticket

resolves PIPE-2994

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

@atzoum
atzoum force-pushed the chore.jobsdbStateOptimization branch from d957f12 to 6b97284 Compare May 16, 2026 11:55
@atzoum atzoum changed the title chore(jobsdb): make no results cache state filter optimization configurable chore(jobsdb): disable no results cache state filter optimization May 16, 2026
@codecov

codecov Bot commented May 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 61.53846% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.09%. Comparing base (8395174) to head (aee2f9e).

Files with missing lines Patch % Lines
jobsdb/jobsdb.go 66.66% 3 Missing and 1 partial ⚠️
.../migrator/partitionmigration/server/grpc_server.go 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6964   +/-   ##
=======================================
  Coverage   80.08%   80.09%           
=======================================
  Files         565      565           
  Lines       63807    63811    +4     
=======================================
+ Hits        51102    51107    +5     
- Misses       9661     9665    +4     
+ Partials     3044     3039    -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@atzoum
atzoum marked this pull request as ready for review May 18, 2026 06:15
@atzoum
atzoum force-pushed the chore.jobsdbStateOptimization branch 2 times, most recently from 04a9a20 to 7b84767 Compare May 19, 2026 11:45
@atzoum
atzoum force-pushed the chore.jobsdbStateOptimization branch 2 times, most recently from 7335bd7 to 8216db1 Compare May 21, 2026 07:07
Comment thread jobsdb/jobsdb.go Outdated
resultsetStates := map[string]struct{}{}
for rows.Next() {
var payloadSize int64
var rowPayloadSize int64

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

rowPayloadSize is not used, we do not need to read this

@atzoum atzoum May 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We need to scan as it is part of the resultset. But since we don't use it we can declare it before the for loop. 👍

@atzoum
atzoum requested a review from mihir20 May 22, 2026 14:15
@atzoum
atzoum force-pushed the chore.jobsdbStateOptimization branch 2 times, most recently from b97d3a8 to b31ff7a Compare May 22, 2026 18:42
atzoum added 4 commits May 25, 2026 09:02
…urable

🔒 Scanned for secrets using gitleaks 8.30.1
🔒 Scanned for secrets using gitleaks 8.30.1
🔒 Scanned for secrets using gitleaks 8.30.1
🔒 Scanned for secrets using gitleaks 8.30.1
@atzoum
atzoum force-pushed the chore.jobsdbStateOptimization branch from b31ff7a to aee2f9e Compare May 25, 2026 06:02
@atzoum
atzoum merged commit c20dad2 into master May 25, 2026
73 checks passed
@atzoum
atzoum deleted the chore.jobsdbStateOptimization branch May 25, 2026 07:14
This was referenced May 25, 2026
mihir20 pushed a commit that referenced this pull request May 25, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.76.0-rc.1](v1.75.0...v1.76.0-rc.1)
(2026-05-25)


### Features

* per-workspace PyT routing + cold-start handling
([#6978](#6978))
([d81e175](d81e175))
* periodic cleanup of rsources shared db tables
([#6945](#6945))
([ed0dfe7](ed0dfe7))


### Bug Fixes

* **batchrouter:** preserve prior LastJobStatus error on drain
([#6958](#6958))
([af31e62](af31e62))
* **batchrouter:** preserve prior LastJobStatus error on drain
([#6958](#6958))
([193f797](193f797))
* clickhouse quarter partition type
([#6965](#6965))
([af31e62](af31e62))
* continuous backend config cache cause postgres disk bloat
([#6983](#6983))
([f45aa06](f45aa06))
* ignore failed messages when source job run id exists
([#6981](#6981))
([045fdc0](045fdc0))
* server getting stuck during startup while initializing rsources
([#6943](#6943))
([62791fa](62791fa))
* snowpipe streaming bulk status offset
([#6966](#6966))
([af31e62](af31e62))


### Miscellaneous

* **ci:** workflow cleanup (SEC-284)
([#6949](#6949))
([516ba5b](516ba5b))
* **deps:** bump actions/upload-artifact from 7.0.0 to 7.0.1
([#6892](#6892))
([866f04d](866f04d))
* **deps:** bump aws-actions/amazon-ecr-login from 2.0.1 to 2.1.4
([#6956](#6956))
([89f1168](89f1168))
* **deps:** bump docker/login-action from 4.0.0 to 4.1.0
([#6881](#6881))
([5bca875](5bca875))
* **deps:** bump rudderlabs/build-scan-push-action from 1.8.2 to 2.2.0
([#6955](#6955))
([78cc895](78cc895))
* **deps:** bump step-security/harden-runner from 2.16.0 to 2.19.1
([#6957](#6957))
([cc5b578](cc5b578))
* **jobsdb:** disable no results cache state filter optimization
([#6964](#6964))
([c20dad2](c20dad2))
* **jobsdb:** release dsList read lock early during store
([#6963](#6963))
([a172404](a172404))
* pyt contracts for ipc and multi threading
([#6942](#6942))
([d570865](d570865))
* remove unused sed deletion method from GZIPLocalFileHandler
([#6974](#6974))
([d788760](d788760))
* replace deprecated WithCredentialsJSON with WithAuthCredentialsJSON
([#6986](#6986))
([8395174](8395174))
* sync release v1.75.0 to main branch
([#6954](#6954))
([f16fe93](f16fe93))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
mihir20 pushed a commit that referenced this pull request May 26, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.76.0](v1.75.0...v1.76.0)
(2026-05-25)


### Features

* per-workspace PyT routing + cold-start handling
([#6978](#6978))
([d81e175](d81e175))
* periodic cleanup of rsources shared db tables
([#6945](#6945))
([ed0dfe7](ed0dfe7))


### Bug Fixes

* **batchrouter:** preserve prior LastJobStatus error on drain
([#6958](#6958))
([af31e62](af31e62))
* **batchrouter:** preserve prior LastJobStatus error on drain
([#6958](#6958))
([193f797](193f797))
* clickhouse quarter partition type
([#6965](#6965))
([af31e62](af31e62))
* continuous backend config cache cause postgres disk bloat
([#6983](#6983))
([f45aa06](f45aa06))
* ignore failed messages when source job run id exists
([#6981](#6981))
([045fdc0](045fdc0))
* server getting stuck during startup while initializing rsources
([#6943](#6943))
([62791fa](62791fa))
* snowpipe streaming bulk status offset
([#6966](#6966))
([af31e62](af31e62))


### Miscellaneous

* **ci:** workflow cleanup (SEC-284)
([#6949](#6949))
([516ba5b](516ba5b))
* **deps:** bump actions/upload-artifact from 7.0.0 to 7.0.1
([#6892](#6892))
([866f04d](866f04d))
* **deps:** bump aws-actions/amazon-ecr-login from 2.0.1 to 2.1.4
([#6956](#6956))
([89f1168](89f1168))
* **deps:** bump docker/login-action from 4.0.0 to 4.1.0
([#6881](#6881))
([5bca875](5bca875))
* **deps:** bump rudderlabs/build-scan-push-action from 1.8.2 to 2.2.0
([#6955](#6955))
([78cc895](78cc895))
* **deps:** bump step-security/harden-runner from 2.16.0 to 2.19.1
([#6957](#6957))
([cc5b578](cc5b578))
* **jobsdb:** disable no results cache state filter optimization
([#6964](#6964))
([c20dad2](c20dad2))
* **jobsdb:** release dsList read lock early during store
([#6963](#6963))
([a172404](a172404))
* pyt contracts for ipc and multi threading
([#6942](#6942))
([d570865](d570865))
* remove unused sed deletion method from GZIPLocalFileHandler
([#6974](#6974))
([d788760](d788760))
* replace deprecated WithCredentialsJSON with WithAuthCredentialsJSON
([#6986](#6986))
([8395174](8395174))
* sync release v1.75.0 to main branch
([#6954](#6954))
([f16fe93](f16fe93))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants