Skip to content

refactor(cache): drop legacy withTransaction + executeTransaction; finish MigrateNarInfo Ent move - #1216

Merged
kalbasit merged 1 commit into
mainfrom
refactor-cache-drop-legacy-tx-helpers
May 23, 2026
Merged

kalbasit merged 1 commit into
mainfrom
refactor-cache-drop-legacy-tx-helpers

Conversation

@kalbasit

Copy link
Copy Markdown
Owner

Now that every cache call site goes through the Ent-backed
withEntTransaction + withEntTransactionRetry path (§11.5 LRU
conversion was the last holdout), the legacy qtx-style helpers
have no production callers. Delete them:

  • *Cache.withTransaction (sqlc Querier closure + deadlock retry)
  • *Cache.executeTransaction (BeginTx/Rollback/Commit lifecycle)

MigrateNarInfo's remaining db.GetNarInfoByHash post-lock recheck
also flips to Ent: NarInfo.Query Where(HashEQ).Only, with the
nullable URL handled via *string == nil instead of sql.NullString.
The Querier parameter is removed from the function signature, the
sole CLI caller (migrate-narinfo.go) is updated, and the unused
db local from createDatabaseQuerier is now elided with _.

The one internal test that still drove the old withTransaction
(testStoreInDatabaseTransactionSafety) is converted to
dbClient.WithTransaction + Ent OnConflict/Ignore + Query.Where —
same scenario (concurrent UPSERT under a single tx), now via the
production code path.

The Cache.db Querier field is retained for now (a handful of
fixture tests still build rows via the legacy API); §12 deletes
it together with the sqlc dependency.

Full -race sweep against SQLite + Postgres + MySQL + Redis +
MinIO is clean.

Co-Authored-By: Claude Opus 4.7 [email protected]

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. go Pull requests that update go code labels May 21, 2026
This was referenced 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.

kalbasit added a commit that referenced this pull request May 22, 2026
…e-check

After acquiring the migration lock, distinguish ent.IsNotFound (the
expected "not yet migrated" case, fall through to migrate) from other DB
errors (log at warn level instead of silently swallowing). The migration
still attempts on any error so a transient lookup glitch doesn't block
progress; if the DB is genuinely broken the upsert below will surface
the failure.

Addresses gemini-code-assist comment on PR #1216 (PRRT_kwDONV6tZs6D3YoD).

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@kalbasit
kalbasit force-pushed the feat-cache-lru-eviction-to-ent branch from bb768f2 to e37ab95 Compare May 22, 2026 23:02
@kalbasit
kalbasit force-pushed the refactor-cache-drop-legacy-tx-helpers branch from 86d9c0f to 364285f Compare May 22, 2026 23:02
kalbasit added a commit that referenced this pull request May 22, 2026
…e-check

After acquiring the migration lock, distinguish ent.IsNotFound (the
expected "not yet migrated" case, fall through to migrate) from other DB
errors (log at warn level instead of silently swallowing). The migration
still attempts on any error so a transient lookup glitch doesn't block
progress; if the DB is genuinely broken the upsert below will surface
the failure.

Addresses gemini-code-assist comment on PR #1216 (PRRT_kwDONV6tZs6D3YoD).

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@kalbasit
kalbasit force-pushed the feat-cache-lru-eviction-to-ent branch from e37ab95 to 194863b Compare May 22, 2026 23:16
@kalbasit
kalbasit force-pushed the refactor-cache-drop-legacy-tx-helpers branch from 364285f to 34adccd Compare May 22, 2026 23:16
kalbasit added a commit that referenced this pull request May 22, 2026
…e-check

After acquiring the migration lock, distinguish ent.IsNotFound (the
expected "not yet migrated" case, fall through to migrate) from other DB
errors (log at warn level instead of silently swallowing). The migration
still attempts on any error so a transient lookup glitch doesn't block
progress; if the DB is genuinely broken the upsert below will surface
the failure.

