Split DB loading into two stages. #8852
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a follow up to #8783, which was supposed to defer loading the DB for commands where it wasn't necessary. The main motivation was for situations where the Dolt CLI doesn't need to load a local DB because it connects to an already-running server instead.
In practice, the prior PR didn't actually accomplish much because in order to determine whether Dolt should connect to an already running server, it checks to see if there's a lock on the local DB, and in order to do that it tries to load it.
In order for CLI commands against an already-running server to avoid loading the DB, we need to either:
This PR tries to tackle the former, although in hindsight the latter might be a cleaner, simpler fix.
Basically, this PR allows us to detect locks without loading the DB by splitting the DB load into two phases:
Phase 1: Acquire any necessary exclusive resources (like locks)
Phase 2: Finish loading the DB
We accomplish this by modifying the
DBFactory
interface. Previously, it had aCreateDB
method that fully loads the DB. Now, it has aGetDBLoader
method that performs the first phase and returns an instance of theDBLoader
interface.DBLoader
has a methodLoadDB
that performs the second phase and returns the fully loaded database.This allows us to add other methods to
DBLoader
to inspect qualities of the DB that were ascertained during the first phase, such as whether or not we were able to acquire an exclusive lock.Notes: