Skip to content

chore(jobsdb): avoid refreshing ds list from database in case of a stale ds error while updating job statuses - #7024

Merged
atzoum merged 3 commits into
masterfrom
fix.updateJobStatusRefresh
Jun 3, 2026
Merged

atzoum merged 3 commits into
masterfrom
fix.updateJobStatusRefresh

Conversation

@atzoum

@atzoum atzoum commented May 30, 2026 •

Copy link
Copy Markdown
Contributor

Description

When updating job statuses, if a background compaction/migration has changed the dataset (DS) layout, the update hits a stale DS list (ErrStaleDsList) and retries. Previously the retry re-read the DS list from the database, which needs a connection from the main pool — so under high concurrency (in-flight updaters ≥ pool size) every connection is already in use, leaving none to perform the refresh, which can stall the whole update path.

The in-memory DS list cache is already kept up to date by the compaction/migration loop, so the retry doesn't need to touch the database. We now refresh from that cached snapshot under a read lock instead, removing the connection requirement from the retry path entirely.

Benchmark

A new compaction jobsdb bench scenario (TestBench/compaction) drains a read-write jobsdb seeded with 2M jobs (20 datasets × 100K, 3KB payload) across 100 destinations, using 100 consumer goroutines against a pool of 80 connections, and measures the time for all consumers to fully drain. It is also used to compare the available compaction strategies under an identical workload.

Run it with:

RUN_COMPACTION_BENCH=1 GOMAXPROCS=2 go test ./jobsdb/bench/ -run 'TestBench/compaction' -v -timeout 30m

Drain time for 2M jobs (lower is better):

Scenario Time vs. baseline
baseline (blocking compaction) 2m56.6s —
nonBlockingCompletedDSDrop 2m10.9s −25.9%
nonBlockingCompaction 1m54.8s −35.0%

Linear Ticket

resolves PIPE-2997

Security

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

This is part 1 of 4 in a stack made with GitButler:

@atzoum
atzoum requested review from ktgowtham and mihir20 May 30, 2026 14:06
@atzoum
atzoum force-pushed the fix.updateJobStatusRefresh branch from 6dac608 to 23b1a9a Compare May 30, 2026 14:13
@codecov

codecov Bot commented May 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 8.30450% with 265 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.72%. Comparing base (0dcf2b4) to head (93029bf).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
jobsdb/bench/scenario/compaction.go 0.00% 258 Missing ⚠️
jobsdb/jobsdb.go 66.66% 4 Missing and 1 partial ⚠️
jobsdb/bench/bench.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7024      +/-   ##
==========================================
- Coverage   79.77%   79.72%   -0.06%     
==========================================
  Files         566      567       +1     
  Lines       64321    64599     +278     
==========================================
+ Hits        51312    51501     +189     
- Misses       9964    10029      +65     
- Partials     3045     3069      +24     

☔ 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.

@mihir20 mihir20 left a comment

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.

LGTM

@atzoum
atzoum force-pushed the fix.updateJobStatusRefresh branch from 11cc801 to 93029bf Compare June 3, 2026 07:36
@atzoum
atzoum enabled auto-merge (squash) June 3, 2026 07:37
@atzoum
atzoum disabled auto-merge June 3, 2026 07:51
@atzoum
atzoum merged commit de98ede into master Jun 3, 2026
69 checks passed
@atzoum
atzoum deleted the fix.updateJobStatusRefresh branch June 3, 2026 07:51
atzoum added a commit that referenced this pull request Jun 3, 2026
# Description

During non-blocking compaction, the source job status table is locked
`EXCLUSIVE` early, before jobs are copied to the destination. Because
the job copy includes the (potentially large) `event_payload`, the bulk
of the lock window is spent moving data that does not actually need the
lock — status updates for jobs in that dataset are blocked for the whole
copy.

This PR adds an opt-in mode (`compactionDeferStatusLock`, off by
default) that splits the copy into two phases:

1. **Copy pending jobs first, with no status lock held** — the slow,
payload-heavy work.
2. **Then lock each source status table one after another** only to copy
the latest statuses of the jobs that were moved.

The result is that the status-table lock window shrinks to roughly the
(small, payload-free) status copy, minimizing how long status updates
are blocked. As a side-effect, jobs that complete between the two phases
are still moved to the new table (now carrying their terminal status).
These few extra completed rows will get reclaimed on the next
compaction.

