[sql-57] Add accounts kvdb->SQL migration itest#1207
[sql-57] Add accounts kvdb->SQL migration itest#1207ViktorT-11 wants to merge 2 commits intolightninglabs:sql-migration-basefrom
Conversation
Summary of ChangesHello @ViktorT-11, 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 significantly advances the project's database infrastructure by introducing a robust integration test for the KVDB to SQL migration of the accounts store. It involves a comprehensive refactoring of the database interaction layer, adopting a new Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. 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 introduces the foundational components for testing KVDB to SQL migrations within the integration test framework, focusing on the accounts store. The changes are extensive, involving a significant refactoring of the database layer to align with lnd/sqldb/v2, introducing a dev build tag for migration-specific code, and adding a new integration test to validate the migration flow. The overall approach is solid and the new test provides valuable coverage. I have one minor suggestion for improving consistency.
5247a8d to
891a015
Compare
|
@ViktorT-11, remember to re-request review from reviewers when ready |
891a015 to
3e0dda2
Compare
bitromortac
left a comment
There was a problem hiding this comment.
Nice to see the work here on the itests 🔥. I have a few questions regarding what endpoints we should use. I think we should only use what's available via RPCs, which should be enough to cover most cases
itest/litd_migration_test.go
Outdated
| ctxt, migNode.Cfg.LitAddr(), migNode.Cfg.LitTLSCertPath, | ||
| ) | ||
| require.NoError(t.t, err) | ||
| defer rawConn.Close() |
There was a problem hiding this comment.
I think we don't need that as it's closed later explicitly
itest/litd_migration_test.go
Outdated
| node.Cfg.LitDir, node.Cfg.NetParams.Name, "litd.db", | ||
| ) | ||
|
|
||
| sqlStore, err := sqldb.NewSqliteStore( |
There was a problem hiding this comment.
Is testing with Sqlite enough?
There was a problem hiding this comment.
I added coverage for postgres also here.
| // Mimics accounts/sql_migration_test.go "account with payments". | ||
| // NOTE: As there's no way to insert payments into the accounts store | ||
| // directly by just using `litcli`, we insert the payments outside | ||
| // of this function, by directly connecting to the bbolt db. | ||
| createAccount(50000, 0, "migration-payments") | ||
| paymentExpectation := expectations["migration-payments"] | ||
| paymentExpectation.payments = 4 | ||
| expectations["migration-payments"] = paymentExpectation |
There was a problem hiding this comment.
Can't we take use the RouterClient and add the account to the context to make some payments? payNode seems to be ready for that
There was a problem hiding this comment.
Do I think this is a bigger questions for not just this PR, but the rest of the migration itest PRs as well.
We can either try to create all the data we can through the different clients, but with the drawback of not being able to mimic the unit tests as they cover more data variations than what's possible to generate through the clients. One example here is to manage to generate an account payment with the status unkonwn, which some users have in their DB due to having generated it with old releases, but which is hard to generate through the clients today.
Therefore I think we have to make the choice here if we want to try to cover as much data variation as possible in the itests, which requires a direct connection to the db, or if we're ok with just generating the data we can through the clients.
I can see the motivation for both alternatives:
- If we generate through the clients, the data becomes much more realistic and may show errors with
nilhandling in the migrations for example. But we won't be able to mimic all unit tests. - If we do it through a direct connection to the db, we'll be able to cover more data variation.
Which variant do you think most sense? Would be interesting to hear @ellemouton opinion here as well after she has reviewed the PR.
itest/litd_migration_test.go
Outdated
|
|
||
| // Step 4: Assert data via litcli where possible. | ||
| assertMigrationDataViaLitCLI() | ||
| assertMigrationDataViaLitCLI(ctxt, t, migNode, accountsData) |
There was a problem hiding this comment.
Can't we just use the RPC to query the contents? I'm not sure it adds a lot using litcli, as it's only a wrapper
There was a problem hiding this comment.
I changed this to use the RPCs directly instead. The reason I used litcli previously is that I intended to mimic the what most users experience when they query LiT, but I agree that it probably don't make most sense.
itest/litd_migration_test.go
Outdated
| assertMigrationDataSQL() | ||
| assertMigrationDataSQL(ctxt, t, migNode, accountsData) | ||
|
|
||
| // Step 7: Assert data via litcli where possible. | ||
| assertMigrationDataViaLitCLI() | ||
| assertMigrationDataViaLitCLI(ctxt, t, migNode, accountsData) |
There was a problem hiding this comment.
It seems like here it would also be enough to query the RPC?
This commit adds the foundational components for testing the kvdb -> SQL migration within the itest framework. The benefit of adding migration coverage through itests compared to just unit tests, is that this will test the full migration flow in litd, as it would be executed in production for a user who switches from a bbolt database backend to an SQL database backend. Additionally, as itests have access to the full litcli, we can also assert parts of the migration through litcli commands, as the end user would experience it.
Implement itest coverage for migrating account data from kvdb to sql. The itest coverage mimics the unit tests in accounts/sql_migration_test.go, except for the randomized migration tests. This coverage ensures that the full kvdb->SQL migration flow for litd works as expected for the accounts store.
3e0dda2 to
73d9fd8
Compare
|
Thanks for the review @bitromortac! I've addressed most of your feedback and responded to some comments above :) |
Based on #1114
Implements part of step 6. of "Phase 3" in #917.
This PR adds the foundational components for testing the kvdb -> SQL migration within the itest framework, and implements itest coverage for the migration of the accounts store.
I'll add follow up PRs which will also add implement itest coverage for the sessions store, and the full firewalldb store.
The benefit of adding migration coverage through itests compared to just unit tests, is that this will test the full migration flow in litd, as it would be executed in production for a user who switches from a bbolt database backend to an SQL database backend.
Additionally, as itests have access to the full litcli, we can also assert parts of the migration through litcli commands, as the end user would experience it.