Skip to content

feat(cache): add withEntTransaction infrastructure helper - #1194

Merged
kalbasit merged 1 commit into
mainfrom
feat-cache-with-ent-transaction
May 22, 2026
Merged

kalbasit merged 1 commit into
mainfrom
feat-cache-with-ent-transaction

Conversation

@kalbasit

Copy link
Copy Markdown
Owner

Adds the Ent-backed counterpart to *Cache.withTransaction so
upcoming §11.2-§11.5 caller-migration commits can convert
qtx-style closures one at a time without rewriting the
deadlock-retry policy each time.

The helper:

  • delegates the lifecycle (begin → fn(tx) → commit / rollback
    / panic-rollback) to *database.Client.WithTransaction added
    in §10
  • preserves the existing retry-on-deadlock loop verbatim (5
    attempts, 50ms initial back-off doubling per try, ctx-aware
    pacing, deadlock detection via database.IsDeadlockError) so
    conversions are behavior-preserving
  • is annotated //nolint:unused because no call site is
    converted yet; the annotation will come off as soon as the
    first qtx-style block migrates over

Once every withTransaction call site moves off the Querier
closure shape, the legacy withTransaction (and the underlying
executeTransaction) become dead code and are removed in §12.

No behavior change. Lint clean, full pkg/cache -race test
suite passes against SQLite + Postgres + MySQL + MinIO + Redis.

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. enhancement New feature or request go Pull requests that update go code labels May 21, 2026
@kalbasit

kalbasit commented May 21, 2026 •

Copy link
Copy Markdown
Owner Author

This change is part of the following stack:

Change managed by git-spice.

This was referenced May 21, 2026
@kalbasit
kalbasit force-pushed the feat-cache-getnarinfo-to-ent branch from 7537892 to 2c22541 Compare May 22, 2026 17:18
@kalbasit
kalbasit force-pushed the feat-cache-with-ent-transaction branch from e22ab56 to 8078fbf Compare May 22, 2026 17:18
@kalbasit
kalbasit force-pushed the feat-cache-getnarinfo-to-ent branch from 2c22541 to 38fa3fa Compare May 22, 2026 17:39
@kalbasit
kalbasit force-pushed the feat-cache-with-ent-transaction branch from 8078fbf to e2c4993 Compare May 22, 2026 17:39
Base automatically changed from feat-cache-getnarinfo-to-ent to main May 22, 2026 17:52
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels May 22, 2026
Adds the Ent-backed counterpart to *Cache.withTransaction so
upcoming §11.2-§11.5 caller-migration commits can convert
qtx-style closures one at a time without rewriting the
deadlock-retry policy each time.

The helper:

- delegates the lifecycle (begin → fn(tx) → commit / rollback
  / panic-rollback) to *database.Client.WithTransaction added
  in §10
- preserves the existing retry-on-deadlock loop verbatim (5
  attempts, 50ms initial back-off doubling per try, ctx-aware
  pacing, deadlock detection via database.IsDeadlockError) so
  conversions are behavior-preserving
- is annotated //nolint:unused because no call site is
  converted yet; the annotation will come off as soon as the
  first qtx-style block migrates over

Once every withTransaction call site moves off the Querier
closure shape, the legacy withTransaction (and the underlying
executeTransaction) become dead code and are removed in §12.

No behavior change. Lint clean, full pkg/cache -race test
suite passes against SQLite + Postgres + MySQL + MinIO + Redis.
@kalbasit
kalbasit force-pushed the feat-cache-with-ent-transaction branch from e2c4993 to f92d4a6 Compare May 22, 2026 17:53
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels May 22, 2026
@codecov

codecov Bot commented May 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 4.94%. Comparing base (df2363d) to head (f92d4a6).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@          Coverage Diff          @@
##            main   #1194   +/-   ##
=====================================
  Coverage   4.94%   4.94%           
=====================================
  Files          6       6           
  Lines        445     445           
=====================================
  Hits          22      22           
  Misses       419     419           
  Partials       4       4           

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

@kalbasit
kalbasit merged commit cbd6db0 into main May 22, 2026
18 checks passed
@kalbasit
kalbasit deleted the feat-cache-with-ent-transaction branch May 22, 2026 18:06
kalbasit added a commit that referenced this pull request May 22, 2026
PR #1194 review surfaced two issues in withEntTransaction:

1. (PRRT_kwDONV6tZs6DsQzn) Restore "starting transaction" /
   "committed successfully" debug logs that the legacy
   executeTransaction emitted. Behind Debug level so noise
   stays opt-in; restores observability parity.

2. (PRRT_kwDONV6tZs6DsQzo) Replace `case <-time.After(delay):`
   inside the retry select with `time.NewTimer(delay)` +
   `t.Stop()` in the ctx-cancellation branch to avoid leaking
   the underlying timer when ctx wins the race.

Behaviour-preserving on the happy path.
kalbasit added a commit that referenced this pull request May 22, 2026
PR #1194 review surfaced two issues in withEntTransaction:

1. (PRRT_kwDONV6tZs6DsQzn) Restore "starting transaction" /
   "committed successfully" debug logs that the legacy
   executeTransaction emitted. Behind Debug level so noise
   stays opt-in; restores observability parity.

2. (PRRT_kwDONV6tZs6DsQzo) Replace `case <-time.After(delay):`
   inside the retry select with `time.NewTimer(delay)` +
   `t.Stop()` in the ctx-cancellation branch to avoid leaking
   the underlying timer when ctx wins the race.

Behaviour-preserving on the happy path.
kalbasit added a commit that referenced this pull request May 22, 2026
PR #1194 review surfaced two issues in withEntTransaction:

1. (PRRT_kwDONV6tZs6DsQzn) Restore "starting transaction" /
   "committed successfully" debug logs that the legacy
   executeTransaction emitted. Behind Debug level so noise
   stays opt-in; restores observability parity.

2. (PRRT_kwDONV6tZs6DsQzo) Replace `case <-time.After(delay):`
   inside the retry select with `time.NewTimer(delay)` +
   `t.Stop()` in the ctx-cancellation branch to avoid leaking
   the underlying timer when ctx wins the race.

Behaviour-preserving on the happy path.
kalbasit added a commit that referenced this pull request May 22, 2026
PR #1194 review surfaced two issues in withEntTransaction:

1. (PRRT_kwDONV6tZs6DsQzn) Restore "starting transaction" /
   "committed successfully" debug logs that the legacy
   executeTransaction emitted. Behind Debug level so noise
   stays opt-in; restores observability parity.

2. (PRRT_kwDONV6tZs6DsQzo) Replace `case <-time.After(delay):`
   inside the retry select with `time.NewTimer(delay)` +
   `t.Stop()` in the ctx-cancellation branch to avoid leaking
   the underlying timer when ctx wins the race.

Behaviour-preserving on the happy path.
kalbasit added a commit that referenced this pull request May 22, 2026
PR #1194 review surfaced two issues in withEntTransaction:

1. (PRRT_kwDONV6tZs6DsQzn) Restore "starting transaction" /
   "committed successfully" debug logs that the legacy
   executeTransaction emitted. Behind Debug level so noise
   stays opt-in; restores observability parity.

2. (PRRT_kwDONV6tZs6DsQzo) Replace `case <-time.After(delay):`
   inside the retry select with `time.NewTimer(delay)` +
   `t.Stop()` in the ctx-cancellation branch to avoid leaking
   the underlying timer when ctx wins the race.

Behaviour-preserving on the happy path.
kalbasit added a commit that referenced this pull request May 22, 2026
PR #1194 review surfaced two issues in withEntTransaction:

1. (PRRT_kwDONV6tZs6DsQzn) Restore "starting transaction" /
   "committed successfully" debug logs that the legacy
   executeTransaction emitted. Behind Debug level so noise
   stays opt-in; restores observability parity.

2. (PRRT_kwDONV6tZs6DsQzo) Replace `case <-time.After(delay):`
   inside the retry select with `time.NewTimer(delay)` +
   `t.Stop()` in the ctx-cancellation branch to avoid leaking
   the underlying timer when ctx wins the race.

Behaviour-preserving on the happy path.
kalbasit added a commit that referenced this pull request May 22, 2026
PR #1194 review surfaced two issues in withEntTransaction:

1. (PRRT_kwDONV6tZs6DsQzn) Restore "starting transaction" /
   "committed successfully" debug logs that the legacy
   executeTransaction emitted. Behind Debug level so noise
   stays opt-in; restores observability parity.

2. (PRRT_kwDONV6tZs6DsQzo) Replace `case <-time.After(delay):`
   inside the retry select with `time.NewTimer(delay)` +
   `t.Stop()` in the ctx-cancellation branch to avoid leaking
   the underlying timer when ctx wins the race.

Behaviour-preserving on the happy path.
kalbasit added a commit that referenced this pull request May 22, 2026
PR #1194 review surfaced two issues in withEntTransaction:

1. (PRRT_kwDONV6tZs6DsQzn) Restore "starting transaction" /
   "committed successfully" debug logs that the legacy
   executeTransaction emitted. Behind Debug level so noise
   stays opt-in; restores observability parity.

2. (PRRT_kwDONV6tZs6DsQzo) Replace `case <-time.After(delay):`
   inside the retry select with `time.NewTimer(delay)` +
   `t.Stop()` in the ctx-cancellation branch to avoid leaking
   the underlying timer when ctx wins the race.

Behaviour-preserving on the happy path.
kalbasit added a commit that referenced this pull request May 22, 2026
PR #1194 review surfaced two issues in withEntTransaction:

1. (PRRT_kwDONV6tZs6DsQzn) Restore "starting transaction" /
   "committed successfully" debug logs that the legacy
   executeTransaction emitted. Behind Debug level so noise
   stays opt-in; restores observability parity.

2. (PRRT_kwDONV6tZs6DsQzo) Replace `case <-time.After(delay):`
   inside the retry select with `time.NewTimer(delay)` +
   `t.Stop()` in the ctx-cancellation branch to avoid leaking
   the underlying timer when ctx wins the race.

Behaviour-preserving on the happy path.
kalbasit added a commit that referenced this pull request May 22, 2026
PR #1194 review surfaced two issues in withEntTransaction:

1. (PRRT_kwDONV6tZs6DsQzn) Restore "starting transaction" /
   "committed successfully" debug logs that the legacy
   executeTransaction emitted. Behind Debug level so noise
   stays opt-in; restores observability parity.

2. (PRRT_kwDONV6tZs6DsQzo) Replace `case <-time.After(delay):`
   inside the retry select with `time.NewTimer(delay)` +
   `t.Stop()` in the ctx-cancellation branch to avoid leaking
   the underlying timer when ctx wins the race.

Behaviour-preserving on the happy path.
kalbasit added a commit that referenced this pull request May 22, 2026
PR #1194 review surfaced two issues in withEntTransaction:

1. (PRRT_kwDONV6tZs6DsQzn) Restore "starting transaction" /
   "committed successfully" debug logs that the legacy
   executeTransaction emitted. Behind Debug level so noise
   stays opt-in; restores observability parity.

2. (PRRT_kwDONV6tZs6DsQzo) Replace `case <-time.After(delay):`
   inside the retry select with `time.NewTimer(delay)` +
   `t.Stop()` in the ctx-cancellation branch to avoid leaking
   the underlying timer when ctx wins the race.

Behaviour-preserving on the happy path.
kalbasit added a commit that referenced this pull request May 22, 2026
PR #1194 review surfaced two issues in withEntTransaction:

1. (PRRT_kwDONV6tZs6DsQzn) Restore "starting transaction" /
   "committed successfully" debug logs that the legacy
   executeTransaction emitted. Behind Debug level so noise
   stays opt-in; restores observability parity.

2. (PRRT_kwDONV6tZs6DsQzo) Replace `case <-time.After(delay):`
   inside the retry select with `time.NewTimer(delay)` +
   `t.Stop()` in the ctx-cancellation branch to avoid leaking
   the underlying timer when ctx wins the race.

Behaviour-preserving on the happy path.
kalbasit added a commit that referenced this pull request May 22, 2026
PR #1194 review surfaced two issues in withEntTransaction:

1. (PRRT_kwDONV6tZs6DsQzn) Restore "starting transaction" /
   "committed successfully" debug logs that the legacy
   executeTransaction emitted. Behind Debug level so noise
   stays opt-in; restores observability parity.

2. (PRRT_kwDONV6tZs6DsQzo) Replace `case <-time.After(delay):`
   inside the retry select with `time.NewTimer(delay)` +
   `t.Stop()` in the ctx-cancellation branch to avoid leaking
   the underlying timer when ctx wins the race.

Behaviour-preserving on the happy path.
kalbasit added a commit that referenced this pull request May 23, 2026
PR #1194 review surfaced two issues in withEntTransaction:

1. (PRRT_kwDONV6tZs6DsQzn) Restore "starting transaction" /
   "committed successfully" debug logs that the legacy
   executeTransaction emitted. Behind Debug level so noise
   stays opt-in; restores observability parity.

2. (PRRT_kwDONV6tZs6DsQzo) Replace `case <-time.After(delay):`
   inside the retry select with `time.NewTimer(delay)` +
   `t.Stop()` in the ctx-cancellation branch to avoid leaking
   the underlying timer when ctx wins the race.

Behaviour-preserving on the happy path.
kalbasit added a commit that referenced this pull request May 23, 2026
PR #1194 review surfaced two issues in withEntTransaction:

1. (PRRT_kwDONV6tZs6DsQzn) Restore "starting transaction" /
   "committed successfully" debug logs that the legacy
   executeTransaction emitted. Behind Debug level so noise
   stays opt-in; restores observability parity.

2. (PRRT_kwDONV6tZs6DsQzo) Replace `case <-time.After(delay):`
   inside the retry select with `time.NewTimer(delay)` +
   `t.Stop()` in the ctx-cancellation branch to avoid leaking
   the underlying timer when ctx wins the race.

Behaviour-preserving on the happy path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request go Pull requests that update go code size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant