Skip to content

go/store/nbs: Lazily load chunk journal database resources when constructing a NomsBlockStore.#11117

Merged
reltuk merged 12 commits into
mainfrom
aaron/read-only-doesnt-load-db
May 28, 2026
Merged

go/store/nbs: Lazily load chunk journal database resources when constructing a NomsBlockStore.#11117
reltuk merged 12 commits into
mainfrom
aaron/read-only-doesnt-load-db

Conversation

@reltuk
Copy link
Copy Markdown
Contributor

@reltuk reltuk commented May 28, 2026

Most Dolt commands currently construct a MultiRepoEnv and then call
into the SQL layer to perform the actual work. In turn, the SQL layer
has some logic which looks at the state of the loaded databases and
sees whether the process has ended up loading some of them in ReadOnly
mode. If it has, then in some cases the Dolt process will attempt to
connect to a running dolt sql-server instead of doing the work
against the database files itself.

This PR makes is to that the application code paths which inspect
AccessMode == ReadOnly can get that signal and make the attempt to
reach out to the server before all of the database state has to be
loaded from disk. This greatly improves the performance of running
dolt CLI commands against a running dolt sql-server, from the same
directory as the server data-dir.

reltuk added 2 commits May 28, 2026 12:16
…ructing a NomsBlockStore.

Most Dolt commands currently construct a MultiRepoEnv and then call
into the SQL layer to perform the actual work. In turn, the SQL layer
has some logic which looks at the state of the loaded databases and
sees whether the process has ended up loading some of them in ReadOnly
mode. If it has, then in some cases the Dolt process will attempt to
connect to a running `dolt sql-server` instead of doing the work
against the database files itself.

This PR makes is to that the application code paths which inspect
AccessMode == ReadOnly can get that signal and make the attempt to
reach out to the server *before* all of the database state has to be
loaded from disk. This greatly improves the performance of running
`dolt` CLI commands against a running `dolt sql-server`, from the same
directory as the server data-dir.
@coffeegoddd
Copy link
Copy Markdown
Contributor

coffeegoddd commented May 28, 2026

@reltuk DOLT

read_tests from_latency to_latency percent_change
covering_index_scan 2.3 2.3 0.0
groupby_scan 132.49 132.49 0.0
index_join 1.93 1.93 0.0
index_join_scan 1.34 1.34 0.0
index_scan 215.44 215.44 0.0
oltp_point_select 0.26 0.26 0.0
oltp_read_only 5.18 5.18 0.0
select_random_points 0.55 0.55 0.0
select_random_ranges 0.64 0.64 0.0
table_scan 207.82 204.11 -1.79
types_table_scan 475.79 484.44 1.82
write_tests from_latency to_latency percent_change
oltp_delete_insert 6.21 6.21 0.0
oltp_insert 3.19 3.13 -1.88
oltp_read_write 11.45 11.45 0.0
oltp_update_index 3.3 3.3 0.0
oltp_update_non_index 3.02 3.02 0.0
oltp_write_only 6.32 6.32 0.0
types_delete_insert 6.91 6.91 0.0

Copy link
Copy Markdown
Contributor

@macneale4 macneale4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One println to remove before shipping. Other comments are up to you

// The |warningsCb| callback is called with any errors encountered that we automatically recover from. This allows the caller
// to handle the situation in a context specific way.
func processJournalRecords(ctx context.Context, r io.ReadSeeker, tryTruncate bool, off int64, cb func(o int64, r journalRec) error, warningsCb func(error)) (int64, error) {
func processJournalRecords(ctx context.Context, path string, r io.ReadSeeker, tryTruncate bool, off int64, cb func(o int64, r journalRec) error, warningsCb func(error)) (int64, error) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit. may be worth a gDoc comment that the path is used only for error reporting.

Comment thread go/store/nbs/store.go Outdated
}

func (nbs *NomsBlockStore) ChunkJournalSize() (int64, bool) {
if err := nbs.ensureLoad(context.Background()); err != nil {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using a Background() ctx here, but a TODO() above. What's the thinking there?

Alternatively - plumb through an actual context?

Comment thread go/store/nbs/store.go Outdated
Comment on lines +824 to +825
// XXX: Just printing here for now so that we can audit when the databases are actually loaded.
fmt.Fprintf(color.Error, "actually loading database at %s\n%s\n", dir, string(debug.Stack()))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove!

LoadDoltDB(ctx, dEnv)
dbErr := dEnv.DBLoadError
if dbErr != nil {
// XXX: We are not guaranteed to see these errors here, because the database might
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why we have a pronographic comment here, but we can probably delete it

@coffeegoddd
Copy link
Copy Markdown
Contributor

coffeegoddd commented May 28, 2026

@reltuk DOLT

test_name from_latency_p95 to_latency_p95 percent_change
tpcc-scale-factor-1 45.79 45.79 0.0
test_name from_server_name from_server_version from_tps to_server_name to_server_version to_tps percent_change
tpcc-scale-factor-1 dolt 75273d6 52.71 dolt fd9284e 53.18 0.89

@coffeegoddd
Copy link
Copy Markdown
Contributor

@reltuk DOLT

comparing_percentages
100.000000 to 100.000000
version result total
83f8dd3 ok 5937471
version total_tests
83f8dd3 5937471
correctness_percentage
100.0

@reltuk reltuk merged commit 4a69899 into main May 28, 2026
29 of 30 checks passed
@coffeegoddd
Copy link
Copy Markdown
Contributor

@reltuk DOLT

comparing_percentages
100.000000 to 100.000000
version result total
fd9284e ok 5937471
version total_tests
fd9284e 5937471
correctness_percentage
100.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants