Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 42 additions & 32 deletions pkg/sql/drop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1557,42 +1557,52 @@ func TestDropLargeDatabaseWithDeclarativeSchemaChanger(t *testing.T) {
func TestTruncateLarge(t *testing.T) {
defer leaktest.AfterTest(t)()
defer log.Scope(t).Close(t)
skip.UnderDuress(t, "truncating a large number of tables")
testTruncateLarge(t, true /* batchLimitSet */)
}

testutils.RunTrueAndFalse(t, "batch limit set", func(t *testing.T, batchLimitSet bool) {
ctx := context.Background()
srv, conn, _ := serverutils.StartServer(t, base.TestServerArgs{})
defer srv.Stopper().Stop(ctx)
sqlDB := sqlutils.MakeSQLRunner(conn)
createCommand := strings.Builder{}
truncateCommand := strings.Builder{}
systemDB := sqlutils.MakeSQLRunner(srv.SystemLayer().SQLConn(t))
systemDB.Exec(t, "SET CLUSTER SETTING kv.raft.command.max_size='5m'")
if batchLimitSet {
sqlDB.Exec(t, "SET CLUSTER SETTING sql.schema_changer.batch_flush_threshold_size='2m'")
}
// Generate the truncate and create table commands.
const numTables = 500
truncateCommand.WriteString("TRUNCATE TABLE ")
for i := range numTables {
createCommand.WriteString(fmt.Sprintf("CREATE TABLE t%d (a INT PRIMARY KEY, j INT, k INT, INDEX (j), INDEX (k), UNIQUE (j, k));\n", i))
truncateCommand.WriteString(fmt.Sprintf("t%d", i))
if i != numTables-1 {
truncateCommand.WriteString(", ")
}
}
// Execute the create commands first.
sqlDB.Exec(t, createCommand.String())
// TestTruncateLargeErr verifies that an error is returned if the batch limit is
// effectively not set.
func TestTruncateLargeErr(t *testing.T) {
defer leaktest.AfterTest(t)()
defer log.Scope(t).Close(t)
testTruncateLarge(t, false /* batchLimitSet */)
}

// The default limit is larger than our reduced raft command size, so if the
// limit is not modified, the truncate command will fail.
if batchLimitSet {
sqlDB.Exec(t, truncateCommand.String())
} else {
sqlDB.ExpectErr(t, "command is too large", truncateCommand.String())
}
func testTruncateLarge(t *testing.T, batchLimitSet bool) {
skip.UnderDuress(t, "truncating a large number of tables")

srv, conn, _ := serverutils.StartServer(t, base.TestServerArgs{
SQLMemoryPoolSize: 1 << 30, /* 1 GiB */
})
defer srv.Stopper().Stop(context.Background())
sqlDB := sqlutils.MakeSQLRunner(conn)
createCommand := strings.Builder{}
truncateCommand := strings.Builder{}
systemDB := sqlutils.MakeSQLRunner(srv.SystemLayer().SQLConn(t))
systemDB.Exec(t, "SET CLUSTER SETTING kv.raft.command.max_size='4.1MiB'")
if batchLimitSet {
sqlDB.Exec(t, "SET CLUSTER SETTING sql.schema_changer.batch_flush_threshold_size='1.8MiB'")
}
// Generate the truncate and create table commands.
const numTables = 340
truncateCommand.WriteString("TRUNCATE TABLE ")
for i := range numTables {
createCommand.WriteString(fmt.Sprintf("CREATE TABLE t%d (a INT PRIMARY KEY, j INT, k INT, INDEX (j), INDEX (k), UNIQUE (j, k));\n", i))
truncateCommand.WriteString(fmt.Sprintf("t%d", i))
if i != numTables-1 {
truncateCommand.WriteString(", ")
}
}
// Execute the create commands first.
sqlDB.Exec(t, createCommand.String())

// The default limit is larger than our reduced raft command size, so if the
// limit is not modified, the truncate command will fail.
if batchLimitSet {
sqlDB.Exec(t, truncateCommand.String())
} else {
sqlDB.ExpectErr(t, "command is too large", truncateCommand.String())
}
}

func BenchmarkDropLargeDatabaseWithGenerateTestObjects(b *testing.B) {
Expand Down