Skip to content

[WIP] feat(jobsdb): deferred status table lock during compaction (enabled by default) - #7021

Closed
atzoum wants to merge 5 commits into
feat.compactLockfrom
feat.compactLockEnabled
Closed

atzoum wants to merge 5 commits into
feat.compactLockfrom
feat.compactLockEnabled

Conversation

@atzoum

@atzoum atzoum commented May 29, 2026 •

Copy link
Copy Markdown
Contributor

Description

Running all tests with nonBlockingCompaction: true & compactionDeferStatusLock: true

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 3 of 4 in a stack made with GitButler:

@codecov

codecov Bot commented May 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.41%. Comparing base (8f7eadc) to head (73b87e2).

Additional details and impacted files
@@                 Coverage Diff                  @@
##           feat.compactLock    #7021      +/-   ##
====================================================
- Coverage             79.41%   79.41%   -0.01%     
====================================================
  Files                   567      567              
  Lines                 64683    64683              
====================================================
- Hits                  51369    51366       -3     
- Misses                10256    10261       +5     
+ Partials               3058     3056       -2     

☔ 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 2 times, most recently from 8b7e437 to c9db23f Compare May 30, 2026 13:56
@atzoum
atzoum changed the base branch from master to feat.compactLock May 30, 2026 14:05
@atzoum
atzoum force-pushed the feat.compactLock branch from a8abd3f to 87430da Compare May 30, 2026 14:13
@atzoum
atzoum force-pushed the feat.compactLockEnabled branch from c9db23f to db2d474 Compare May 30, 2026 14:13
@atzoum
atzoum requested review from ktgowtham and mihir20 May 30, 2026 14:14
@atzoum
atzoum force-pushed the feat.compactLock branch from 87430da to fcb2117 Compare May 31, 2026 10:19
@atzoum
atzoum force-pushed the feat.compactLockEnabled branch from db2d474 to d455bf7 Compare May 31, 2026 10:19
@atzoum
atzoum force-pushed the feat.compactLock branch from fcb2117 to 47914fa Compare May 31, 2026 11:12
@atzoum
atzoum force-pushed the feat.compactLockEnabled branch from d455bf7 to 3946c79 Compare May 31, 2026 11:12
@atzoum
atzoum force-pushed the feat.compactLock branch from 47914fa to e2b976d Compare May 31, 2026 11:12
@atzoum
atzoum force-pushed the feat.compactLockEnabled branch from 3946c79 to 51cb9b9 Compare May 31, 2026 11:12
@atzoum
atzoum force-pushed the feat.compactLock branch from e2b976d to c3e2bf1 Compare May 31, 2026 11:12
@atzoum
atzoum force-pushed the feat.compactLockEnabled branch from 51cb9b9 to 741dd59 Compare May 31, 2026 11:12
@atzoum
atzoum force-pushed the feat.compactLock branch from c3e2bf1 to 0af528e Compare May 31, 2026 12:31
@atzoum
atzoum force-pushed the feat.compactLockEnabled branch from 741dd59 to d8d57ff Compare May 31, 2026 12:31
@atzoum
atzoum force-pushed the feat.compactLock branch from 0af528e to 4cafb77 Compare May 31, 2026 12:35
@atzoum
atzoum force-pushed the feat.compactLockEnabled branch from d8d57ff to cf3b79c Compare May 31, 2026 12:35
@atzoum
atzoum force-pushed the feat.compactLock branch from 4cafb77 to 09eb3af Compare June 2, 2026 13:20
@atzoum
atzoum force-pushed the feat.compactLockEnabled branch from cf3b79c to 71818a3 Compare June 2, 2026 13:20
@atzoum
atzoum force-pushed the feat.compactLock branch from 09eb3af to 8f7eadc Compare June 3, 2026 06:08
@atzoum
atzoum force-pushed the feat.compactLockEnabled branch from 71818a3 to 73b87e2 Compare June 3, 2026 06:08
atzoum added 2 commits June 3, 2026 10:36
🔒 Scanned for secrets using gitleaks 8.30.1

chore: timed lock
@atzoum
atzoum force-pushed the feat.compactLock branch from 8f7eadc to 91e990c Compare June 3, 2026 07:36
@atzoum
atzoum force-pushed the feat.compactLockEnabled branch 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
atzoum force-pushed the feat.compactLock branch from 91e990c to 100ca0b Compare June 3, 2026 07:52
@atzoum atzoum closed this Jun 3, 2026
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 deleted the feat.compactLockEnabled branch June 29, 2026 09:24
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