Commit c20dad2
authored
chore(jobsdb): disable no results cache state filter optimization (#6964)
🔒 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
- [x] The code changed/added as part of this pull request won't create
any security issues with how the software is being used.1 parent 8395174 commit c20dad2
3 files changed
Lines changed: 162 additions & 37 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
45 | | - | |
| 46 | + | |
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
588 | 588 | | |
589 | 589 | | |
590 | 590 | | |
591 | | - | |
592 | | - | |
593 | | - | |
594 | | - | |
595 | | - | |
596 | | - | |
597 | | - | |
598 | | - | |
599 | | - | |
600 | | - | |
601 | | - | |
602 | | - | |
603 | | - | |
604 | | - | |
605 | | - | |
606 | | - | |
607 | | - | |
608 | | - | |
609 | | - | |
610 | | - | |
611 | | - | |
612 | | - | |
613 | | - | |
614 | | - | |
615 | | - | |
616 | | - | |
617 | | - | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
618 | 619 | | |
619 | 620 | | |
620 | 621 | | |
| |||
1107 | 1108 | | |
1108 | 1109 | | |
1109 | 1110 | | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
1110 | 1115 | | |
1111 | 1116 | | |
1112 | 1117 | | |
| |||
2254 | 2259 | | |
2255 | 2260 | | |
2256 | 2261 | | |
| 2262 | + | |
2257 | 2263 | | |
2258 | | - | |
2259 | | - | |
2260 | | - | |
| 2264 | + | |
| 2265 | + | |
| 2266 | + | |
| 2267 | + | |
| 2268 | + | |
2261 | 2269 | | |
2262 | 2270 | | |
2263 | 2271 | | |
| |||
2390 | 2398 | | |
2391 | 2399 | | |
2392 | 2400 | | |
2393 | | - | |
2394 | | - | |
2395 | | - | |
2396 | 2401 | | |
2397 | 2402 | | |
2398 | 2403 | | |
2399 | 2404 | | |
| 2405 | + | |
| 2406 | + | |
| 2407 | + | |
| 2408 | + | |
| 2409 | + | |
| 2410 | + | |
| 2411 | + | |
2400 | 2412 | | |
2401 | 2413 | | |
2402 | | - | |
2403 | 2414 | | |
| 2415 | + | |
| 2416 | + | |
2404 | 2417 | | |
2405 | 2418 | | |
2406 | 2419 | | |
| |||
2410 | 2423 | | |
2411 | 2424 | | |
2412 | 2425 | | |
2413 | | - | |
| 2426 | + | |
2414 | 2427 | | |
2415 | 2428 | | |
2416 | 2429 | | |
| |||
2466 | 2479 | | |
2467 | 2480 | | |
2468 | 2481 | | |
2469 | | - | |
| 2482 | + | |
| 2483 | + | |
| 2484 | + | |
2470 | 2485 | | |
2471 | 2486 | | |
2472 | 2487 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1639 | 1639 | | |
1640 | 1640 | | |
1641 | 1641 | | |
| 1642 | + | |
| 1643 | + | |
| 1644 | + | |
| 1645 | + | |
| 1646 | + | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + | |
| 1653 | + | |
| 1654 | + | |
| 1655 | + | |
| 1656 | + | |
| 1657 | + | |
| 1658 | + | |
| 1659 | + | |
| 1660 | + | |
| 1661 | + | |
| 1662 | + | |
| 1663 | + | |
| 1664 | + | |
| 1665 | + | |
| 1666 | + | |
| 1667 | + | |
| 1668 | + | |
| 1669 | + | |
| 1670 | + | |
| 1671 | + | |
| 1672 | + | |
| 1673 | + | |
| 1674 | + | |
| 1675 | + | |
| 1676 | + | |
| 1677 | + | |
| 1678 | + | |
| 1679 | + | |
| 1680 | + | |
| 1681 | + | |
| 1682 | + | |
| 1683 | + | |
| 1684 | + | |
| 1685 | + | |
| 1686 | + | |
| 1687 | + | |
| 1688 | + | |
| 1689 | + | |
| 1690 | + | |
| 1691 | + | |
| 1692 | + | |
| 1693 | + | |
| 1694 | + | |
| 1695 | + | |
| 1696 | + | |
| 1697 | + | |
| 1698 | + | |
| 1699 | + | |
| 1700 | + | |
| 1701 | + | |
| 1702 | + | |
| 1703 | + | |
| 1704 | + | |
| 1705 | + | |
| 1706 | + | |
| 1707 | + | |
| 1708 | + | |
| 1709 | + | |
| 1710 | + | |
| 1711 | + | |
| 1712 | + | |
| 1713 | + | |
| 1714 | + | |
| 1715 | + | |
| 1716 | + | |
| 1717 | + | |
| 1718 | + | |
| 1719 | + | |
| 1720 | + | |
| 1721 | + | |
| 1722 | + | |
| 1723 | + | |
| 1724 | + | |
| 1725 | + | |
| 1726 | + | |
| 1727 | + | |
| 1728 | + | |
| 1729 | + | |
| 1730 | + | |
| 1731 | + | |
| 1732 | + | |
| 1733 | + | |
| 1734 | + | |
| 1735 | + | |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
1642 | 1751 | | |
1643 | 1752 | | |
1644 | 1753 | | |
| |||
0 commit comments