multi: let all V1Store ForEach* methods take a reset call-back#10068
multi: let all V1Store ForEach* methods take a reset call-back#10068guggero merged 11 commits intolightningnetwork:masterfrom
ForEach* methods take a reset call-back#10068Conversation
There was a problem hiding this comment.
Summary of Changes
Hello @ellemouton, 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 enhances the reliability of database iteration methods by introducing a reset callback. This callback is invoked upon database retry attempts, allowing for the cleanup of transient state accumulated during the iteration. This is a crucial step towards preventing data inconsistencies and improving the overall robustness of operations that interact with the graph database, particularly in the context of potential database retries.
Highlights
- API and Interface Changes: Modified numerous
ForEach*methods across various packages (e.g.,autopilot,graph/db,routing,discovery,rpcserver) to accept an additionalreset func()parameter. This change is propagated through several interfaces, includingautopilot/interface.go,graph/db/interfaces.go,graph/interfaces.go, androuting/graph.go, ensuring consistency across the codebase. - Database Interaction Robustness: The primary intent of this change is to improve the robustness of database interactions. The new
resetcallback allows callers to clear any accumulated state if a database operation needs to be retried. This prevents bugs that could arise from stale or partially collected data during retries, ensuring data integrity. - State Management During Retries: Implemented specific state-clearing logic within the new
resetcallbacks at various call sites. This includes clearing maps, slices, and other variables that accumulate data duringForEach*iterations, ensuring a clean slate for subsequent retry attempts. Examples include clearingnodesandaddressesinautopilot/agent.go,localChansinrouting/bandwidth.go, and various RPC response fields inrpcserver.go. - Underlying Database Store Updates: The
V1Storeimplementations, both KV-based (graph/db/kv_store.go) and SQL-based (graph/db/sql_store.go), have been updated to support and pass through theresetcallback. This ensures that the cleanup mechanism is effective at the lowest layers of database interaction. - Test Coverage Updates: Corresponding test files have been updated to accommodate the new function signatures, providing appropriate
resetcallbacks. This includes addingfunc(){}for simple cases where no state needs explicit clearing, and specific state resets for more complex scenarios in test setups.
Using Gemini Code Assist
The 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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and 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 to provide feedback.
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
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
This pull request correctly adds a reset callback to all V1Store ForEach* methods to handle database retries gracefully. The changes are extensive and have been applied consistently across interfaces, implementations, and call sites. The refactoring in some places to make the callbacks purer is a great improvement for code clarity and robustness.
I've found one minor style issue related to line length that should be addressed. Otherwise, the changes look solid and well-implemented.
guggero
left a comment
There was a problem hiding this comment.
Very nice way of splitting up this quite large change into multiple commits. LGTM 🎉
d6378e5 to
c5031c3
Compare
This commit passes no-op reset callbacks to various places where they are needed in the KVStore. Upcoming commits will replace the no-ops by adding reset params to the methods that require it.
This commit just surfaces the locations in the SQLStore where we will later pass reset params through.
Add a `reset` call-back param to the V1Store ForEachChannel method.
c5031c3 to
83f6dc4
Compare
|
cc @guggero for le override powers |
The
ForEach*methods should expose the underlyingresetparam that is passed to the DB callso that callers can correctly "clean" any state that was collected during the execution of the main
call-back if a DB-retry occurs.
In the longer term, we should aim to replace these ForEach methods with proper/safe iterators that
only apply the call-backs to successful DB fetches. But for now, this is at least an improvement & fixes a few pre-existing bugs.