Repository navigation
fix: repair narinfo migration logic for invalid URLs - #642
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
Summary of ChangesHello @kalbasit, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a critical issue where Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly identifies and fixes a bug in the narinfo migration logic where placeholder records with NULL URLs were not being processed. The changes to re-enable the background migration trigger and handle upserts by replacing existing records are well-implemented. The addition of the regression test TestGetNarInfo_MigratesInvalidURL is excellent and ensures this behavior is covered going forward. However, I found a critical syntax error in the new error handling logic that will prevent the code from compiling, which needs to be addressed.
7152eff to
eb9361d
Compare
This commit addresses an issue where NarInfo records with missing URLs (indicating incomplete migration) were not being correctly identified and migrated to the database. Changes implemented: 1. **Migration Trigger**: Restored the check for '!nir.URL.Valid' in 'getNarInfoFromStore' (pkg/cache/cache.go). When a NarInfo is found with a NULL URL, the system now correctly triggers 'backgroundMigrateNarInfo' to fetch and update the record. 2. **Idempotent Inserts**: Updated 'CreateNarInfo' SQL queries to use 'ON CONFLICT DO UPDATE' (Upsert). This ensures that the migration process can update existing incomplete records in the database with data fetched from storage, instead of failing with duplicate key errors. 3. **Tests**: Added a regression test 'TestGetNarInfo_MigratesInvalidURL' in 'pkg/cache/cache_test.go' and updated 'TestStoreInDatabaseDuplicateDetection' in 'pkg/cache/cache_internal_test.go' to verify the new upsert behavior.
eb9361d to
c9df0ed
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request provides a robust fix for the narinfo migration logic. The use of conditional UPSERTs across all supported database backends is a solid approach to handle the migration of placeholder records idempotently. The Go code changes are well-integrated with the new SQL logic, and the error handling for different database behaviors is thoughtful. The accompanying tests are comprehensive, covering data integrity, concurrency, and behavior consistency across databases, which significantly increases confidence in the fix. The suggestion to improve the robustness of the error handling in the delete logic has been retained as it aligns with general best practices and is not covered by existing rules.
#645) This commit improves the robustness and consistency of database lookups in the cache layer by correctly utilizing the `database.IsNotFoundError` helper. Specifically: - In `deleteNarInfoFromStore`, the logic to check if a NarInfo exists in the database has been refactored to be more concise and explicit about error handling. - In `setupSecretKey`, the error check when fetching the secret key from the database now correctly ignores "not found" errors, ensuring that the fallback logic (to the config store or key generation) is correctly triggered. Fix comment from #642.

This commit restores and fixes the logic where a NarInfo with an invalid (NULL) URL in the database is treated as a signal that the record has not yet been fully migrated from storage. The
migrate-narinfocommand and other parts of the system rely on thisurl IS NULLcondition to identify pending migrations.Specifically, this change:
GetNarInfowhen it encounters a database record with an invalid URL.storeInDatabaseto properly handle upserts when such a placeholder record exists. Instead of failing with a duplicate key error, it deletes the existing partial record and recreates it with the full details, ensuring the migration can complete successfully.TestGetNarInfo_MigratesInvalidURLto verify this behavior.