Addresses gemini-code-assist comment on PR #1216 (PRRT_kwDONV6tZs6D3YoD).

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@kalbasit
kalbasit force-pushed the feat-cache-lru-eviction-to-ent branch from 194863b to 1d43640 Compare May 22, 2026 23:28
@kalbasit
kalbasit force-pushed the refactor-cache-drop-legacy-tx-helpers branch from 34adccd to 6c5decb Compare May 22, 2026 23:28
kalbasit added a commit that referenced this pull request May 22, 2026
…e-check

After acquiring the migration lock, distinguish ent.IsNotFound (the
expected "not yet migrated" case, fall through to migrate) from other DB
errors (log at warn level instead of silently swallowing). The migration
still attempts on any error so a transient lookup glitch doesn't block
progress; if the DB is genuinely broken the upsert below will surface
the failure.

Addresses gemini-code-assist comment on PR #1216 (PRRT_kwDONV6tZs6D3YoD).

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@kalbasit
kalbasit force-pushed the feat-cache-lru-eviction-to-ent branch from 1d43640 to 64a722f Compare May 22, 2026 23:54
@kalbasit
kalbasit force-pushed the refactor-cache-drop-legacy-tx-helpers branch from 6c5decb to e24c793 Compare May 22, 2026 23:54
kalbasit added a commit that referenced this pull request May 22, 2026
…e-check

After acquiring the migration lock, distinguish ent.IsNotFound (the
expected "not yet migrated" case, fall through to migrate) from other DB
errors (log at warn level instead of silently swallowing). The migration
still attempts on any error so a transient lookup glitch doesn't block
progress; if the DB is genuinely broken the upsert below will surface
the failure.

Addresses gemini-code-assist comment on PR #1216 (PRRT_kwDONV6tZs6D3YoD).

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@kalbasit
kalbasit force-pushed the feat-cache-lru-eviction-to-ent branch from 64a722f to 98d03dc Compare May 23, 2026 00:07
@kalbasit
kalbasit force-pushed the refactor-cache-drop-legacy-tx-helpers branch from e24c793 to e6aaef8 Compare May 23, 2026 00:07
kalbasit added a commit that referenced this pull request May 23, 2026
…e-check

After acquiring the migration lock, distinguish ent.IsNotFound (the
expected "not yet migrated" case, fall through to migrate) from other DB
errors (log at warn level instead of silently swallowing). The migration
still attempts on any error so a transient lookup glitch doesn't block
progress; if the DB is genuinely broken the upsert below will surface
the failure.

Addresses gemini-code-assist comment on PR #1216 (PRRT_kwDONV6tZs6D3YoD).

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@kalbasit
kalbasit force-pushed the feat-cache-lru-eviction-to-ent branch from 98d03dc to 453905e Compare May 23, 2026 00:35
@kalbasit
kalbasit force-pushed the refactor-cache-drop-legacy-tx-helpers branch from e6aaef8 to fdf9e14 Compare May 23, 2026 00:35
kalbasit added a commit that referenced this pull request May 23, 2026
…e-check

After acquiring the migration lock, distinguish ent.IsNotFound (the
expected "not yet migrated" case, fall through to migrate) from other DB
errors (log at warn level instead of silently swallowing). The migration
still attempts on any error so a transient lookup glitch doesn't block
progress; if the DB is genuinely broken the upsert below will surface
the failure.

Addresses gemini-code-assist comment on PR #1216 (PRRT_kwDONV6tZs6D3YoD).

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@kalbasit
kalbasit force-pushed the feat-cache-lru-eviction-to-ent branch from 453905e to 670f6c8 Compare May 23, 2026 03:31
@kalbasit
kalbasit force-pushed the refactor-cache-drop-legacy-tx-helpers branch from fdf9e14 to ab142f2 Compare May 23, 2026 03:31
…nish MigrateNarInfo Ent move

