Skip to content

[WIP] chore(jobsdb): refactor and cleanup - #7038

Closed
atzoum wants to merge 7 commits into
feat.compactLockEnabledfrom
chore.jobsdbRefactorCleanup
Closed

atzoum wants to merge 7 commits into
feat.compactLockEnabledfrom
chore.jobsdbRefactorCleanup

Conversation

@atzoum

@atzoum atzoum commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

@codecov

codecov Bot commented Jun 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.19349% with 312 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (feat.compactLockEnabled@71818a3). Learn more about missing BASE report.

Files with missing lines Patch % Lines
jobsdb/jobsdb_dataset.go 69.69% 108 Missing and 42 partials ⚠️
jobsdb/jobsdb_get.go 89.03% 32 Missing and 19 partials ⚠️
jobsdb/jobsdb_update.go 86.03% 25 Missing and 19 partials ⚠️
jobsdb/jobsdb_journal.go 68.03% 37 Missing and 2 partials ⚠️
jobsdb/jobsdb_store.go 89.20% 9 Missing and 6 partials ⚠️
jobsdb/jobsdb_compaction.go 86.59% 10 Missing and 3 partials ⚠️
Additional details and impacted files
@@                    Coverage Diff                     @@
##             feat.compactLockEnabled    #7038   +/-   ##
==========================================================
  Coverage                           ?   79.73%           
==========================================================
  Files                              ?      571           
  Lines                              ?    64549           
  Branches                           ?        0           
==========================================================
  Hits                               ?    51471           
  Misses                             ?    10012           
  Partials                           ?     3066           

☔ 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 force-pushed the feat.compactLockEnabled branch from cf3b79c to 71818a3 Compare June 2, 2026 13:20
@atzoum
atzoum force-pushed the chore.jobsdbRefactorCleanup branch from 77beed3 to 1aeea6b Compare June 2, 2026 13:20
@atzoum atzoum changed the title chore(jobsdb): refactor and cleanup [WIP] chore(jobsdb): refactor and cleanup Jun 2, 2026
@atzoum
atzoum force-pushed the chore.jobsdbRefactorCleanup branch from 1aeea6b to 8f5f3fb Compare June 2, 2026 15:09
@atzoum
atzoum force-pushed the feat.compactLockEnabled branch 2 times, most recently from 73b87e2 to 64089b0 Compare June 3, 2026 07:36
atzoum added a commit that referenced this pull request Jun 3, 2026
…ale ds error while updating job statuses (#7024)

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

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

## Linear Ticket

resolves PIPE-2997

## 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 1 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 -->
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 -->
@atzoum atzoum closed this Jun 3, 2026
@atzoum
atzoum deleted the chore.jobsdbRefactorCleanup branch June 3, 2026 08:28
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.

1 participant