-
-
Notifications
You must be signed in to change notification settings - Fork 721
go/store/nbs: Fix possible data loss from Dolt CLI utilization when executing against a running server that was in the process of writing to its journal file. #10341
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
Merged
reltuk
merged 2 commits into
main
from
aaron/fix-10331-no-truncate-on-read-only-journal-open
Jan 21, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
173 changes: 173 additions & 0 deletions
173
integration-tests/go-sql-server-driver/repro_10331_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| // Copyright 2026 Dolthub, Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| // "context" | ||
| // "database/sql" | ||
| // sqldriver "database/sql/driver" | ||
| // "fmt" | ||
| // "strings" | ||
| "crypto/rand" | ||
| "encoding/base64" | ||
| "fmt" | ||
| "strconv" | ||
| "strings" | ||
| "sync/atomic" | ||
| "testing" | ||
| "time" | ||
|
|
||
| // "time" | ||
|
|
||
| // "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| "golang.org/x/sync/errgroup" | ||
|
|
||
| // "golang.org/x/sync/errgroup" | ||
|
|
||
| driver "github.com/dolthub/dolt/go/libraries/doltcore/dtestutils/sql_server_driver" | ||
| ) | ||
|
|
||
| // TestRegression10331 tests for the checksum error caused by concurrent executions of `dolt sql` | ||
| // while dolt sql-server is processing writes. | ||
| // | ||
| // https://github.com/dolthub/dolt/issues/10331 | ||
| func TestRegression10331(t *testing.T) { | ||
| t.Parallel() | ||
| // This test is not 100% reliable at detecting errors quickly, so we run it a few times. | ||
| const testCount = 4 | ||
| for i := range testCount { | ||
| t.Run(strconv.Itoa(i), func(t *testing.T) { | ||
| var ports DynamicResources | ||
| ports.global = &GlobalPorts | ||
| ports.t = t | ||
| u, err := driver.NewDoltUser() | ||
| require.NoError(t, err) | ||
| t.Cleanup(func() { | ||
| u.Cleanup() | ||
| }) | ||
|
|
||
| rs, err := u.MakeRepoStore() | ||
| require.NoError(t, err) | ||
|
|
||
| repo, err := rs.MakeRepo("regression_10331_test") | ||
| require.NoError(t, err) | ||
|
|
||
| srvSettings := &driver.Server{ | ||
| Args: []string{"-P", `{{get_port "server_port"}}`}, | ||
| DynamicPort: "server_port", | ||
| } | ||
| server := MakeServer(t, repo, srvSettings, &ports) | ||
| server.DBName = "regression_10331_test" | ||
|
|
||
| db, err := server.DB(driver.Connection{User: "root"}) | ||
| require.NoError(t, err) | ||
| defer db.Close() | ||
|
|
||
| ctx := t.Context() | ||
|
|
||
| func() { | ||
| conn, err := db.Conn(ctx) | ||
| require.NoError(t, err) | ||
| defer conn.Close() | ||
|
|
||
| // Create table and initial data. | ||
| _, err = conn.ExecContext(ctx, "CREATE TABLE data (id INT PRIMARY KEY AUTO_INCREMENT, val LONGTEXT)") | ||
| require.NoError(t, err) | ||
| for i := 0; i <= 50; i++ { | ||
| var bs [10240]byte | ||
| rand.Read(bs[:]) | ||
| data := base64.StdEncoding.EncodeToString(bs[:]) | ||
| _, err = conn.ExecContext(ctx, "INSERT INTO data (val) VALUES (?)", data) | ||
| require.NoError(t, err) | ||
| } | ||
| _, err = conn.ExecContext(ctx, "CALL DOLT_COMMIT('-Am', 'init with data')") | ||
| require.NoError(t, err) | ||
| }() | ||
|
|
||
| eg, ctx := errgroup.WithContext(ctx) | ||
| start := time.Now() | ||
|
|
||
| var successfulWrites, successfulReads int32 | ||
| var errWrites, errReads int32 | ||
| const numWriters = 8 | ||
| const numReaders = 16 | ||
| const testDuration = 8 * time.Second | ||
| for i := range numWriters { | ||
| eg.Go(func() error { | ||
| var bs [1024]byte | ||
| rand.Read(bs[:]) | ||
| data := base64.StdEncoding.EncodeToString(bs[:]) | ||
| j := 0 | ||
| for { | ||
| if time.Since(start) > testDuration { | ||
| return nil | ||
| } | ||
| if ctx.Err() != nil { | ||
| return nil | ||
| } | ||
| out, err := func() (string, error) { | ||
| cmd := repo.DoltCmd("sql", "-r", "csv", "-q", fmt.Sprintf("INSERT INTO data (val) VALUES ('%s'); CALL DOLT_COMMIT('--allow-empty', '-Am', 'w%d c%d')", data, i, j)) | ||
| out, err := cmd.CombinedOutput() | ||
| return string(out), err | ||
| }() | ||
| if err != nil { | ||
| t.Logf("error writing, %v", err) | ||
| atomic.AddInt32(&errWrites, 1) | ||
| if strings.Contains(out, "checksum") || strings.Contains(out, " EOF") { | ||
| return fmt.Errorf("error writing values %d: %s, %w", i, out, err) | ||
| } | ||
| } else { | ||
| atomic.AddInt32(&successfulWrites, 1) | ||
| } | ||
| j += 1 | ||
| } | ||
| }) | ||
| } | ||
| for i := range numReaders { | ||
| eg.Go(func() error { | ||
| j := 0 | ||
| for { | ||
| if time.Since(start) > testDuration { | ||
| return nil | ||
| } | ||
| if ctx.Err() != nil { | ||
| return nil | ||
| } | ||
| out, err := func() (string, error) { | ||
| cmd := repo.DoltCmd("sql", "-r", "csv", "-q", "SELECT COUNT(*) FROM data; SELECT * FROM dolt_log LIMIT 20") | ||
| out, err := cmd.CombinedOutput() | ||
| return string(out), err | ||
| }() | ||
| if err != nil { | ||
| t.Logf("error reading, %v", err) | ||
| atomic.AddInt32(&errReads, 1) | ||
| if strings.Contains(out, "checksum") || strings.Contains(out, " EOF") { | ||
| return fmt.Errorf("READER error %d: %s, %w", i, out, err) | ||
| } | ||
| } else { | ||
| atomic.AddInt32(&successfulReads, 1) | ||
| } | ||
| j += 1 | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| require.NoError(t, eg.Wait()) | ||
| t.Logf("err writes: %d, err reads: %d", errWrites, errReads) | ||
| t.Logf("successful writes: %d, successful reads: %d", successfulWrites, successfulReads) | ||
| }) | ||
| } | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about a test where we pass false and watch it do the right thing?