-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
kvdb: migrate between different backends #5524
Conversation
As a preparation to initialize more than just the channel database on startup we introduce a new struct that holds a reference to each of our database instances.
As a preparation to not have a local and remote version of the database around anymore, we rename the variables into what their actual function is. In case of the RPC server we even directly use the channel graph instead of the DB instance. This should allow us to extract the channel graph into its own, separate database (perhaps with better access characteristics) in the future.
In order to separate our databases more clearly, we refactor the height hint cache DB to use a kvdb backend instead of the channel DB instance directly.
This commit gets rid of the concept of a local and remote database when etcd is used. Instead the same backend is now used for both the (previously renamed from local and remote DB) graph and channel state databases. This will make path finding extremely slow on etcd and will require further optimizations and possibly a write-through cache for the graph DB. But this is a requirement for making lnd itself fully stateless.
The macaroon root keys should also be stored to the remote database if a replicated backend such as etcd is used. This commit refactors the macaroons service and wallet unlocker to accept a kvdb backend directly instead of creating the bolt instance automatically.
The wallet and macaroon databases are the first files that are created for a new node. When initializing those databases, the parent directory is created if it does not exist. With both of the databases now potentially being remote, that code that creates the parent directory might never be executed and we need to do that manually when parsing the configuration. Otherwise we run into an error when we later try to create our default macaroons in that folder and it doesn't exist.
Even though the sphinx router's persistent replay log is not crucial in the operation of lnd as its state can be re-created by creating a new brontide connection, we want to make lnd fully stateless and therefore have the option of not storing any state on disk.
The final database that needs to be made remote compatible is the watchtower server and client database. They are handled a bit differently because both of them are not always active, only when specifically turned on in the config.
To have all the database backend related code in one place, we finally also move the initialization of the wallet DB loader option into the GetBackends() method.
Since we're now storing the content of multiple previously distinct database files in etcd, we want to properly namespace them as not to provoke any key collisions. We append a sub namespace to the given global namespace in order to still support multiple lnd nodes using the same etcd database simultaneously.
Accessing buckets that have been removed is not an allowed operation.
From bbolt docs: // Seek positions the cursor at the passed seek key. If the key does not exist, // the cursor is moved to the next key after seek. Returns the new pair.
I pushed a rebased version of this to https://github.com/guggero/lnd/tree/database-migration-lndinit in case you want to use that. Or I can take over this PR and continue maintaining it? A question that popped up when writing the release notes for #5484: It sounds quite bad if we have to add a |
No, I don't mind you taking over the code that I have so far. Regarding the etcd 0.13 to 0.14 migration: I don't think it is just adding the prefix, but also migrating walletdb, heighthint, towers etc to etcd. I would indeed keep the option in mind in case anyone complains during the rc cycle. To me that seems unlikely to happen. |
Replaced by #5561. |
No description provided.