* ci(bazel): scope the proxied lane's shared-server projects to their own database (44 -> 28 shards)
//cmd/bd:bd_proxied_test spends nearly all its time in `bd init
--proxied-server` against the shard's shared dolt sql-server. Measured
where that goes (dolt query log): of ~2,031 statements per init, the ~220
INFORMATION_SCHEMA queries (migration guards and pre-repair probes) are
~80% of server time at a handful of databases, the 81 DOLT_COMMITs only
~0.5s. Dolt evaluates INFORMATION_SCHEMA by walking every database the
session can see, so as root each init cost the server ~1.2 CPU-seconds
more per database already on it (locally 6.7 CPU-s with 1 database, 21
with 11): a shard's k-th init paid for the k-1 projects before it.
- proxied_shared_harness_test.go: newSharedProxiedProject now provisions
the database server-side (root creates it plus a passwordless user of
the same name with ALL on it and nothing else) and inits with
--proxied-server-external-user, so each project's sessions see one
database. newSharedProxiedRootProject keeps the old root/bd-creates-it
shape for the four tests that need a server-wide privilege (DOLT_REMOTE
remove, CREATE DATABASE, one compact statement); a run with the server
log in test outputs showed no other denied statement.
- Dropping finished databases instead was tried and rejected: a DROP
DATABASE fails other sessions' in-flight INFORMATION_SCHEMA queries
("no root value found in session"), ~35 init failures per run.
- No assertion changed. The bd-creates-the-database path stays covered
by the root variant, the managed-local and non-shared init tests.
- proxied_test_durations.json re-measured (two rbe-west runs): 19,618 ->
6,345 cost-seconds. 44 -> 28 shards, LPT-packed to ~227 per shard.
rbe-west, --nocache_test_results (BEP attempt durations): before 44
shards, sum 6,063s, max 186s; scoped users at 44 shards, sum 2,337s, max
68s; at 20 shards, sum 1,950s, max 136s.
Bead: ga-vnycm2.16
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* ci(bazel): proxied lane 28 -> 34 shards for a <=100s slowest shard
PR CI at 28 shards (~227 packed cost each): 2,285 shard-seconds, median
78s, but max 113s; equally packed shards spread up to 1.45x the median.
34 shards (~187 each) targets a slowest shard under 100s.
Bead: ga-vnycm2.16
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
134 lines
5 KiB
Go
134 lines
5 KiB
Go
//go:build cgo
|
|
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// These tests exercise `bd sql`, not the managed-local backend lifecycle, so
|
|
// they run against the shared per-binary dolt sql-server instead of having
|
|
// each `bd init --proxied-server` spawn its own. A spawned backend's port is
|
|
// picked bind-and-close at init and bound by dolt seconds later; under the
|
|
// parallel proxied tier another process can take it in between, dolt exits
|
|
// with "Port N already in use", and the proxy's dial-only readiness check has
|
|
// already accepted the foreign listener, so init's first ping dies with
|
|
// "unexpected EOF" then "connection refused". The shared server's own startup
|
|
// (testutil.localDoltServer) waits for dolt's ready line and retries on
|
|
// another port, so it does not have that race.
|
|
func TestProxiedServerMultiStatementSQL(t *testing.T) {
|
|
bd := buildEmbeddedBD(t)
|
|
p := newSharedProxiedProject(t, bd, "ms")
|
|
|
|
// A multi-statement batch is treated as a write: it executes and commits
|
|
// atomically, and reports "OK" with no rows-affected count.
|
|
batch := "CREATE TABLE ms_t (id INT PRIMARY KEY); INSERT INTO ms_t VALUES (1); INSERT INTO ms_t VALUES (2)"
|
|
out, err := bdProxiedRun(t, bd, p.dir, "sql", batch)
|
|
if err != nil {
|
|
t.Fatalf("bd sql multi-statement failed: %v\n%s", err, out)
|
|
}
|
|
got := strings.TrimSpace(string(out))
|
|
if got != "OK" {
|
|
t.Fatalf("multi-statement output = %q, want %q", got, "OK")
|
|
}
|
|
|
|
// Both inserts must have committed.
|
|
db := openProxiedDB(t, p)
|
|
var n int
|
|
if err := db.QueryRowContext(context.Background(), "SELECT COUNT(*) FROM ms_t").Scan(&n); err != nil {
|
|
t.Fatalf("count ms_t: %v", err)
|
|
}
|
|
if n != 2 {
|
|
t.Fatalf("ms_t row count = %d, want 2 (multi-statement writes not committed)", n)
|
|
}
|
|
|
|
// A single write still reports the affected-row count.
|
|
out, err = bdProxiedRun(t, bd, p.dir, "sql", "INSERT INTO ms_t VALUES (3)")
|
|
if err != nil {
|
|
t.Fatalf("bd sql single write failed: %v\n%s", err, out)
|
|
}
|
|
if got := strings.TrimSpace(string(out)); got != "OK, 1 rows affected" {
|
|
t.Fatalf("single-write output = %q, want %q", got, "OK, 1 rows affected")
|
|
}
|
|
|
|
// A single read still renders a result table.
|
|
out, err = bdProxiedRun(t, bd, p.dir, "sql", "SELECT COUNT(*) AS c FROM ms_t")
|
|
if err != nil {
|
|
t.Fatalf("bd sql single read failed: %v\n%s", err, out)
|
|
}
|
|
if s := string(out); !strings.Contains(s, "c") || !strings.Contains(s, "3") {
|
|
t.Fatalf("single-read output missing rendered result:\n%s", s)
|
|
}
|
|
|
|
// Multi-statement with --json reports a status object, not rows_affected.
|
|
out, err = bdProxiedRun(t, bd, p.dir, "sql", "--json",
|
|
"INSERT INTO ms_t VALUES (4); INSERT INTO ms_t VALUES (5)")
|
|
if err != nil {
|
|
t.Fatalf("bd sql --json multi-statement failed: %v\n%s", err, out)
|
|
}
|
|
s := string(out)
|
|
if !strings.Contains(s, "\"status\"") || !strings.Contains(s, "ok") {
|
|
t.Fatalf("multi-statement --json output = %q, want a status:ok object", s)
|
|
}
|
|
if strings.Contains(s, "rows_affected") {
|
|
t.Fatalf("multi-statement --json should not include rows_affected: %q", s)
|
|
}
|
|
}
|
|
|
|
func TestProxiedServerSQLDatabaseFlag(t *testing.T) {
|
|
bd := buildEmbeddedBD(t)
|
|
p := newSharedProxiedRootProject(t, bd, "df")
|
|
|
|
// Stand up a second database with a table, alongside the project database.
|
|
// The server is shared, so the name derives from the project's unique one.
|
|
other := p.database + "_other"
|
|
db := openProxiedDB(t, p)
|
|
for _, q := range []string{
|
|
"CREATE DATABASE " + other,
|
|
"USE " + other + "; CREATE TABLE widgets (id INT PRIMARY KEY, name VARCHAR(32))",
|
|
} {
|
|
if _, err := db.ExecContext(context.Background(), q); err != nil {
|
|
t.Fatalf("setup %q: %v", q, err)
|
|
}
|
|
}
|
|
|
|
// A single write routed to the other database with --database.
|
|
out, err := bdProxiedRun(t, bd, p.dir, "sql", "--database", other,
|
|
"INSERT INTO widgets VALUES (1, 'gear')")
|
|
if err != nil {
|
|
t.Fatalf("bd sql --database write failed: %v\n%s", err, out)
|
|
}
|
|
if got := strings.TrimSpace(string(out)); got != "OK, 1 rows affected" {
|
|
t.Fatalf("--database write output = %q, want %q", got, "OK, 1 rows affected")
|
|
}
|
|
|
|
// The write must have committed in the other database, not the project one.
|
|
var n int
|
|
if err := db.QueryRowContext(context.Background(),
|
|
"SELECT COUNT(*) FROM "+other+".widgets WHERE name = 'gear'").Scan(&n); err != nil {
|
|
t.Fatalf("count %s.widgets: %v", other, err)
|
|
}
|
|
if n != 1 {
|
|
t.Fatalf("%s.widgets rows = %d, want 1 (--database write not committed there)", other, n)
|
|
}
|
|
|
|
// A read routed with --database against an unqualified table name resolves
|
|
// in the switched database and renders results.
|
|
out, err = bdProxiedRun(t, bd, p.dir, "sql", "--database", other,
|
|
"SELECT name FROM widgets WHERE id = 1")
|
|
if err != nil {
|
|
t.Fatalf("bd sql --database read failed: %v\n%s", err, out)
|
|
}
|
|
if s := string(out); !strings.Contains(s, "gear") {
|
|
t.Fatalf("--database read output missing 'gear':\n%s", s)
|
|
}
|
|
|
|
// An invalid database identifier is rejected, not interpolated.
|
|
out, err = bdProxiedRun(t, bd, p.dir, "sql", "--database", "bad;name",
|
|
"SELECT 1")
|
|
if err == nil {
|
|
t.Fatalf("expected --database with invalid identifier to fail; got:\n%s", out)
|
|
}
|
|
}
|