#7021 runs all tests with this feature enabled

## Benchmark

Deferring the status lock shaves a further ~12% off
`nonBlockingCompaction` alone.
Run it with:

```bash
RUN_COMPACTION_BENCH=1 GOMAXPROCS=2 go test ./jobsdb/bench/ -run 'TestBench/compaction' -v -timeout 30m
```

Drain time for 2M jobs (lower is better):

| Scenario | Time | vs. baseline |
| ------------------------------------------ | --------- | ------------
|
| baseline (blocking compaction) | 2m56.6s | — |
| nonBlockingCompletedDSDrop | 2m10.9s | −25.9% |
| nonBlockingCompaction | 1m54.8s | −35.0% |
| nonBlockingCompaction + deferStatusLock | 1m40.7s | −43.0% |

## Linear Ticket

resolves PIPE-3064

## 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.

<!-- GitButler Footer Boundary Top -->
---
This is **part 2 of 4 in a stack** made with GitButler:
- <kbd>&nbsp;4&nbsp;</kbd> #7038 
- <kbd>&nbsp;3&nbsp;</kbd> #7021 
- <kbd>&nbsp;2&nbsp;</kbd> #7020 👈 
- <kbd>&nbsp;1&nbsp;</kbd> #7024 
<!-- GitButler Footer Boundary Bottom -->
This was referenced Jun 8, 2026
itsmihir pushed a commit that referenced this pull request Jun 8, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.77.0-rc.1](v1.76.0...v1.77.0-rc.1)
(2026-06-08)


### Features