Now that every cache call site goes through the Ent-backed
withEntTransaction + withEntTransactionRetry path (§11.5 LRU
conversion was the last holdout), the legacy qtx-style helpers
have no production callers. Delete them:

  - *Cache.withTransaction (sqlc Querier closure + deadlock retry)
  - *Cache.executeTransaction (BeginTx/Rollback/Commit lifecycle)

MigrateNarInfo's remaining db.GetNarInfoByHash post-lock recheck
also flips to Ent: NarInfo.Query Where(HashEQ).Only, with the
nullable URL handled via *string == nil instead of sql.NullString.
The Querier parameter is removed from the function signature, the
sole CLI caller (migrate-narinfo.go) is updated, and the unused
db local from createDatabaseQuerier is now elided with _.

The one internal test that still drove the old withTransaction
(testStoreInDatabaseTransactionSafety) is converted to
dbClient.WithTransaction + Ent OnConflict/Ignore + Query.Where —
same scenario (concurrent UPSERT under a single tx), now via the
production code path.

The Cache.db Querier field is retained for now (a handful of
fixture tests still build rows via the legacy API); §12 deletes
it together with the sqlc dependency.

Full -race sweep against SQLite + Postgres + MySQL + Redis +
MinIO is clean.

Co-Authored-By: Claude Opus 4.7 <[email protected]>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pkg/cache/cache.go (1)

4804-4813: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Update the exported docs to match the new MigrateNarInfo signature.

The doc block still lists the removed db parameter, so the public contract now disagrees with the actual API.

✏️ Suggested doc fix
 // Parameters:
 //   - ctx: Context for the operation
 //   - locker: Distributed locker for coordination (can be in-memory for single-instance)
-//   - db: Database querier (legacy; kept for the pre-lock double-check
-//     until §11 fully retires the Querier surface)
-//   - dbClient: Ent-backed client used by storeNarInfoInDatabase for
-//     the actual UPSERT pipeline
+//   - dbClient: Ent-backed client used for the post-lock migration check
+//     and the actual UPSERT pipeline
 //   - narInfoStore: Optional storage backend to delete from after migration (nil to skip deletion)
 //   - hash: The narinfo hash to migrate
 //   - ni: The parsed narinfo to migrate
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/cache/cache.go` around lines 4804 - 4813, The doc comment for the
exported function MigrateNarInfo is stale: it still lists a removed db parameter
and mentions the legacy Querier surface. Update the comment to match the current
MigrateNarInfo signature by removing the `db` parameter from the parameters
list, ensure the remaining params (ctx, locker, dbClient, narInfoStore, hash,
ni) are listed and described correctly, and adjust any wording that refers to
the legacy Querier surface so the public docs accurately reflect the new API.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@pkg/cache/cache.go`:
- Around line 4804-4813: The doc comment for the exported function
MigrateNarInfo is stale: it still lists a removed db parameter and mentions the
legacy Querier surface. Update the comment to match the current MigrateNarInfo
signature by removing the `db` parameter from the parameters list, ensure the
remaining params (ctx, locker, dbClient, narInfoStore, hash, ni) are listed and
described correctly, and adjust any wording that refers to the legacy Querier
surface so the public docs accurately reflect the new API.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6408cf9d-8bb9-40fe-9a40-9a27c3bd6e64

📥 Commits

Reviewing files that changed from the base of the PR and between 71f1563 and 8cdb4a8.

📒 Files selected for processing (3)
  • pkg/cache/cache.go
  • pkg/cache/cache_internal_test.go
  • pkg/ncps/migrate_narinfo.go

@codecov

codecov Bot commented May 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 5.68%. Comparing base (71f1563) to head (8cdb4a8).

Additional details and impacted files
@@          Coverage Diff          @@
##            main   #1216   +/-   ##
=====================================
  Coverage   5.68%   5.68%           
=====================================
  Files          6       6           
  Lines        387     387           
=====================================
  Hits          22      22           
  Misses       361     361           
  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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go Pull requests that update go code merge-stack size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant