Skip to content

go: sqle/dsess: transactions.go: When serializing transaction commits against a working set, form the key with the normalized db name.#10456

Merged
reltuk merged 3 commits intomainfrom
aaron/concurrent-writes-optimistic-lock-failure
Feb 9, 2026
Merged

go: sqle/dsess: transactions.go: When serializing transaction commits against a working set, form the key with the normalized db name.#10456
reltuk merged 3 commits intomainfrom
aaron/concurrent-writes-optimistic-lock-failure

Conversation

@reltuk
Copy link
Copy Markdown
Contributor

@reltuk reltuk commented Feb 9, 2026

Previously, this lock would accidentally allow concurrent access to writing the database working set value because a non-normalized database name like db/main\x00/refs/heads/main would allow access along with a normalized database name like db\x00/refs/heads/main. This did not impact correctness, since the working sets are safe for concurrent modification at the storage layer, but it could cause transient failures for a client if the optimistic lock retries failed sequentially enough times.

Here we fix the bug so that the txLocks serialize access to the ref heads as expected.

… against a working set, form the key with the normalized db name.

Previously, this lock would accidentally allow concurrent access to writing the database working set value because a non-normalized database name like `db/main\x00/refs/heads/main` would allow access along with a normalized database name like `db\x00/refs/heads/main`. This did not impact correctness, since the working sets are safe for concurrent modification at the storage layer, but it could cause transient failures for a client if the optimistic lock retries failed sequentially enough times.

Here we fix the bug so that the txLocks serialize access to the ref heads as expected.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes transaction-commit serialization to ensure txLocks keying uses a normalized database name, preventing concurrent commit paths from bypassing the intended lock and causing transient optimistic-lock retry failures.

Changes:

  • Removes stale commented-out imports from an existing regression test file.
  • Adds a new integration test that stress-tests concurrent SQL writes + DOLT_COMMIT to exercise commit serialization behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
integration-tests/go-sql-server-driver/repro_10331_test.go Cleans up commented-out imports in an existing concurrency regression test.
integration-tests/go-sql-server-driver/concurrent_writes_test.go Adds a concurrent-writes integration test to validate stability under heavy commit contention.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +86 to +89
db, err := server.DB(driver.Connection{User: "root"})
require.NoError(t, err)
db.SetMaxOpenConns(1)
conn, err := db.Conn(ctx)
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

Each writer goroutine creates a new *sql.DB via server.DB(...) but never closes it. Over many goroutines this can leak connections / background goroutines and make the test flaky. Close the per-worker DB (e.g., defer db.Close() after creation) or reuse a shared DB and create per-worker conns/transactions instead.

Copilot uses AI. Check for mistakes.
Comment on lines +121 to +127
conn, err := db.Conn(ctx)
if err != nil {
require.NoError(t, err)
}
defer func () {
require.NoError(t, conn.Close())
}()
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

The error handling here is redundant/awkward (if err != nil { require.NoError(...) }) and the defer func () { spacing doesn’t match gofmt. Prefer a straight require.NoError(t, err) and a standard defer func() { ... }() to keep the test readable and consistent with the rest of the suite.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

@coffeegoddd coffeegoddd left a comment

Choose a reason for hiding this comment

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

LGTM!

reltuk and others added 2 commits February 9, 2026 13:01
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@coffeegoddd
Copy link
Copy Markdown
Contributor

@reltuk DOLT

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

@reltuk reltuk merged commit 7cb0d29 into main Feb 9, 2026
23 of 24 checks passed
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