Skip to content

Fix: Improve transactional safety of payload offload reads and writes#3814

Merged
mrkaye97 merged 4 commits intomainfrom
mk/payloads-long-tx
May 5, 2026
Merged

Fix: Improve transactional safety of payload offload reads and writes#3814
mrkaye97 merged 4 commits intomainfrom
mk/payloads-long-tx

Conversation

@mrkaye97
Copy link
Copy Markdown
Contributor

@mrkaye97 mrkaye97 commented May 4, 2026

Description

Makes the payload offload job a little bit more transactionally safe by listing doing the original payload listing + the writes in separate txs

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Copilot AI review requested due to automatic review settings May 4, 2026 16:30
@vercel
Copy link
Copy Markdown

vercel Bot commented May 4, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hatchet-docs Ready Ready Preview, Comment May 4, 2026 5:06pm

Request Review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to improve transactional safety during payload cutover/offload batches by opening a single transaction earlier and reusing it through window-size optimization, range chunk creation, payload reads, and the final temp-table insert + lease update.

Changes:

  • Start a DB transaction at the beginning of each cutover batch iteration (payloadstore + OLAP).
  • Thread the transaction through the window-size optimization and payload range chunk creation queries.
  • Switch paginated payload reads to use the same transaction connection instead of the pool.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
pkg/repository/payloadstore.go Opens a long-running tx for ProcessPayloadCutoverBatch and passes it into sizing/chunking/listing queries.
pkg/repository/olap.go Same pattern as payloadstore for OLAP payload cutover batches.

Comment thread pkg/repository/payloadstore.go Outdated
Comment thread pkg/repository/payloadstore.go Outdated
Comment thread pkg/repository/olap.go
Comment thread pkg/repository/olap.go Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (2)

pkg/repository/payloadstore.go:662

  • This function now uses two separate transactions but reuses the same tx/commit/rollback variables and stacks multiple defer rollback() calls. It works, but it’s easy to misread/modify incorrectly later. Consider scoping each transaction in its own block and/or using distinct variable names so it’s obvious which rollback/commit corresponds to which transaction.
	tx, commit, rollback, err = sqlchelpers.PrepareTx(ctx, p.pool, p.l)

	if err != nil {
		return nil, fmt.Errorf("failed to prepare transaction for copying offloaded payloads: %w", err)
	}

	defer rollback()

pkg/repository/olap.go:3130

  • Similar to payloadstore, this function now uses multiple transactions but reuses tx/commit/rollback and defers multiple rollbacks in the same scope. To reduce the chance of future mistakes, consider scoping each transaction in its own block or using distinct variable names for each transaction.
	tx, commit, rollback, err = sqlchelpers.PrepareTx(ctx, p.pool, p.l)

	if err != nil {
		return nil, fmt.Errorf("failed to prepare transaction for copying offloaded payloads: %w", err)
	}

	defer rollback()

Comment thread pkg/repository/payloadstore.go
Comment thread pkg/repository/olap.go
@mrkaye97 mrkaye97 requested a review from abelanger5 May 5, 2026 17:15
@mrkaye97 mrkaye97 changed the title Fix: Use long tx for payload offloads to improve transactional safety Fix: Improve transactional safety of payload offload reads and writes May 5, 2026
@mrkaye97 mrkaye97 merged commit 3948c8e into main May 5, 2026
52 checks passed
@mrkaye97 mrkaye97 deleted the mk/payloads-long-tx branch May 5, 2026 18: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.

3 participants