* **jobsdb:** deferred status table lock during compaction
([#7020](#7020))
([d156057](d156057))
* **jobsdb:** non-blocking dataset compaction
([#6967](#6967))
([e0838dc](e0838dc))
* **jobsdb:** versioned dataset list and non-blocking drop for completed
datasets
([#6962](#6962))
([d7fe1ae](d7fe1ae))


### Bug Fixes

* flaky cluster test
([#7003](#7003))
([d7fe1ae](d7fe1ae))
* **jobsdb:** pq 42P01 error when trying to store to a dataset that has
been dropped
([#7041](#7041))
([9db406d](9db406d))
* server panics with sql database is closed in case of an etcd error
([#7023](#7023))
([15dc39a](15dc39a))
* support scoped batchrouter datePrefixOverride
([#7037](#7037))
([9e8a0a8](9e8a0a8))


### Miscellaneous

* capture scheduler lag in stats
([#7017](#7017))
([0dcf2b4](0dcf2b4))
* **deps:** bump actions/create-github-app-token from 3.0.0 to 3.1.1
([#6969](#6969))
([ee7f735](ee7f735))
* **deps:** bump actions/create-github-app-token from 3.1.1 to 3.2.0
([#7013](#7013))
([ac5681b](ac5681b))
* **deps:** bump actions/labeler from 5.0.0 to 6.1.0
([#6970](#6970))
([e748b86](e748b86))
* **deps:** bump actions/stale from 10.2.0 to 10.3.0
([#7031](#7031))
([6cf6804](6cf6804))
* **deps:** bump aws-actions/amazon-ecr-login from 2.1.4 to 2.1.5
([#6972](#6972))
([e38a99d](e38a99d))
* **deps:** bump aws-actions/configure-aws-credentials from 5.0.0 to
6.1.1 ([#6971](#6971))
([1114b7f](1114b7f))
* **deps:** bump aws-actions/configure-aws-credentials from 6.1.1 to
6.1.2 ([#7049](#7049))
([e210e68](e210e68))
* **deps:** bump codecov/codecov-action from 6.0.0 to 6.0.1
([#7016](#7016))
([3d639f5](3d639f5))
* **deps:** bump docker/login-action from 4.1.0 to 4.2.0
([#7035](#7035))
([b39183b](b39183b))
* **deps:** bump docker/metadata-action from 6.0.0 to 6.1.0
([#7032](#7032))
([574f7c8](574f7c8))
* **deps:** bump docker/setup-buildx-action from 4.0.0 to 4.1.0
([#7034](#7034))
([ff49009](ff49009))
* **deps:** bump golangci/golangci-lint-action from 8.0.0 to 9.2.1
([#7044](#7044))
([56070dc](56070dc))
* **deps:** bump slackapi/slack-github-action from 3.0.1 to 3.0.3
([#6968](#6968))
([fd70e60](fd70e60))
* **deps:** bump step-security/harden-runner from 2.19.1 to 2.19.3
([#7012](#7012))
([b4dc9b2](b4dc9b2))
* **deps:** bump step-security/harden-runner from 2.19.3 to 2.19.4
([#7033](#7033))
([ba82100](ba82100))
* **jobsdb:** avoid refreshing ds list from database in case of a stale
ds error while updating job statuses
([#7024](#7024))
([de98ede](de98ede))
* **jobsdb:** lateral join for getting jobs
([#7007](#7007))
([7148a30](7148a30))
* remove deprecated bulkStatusEnabled flag for snowpipe streaming
([#6992](#6992))
([d7fe1ae](d7fe1ae))

---
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>
This was referenced Jun 8, 2026
atzoum pushed a commit that referenced this pull request Jun 8, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.77.0-rc.2](v1.76.0...v1.77.0-rc.2)
(2026-06-08)


### Features

* **jobsdb:** deferred status table lock during compaction
([#7020](#7020))
([d156057](d156057))
* **jobsdb:** non-blocking dataset compaction
([#6967](#6967))
([e0838dc](e0838dc))
* **jobsdb:** versioned dataset list and non-blocking drop for completed
datasets
([#6962](#6962))
([d7fe1ae](d7fe1ae))


### Bug Fixes

* flaky cluster test
([#7003](#7003))
([d7fe1ae](d7fe1ae))
* **jobsdb:** pq 42P01 error when trying to store to a dataset that has
been dropped
([#7041](#7041))
([9db406d](9db406d))
* **jobsdb:** stale table count gauge after dropping dataset async
([#7063](#7063))
([4abb293](4abb293))
* server panics with sql database is closed in case of an etcd error
([#7023](#7023))
([15dc39a](15dc39a))
* support scoped batchrouter datePrefixOverride
([#7037](#7037))
([9e8a0a8](9e8a0a8))


### Miscellaneous

* capture scheduler lag in stats
([#7017](#7017))
([0dcf2b4](0dcf2b4))
* **deps:** bump actions/create-github-app-token from 3.0.0 to 3.1.1
([#6969](#6969))
([ee7f735](ee7f735))
* **deps:** bump actions/create-github-app-token from 3.1.1 to 3.2.0
([#7013](#7013))
([ac5681b](ac5681b))
* **deps:** bump actions/labeler from 5.0.0 to 6.1.0
([#6970](#6970))
([e748b86](e748b86))
* **deps:** bump actions/stale from 10.2.0 to 10.3.0
([#7031](#7031))
([6cf6804](6cf6804))
* **deps:** bump aws-actions/amazon-ecr-login from 2.1.4 to 2.1.5
([#6972](#6972))
([e38a99d](e38a99d))
* **deps:** bump aws-actions/configure-aws-credentials from 5.0.0 to
6.1.1 ([#6971](#6971))
([1114b7f](1114b7f))
* **deps:** bump aws-actions/configure-aws-credentials from 6.1.1 to
6.1.2 ([#7049](#7049))
([e210e68](e210e68))
* **deps:** bump codecov/codecov-action from 6.0.0 to 6.0.1
([#7016](#7016))
([3d639f5](3d639f5))
* **deps:** bump docker/login-action from 4.1.0 to 4.2.0
([#7035](#7035))
([b39183b](b39183b))
* **deps:** bump docker/metadata-action from 6.0.0 to 6.1.0
([#7032](#7032))
([574f7c8](574f7c8))
* **deps:** bump docker/setup-buildx-action from 4.0.0 to 4.1.0
([#7034](#7034))
([ff49009](ff49009))
* **deps:** bump golangci/golangci-lint-action from 8.0.0 to 9.2.1
([#7044](#7044))
([56070dc](56070dc))
* **deps:** bump slackapi/slack-github-action from 3.0.1 to 3.0.3
([#6968](#6968))
([fd70e60](fd70e60))
* **deps:** bump step-security/harden-runner from 2.19.1 to 2.19.3
([#7012](#7012))
([b4dc9b2](b4dc9b2))
* **deps:** bump step-security/harden-runner from 2.19.3 to 2.19.4
([#7033](#7033))
([ba82100](ba82100))
* **jobsdb:** avoid refreshing ds list from database in case of a stale
ds error while updating job statuses
([#7024](#7024))
([de98ede](de98ede))
* **jobsdb:** lateral join for getting jobs
([#7007](#7007))
([7148a30](7148a30))
* remove deprecated bulkStatusEnabled flag for snowpipe streaming
([#6992](#6992))
([d7fe1ae](d7fe1ae))

---
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>
This was referenced Jun 8, 2026
atzoum pushed a commit that referenced this pull request Jun 8, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.77.0-rc.3](v1.76.0...v1.77.0-rc.3)
(2026-06-08)


### Features

* **jobsdb:** deferred status table lock during compaction
([#7020](#7020))
([d156057](d156057))
* **jobsdb:** non-blocking dataset compaction
([#6967](#6967))
([e0838dc](e0838dc))
* **jobsdb:** versioned dataset list and non-blocking drop for completed
datasets
([#6962](#6962))
([d7fe1ae](d7fe1ae))


### Bug Fixes

* flaky cluster test
([#7003](#7003))
([d7fe1ae](d7fe1ae))
* **jobsdb:** jobsdb_lock_total_time for dsMigrationLock missing
([#7066](#7066))
([7e00370](7e00370))
* **jobsdb:** pq 42P01 error when trying to store to a dataset that has
been dropped
([#7041](#7041))
([9db406d](9db406d))
* **jobsdb:** stale table count gauge after dropping dataset async
([#7063](#7063))
([4abb293](4abb293))
* server panics with sql database is closed in case of an etcd error
([#7023](#7023))
([15dc39a](15dc39a))
* support scoped batchrouter datePrefixOverride
([#7037](#7037))
([9e8a0a8](9e8a0a8))


### Miscellaneous

* capture scheduler lag in stats
([#7017](#7017))
([0dcf2b4](0dcf2b4))
* **deps:** bump actions/create-github-app-token from 3.0.0 to 3.1.1
([#6969](#6969))
([ee7f735](ee7f735))
* **deps:** bump actions/create-github-app-token from 3.1.1 to 3.2.0
([#7013](#7013))
([ac5681b](ac5681b))
* **deps:** bump actions/labeler from 5.0.0 to 6.1.0
([#6970](#6970))
([e748b86](e748b86))
* **deps:** bump actions/stale from 10.2.0 to 10.3.0
([#7031](#7031))
([6cf6804](6cf6804))
* **deps:** bump aws-actions/amazon-ecr-login from 2.1.4 to 2.1.5
([#6972](#6972))
([e38a99d](e38a99d))
* **deps:** bump aws-actions/configure-aws-credentials from 5.0.0 to
6.1.1 ([#6971](#6971))
([1114b7f](1114b7f))
* **deps:** bump aws-actions/configure-aws-credentials from 6.1.1 to
6.1.2 ([#7049](#7049))
([e210e68](e210e68))
* **deps:** bump codecov/codecov-action from 6.0.0 to 6.0.1
([#7016](#7016))
([3d639f5](3d639f5))
* **deps:** bump docker/login-action from 4.1.0 to 4.2.0
([#7035](#7035))
([b39183b](b39183b))
* **deps:** bump docker/metadata-action from 6.0.0 to 6.1.0
([#7032](#7032))
([574f7c8](574f7c8))
* **deps:** bump docker/setup-buildx-action from 4.0.0 to 4.1.0
([#7034](#7034))
([ff49009](ff49009))
* **deps:** bump golangci/golangci-lint-action from 8.0.0 to 9.2.1
([#7044](#7044))
([56070dc](56070dc))
* **deps:** bump slackapi/slack-github-action from 3.0.1 to 3.0.3
([#6968](#6968))
([fd70e60](fd70e60))
* **deps:** bump step-security/harden-runner from 2.19.1 to 2.19.3
([#7012](#7012))
([b4dc9b2](b4dc9b2))
* **deps:** bump step-security/harden-runner from 2.19.3 to 2.19.4
([#7033](#7033))
([ba82100](ba82100))
* **jobsdb:** avoid refreshing ds list from database in case of a stale
ds error while updating job statuses
([#7024](#7024))
([de98ede](de98ede))
* **jobsdb:** lateral join for getting jobs
([#7007](#7007))
([7148a30](7148a30))
* remove deprecated bulkStatusEnabled flag for snowpipe streaming
([#6992](#6992))
([d7fe1ae](d7fe1ae))

---
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>
itsmihir pushed a commit that referenced this pull request Jun 9, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.77.0](v1.76.0...v1.77.0)
(2026-06-08)


### Features

* **jobsdb:** deferred status table lock during compaction
([#7020](#7020))
([d156057](d156057))
* **jobsdb:** non-blocking dataset compaction
([#6967](#6967))
([e0838dc](e0838dc))
* **jobsdb:** versioned dataset list and non-blocking drop for completed
datasets
([#6962](#6962))
([d7fe1ae](d7fe1ae))


### Bug Fixes

* flaky cluster test
([#7003](#7003))
([d7fe1ae](d7fe1ae))
* **jobsdb:** jobsdb_lock_total_time for dsMigrationLock missing
([#7066](#7066))
([7e00370](7e00370))
* **jobsdb:** pq 42P01 error when trying to store to a dataset that has
been dropped
([#7041](#7041))
([9db406d](9db406d))
* **jobsdb:** stale table count gauge after dropping dataset async
([#7063](#7063))
([4abb293](4abb293))
* server panics with sql database is closed in case of an etcd error
([#7023](#7023))
([15dc39a](15dc39a))
* support scoped batchrouter datePrefixOverride
([#7037](#7037))
([9e8a0a8](9e8a0a8))


### Miscellaneous

* capture scheduler lag in stats
([#7017](#7017))
([0dcf2b4](0dcf2b4))
* **deps:** bump actions/create-github-app-token from 3.0.0 to 3.1.1
([#6969](#6969))
([ee7f735](ee7f735))
* **deps:** bump actions/create-github-app-token from 3.1.1 to 3.2.0
([#7013](#7013))
([ac5681b](ac5681b))
* **deps:** bump actions/labeler from 5.0.0 to 6.1.0
([#6970](#6970))
([e748b86](e748b86))
* **deps:** bump actions/stale from 10.2.0 to 10.3.0
([#7031](#7031))
([6cf6804](6cf6804))
* **deps:** bump aws-actions/amazon-ecr-login from 2.1.4 to 2.1.5
([#6972](#6972))
([e38a99d](e38a99d))
* **deps:** bump aws-actions/configure-aws-credentials from 5.0.0 to
6.1.1 ([#6971](#6971))
([1114b7f](1114b7f))
* **deps:** bump aws-actions/configure-aws-credentials from 6.1.1 to
6.1.2 ([#7049](#7049))
([e210e68](e210e68))
* **deps:** bump codecov/codecov-action from 6.0.0 to 6.0.1
([#7016](#7016))
([3d639f5](3d639f5))
* **deps:** bump docker/login-action from 4.1.0 to 4.2.0
([#7035](#7035))
([b39183b](b39183b))
* **deps:** bump docker/metadata-action from 6.0.0 to 6.1.0
([#7032](#7032))
([574f7c8](574f7c8))
* **deps:** bump docker/setup-buildx-action from 4.0.0 to 4.1.0
([#7034](#7034))
([ff49009](ff49009))
* **deps:** bump golangci/golangci-lint-action from 8.0.0 to 9.2.1
([#7044](#7044))
([56070dc](56070dc))
* **deps:** bump slackapi/slack-github-action from 3.0.1 to 3.0.3
([#6968](#6968))
([fd70e60](fd70e60))
* **deps:** bump step-security/harden-runner from 2.19.1 to 2.19.3
([#7012](#7012))
([b4dc9b2](b4dc9b2))
* **deps:** bump step-security/harden-runner from 2.19.3 to 2.19.4
([#7033](#7033))
([ba82100](ba82100))
* **jobsdb:** avoid refreshing ds list from database in case of a stale
ds error while updating job statuses
([#7024](#7024))
([de98ede](de98ede))
* **jobsdb:** lateral join for getting jobs
([#7007](#7007))
([7148a30](7148a30))
* remove deprecated bulkStatusEnabled flag for snowpipe streaming
([#6992](#6992))
([d7fe1ae](d7fe1ae))

---
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