-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
69486: sql: support for temporary table clean up for tenants r=fqazi a=fqazi Fixes: #67401 Previously, the temporary table clean-up did not execute for tenants. This was inadequate that temporary tables would last longer than the life span of user sessions. To address this, this patch adds support for cleaning up on a single tenant pod. Specifically removing checks for meta1 lease when under a tenant, and support for listing sessions. Release justification: low risk and fixes a tenant-related bug Release note (bug fix): Temporary tables were not properly cleaned up for tenants. 69789: sql: drop database cascade can fail resolving schemas r=fqazi a=fqazi Fixes: #69713 Previously, drop database cascade would drop the schema first, and then drop any objects under those schemas after. This was inadequate because as we look up any objects under the schemas, we may need to resolve types, which will may lead to a look up on the schema. If the schema is dropped then we will fail while resolving any types. To address this, this patch drops the objects under the schema first followed by the database. Release justification: Low risk bug fix for drop database cascade Release note (bug fix): Drop database cascade can fail while resolving a schema in a certain scenarios with the following error: "ERROR: error resolving referenced table ID <ID>: descriptor is being dropped" 69975: sql: fix interaction between stmt bundles and tracing r=yuzefovich a=yuzefovich Previously, we wouldn't generate the bundle if the verbose tracing was already enabled on the cluster because we wouldn't call `instrumentationHelper.Finish` where we actually generate the bundle. This would result in empty responses for `EXPLAIN ANALYZE (DEBUG)` as well as the requests for stmt diagnostics being stuck in "waiting" state. Fixes: #69398. Release note (bug fix): Previously, if the tracing (`sql.trace.txn.enable_threshold` cluster setting) was enabled on the cluster, the statement diagnostics collection (`EXPLAIN ANALYZE (DEBUG)`) wouldn't work. This is now fixed. Release justification: low-risk fix to a long-standing bug. Co-authored-by: Faizan Qazi <faizan@cockroachlabs.com> Co-authored-by: Yahor Yuzefovich <yahor@cockroachlabs.com>
- Loading branch information
Showing
17 changed files
with
351 additions
and
52 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,127 @@ | ||
// Copyright 2021 The Cockroach Authors. | ||
// | ||
// Licensed as a CockroachDB Enterprise file under the Cockroach Community | ||
// License (the "License"); you may not use this file except in compliance with | ||
// the License. You may obtain a copy of the License at | ||
// | ||
// https://github.com/cockroachdb/cockroach/blob/master/licenses/CCL.txt | ||
|
||
package sqlccl_test | ||
|
||
import ( | ||
"context" | ||
"reflect" | ||
"testing" | ||
"time" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/base" | ||
"github.com/cockroachdb/cockroach/pkg/settings/cluster" | ||
"github.com/cockroachdb/cockroach/pkg/sql" | ||
"github.com/cockroachdb/cockroach/pkg/sql/sqlliveness/slinstance" | ||
"github.com/cockroachdb/cockroach/pkg/testutils/serverutils" | ||
"github.com/cockroachdb/cockroach/pkg/testutils/sqlutils" | ||
"github.com/cockroachdb/cockroach/pkg/util/leaktest" | ||
"github.com/cockroachdb/cockroach/pkg/util/log" | ||
"github.com/cockroachdb/cockroach/pkg/util/stop" | ||
"github.com/cockroachdb/cockroach/pkg/util/timeutil" | ||
) | ||
|
||
func TestTenantTempTableCleanup(t *testing.T) { | ||
defer leaktest.AfterTest(t)() | ||
|
||
ctx := context.Background() | ||
t.Helper() | ||
settings := cluster.MakeTestingClusterSettings() | ||
sql.TempObjectCleanupInterval.Override(ctx, &settings.SV, time.Second) | ||
sql.TempObjectWaitInterval.Override(ctx, &settings.SV, time.Second*0) | ||
// Set up sessions to expire within 5 seconds of a | ||
// nodes death. | ||
slinstance.DefaultTTL.Override(ctx, &settings.SV, 5*time.Second) | ||
slinstance.DefaultHeartBeat.Override(ctx, &settings.SV, time.Second) | ||
|
||
tc := serverutils.StartNewTestCluster( | ||
t, 3 /* numNodes */, base.TestClusterArgs{ReplicationMode: base.ReplicationManual, | ||
ServerArgs: base.TestServerArgs{ | ||
Settings: settings, | ||
}}, | ||
) | ||
log.TestingClearServerIdentifiers() | ||
tenantStoppers := []*stop.Stopper{stop.NewStopper(), stop.NewStopper()} | ||
_, tenantPrimaryDB := serverutils.StartTenant(t, tc.Server(0), | ||
base.TestTenantArgs{ | ||
TenantID: serverutils.TestTenantID(), | ||
Settings: settings, | ||
Stopper: tenantStoppers[0], | ||
}) | ||
tenantSQL := sqlutils.MakeSQLRunner(tenantPrimaryDB) | ||
|
||
// Sanity: Temporary table clean up works fine, we are going | ||
// to start two nodes and close the kill one of | ||
// them. | ||
tenantSQL.Exec(t, "SET experimental_enable_temp_tables = 'on'") | ||
tenantSQL.Exec(t, "set cluster setting sql.temp_object_cleaner.cleanup_interval='1 seconds'") | ||
tenantSQL.Exec(t, "CREATE TEMP TABLE temp_table (x INT PRIMARY KEY, y INT);") | ||
// Prevent a logging assertion that the server ID is initialized multiple times. | ||
log.TestingClearServerIdentifiers() | ||
_, tenantSecondDB := serverutils.StartTenant(t, tc.Server(1), | ||
base.TestTenantArgs{ | ||
Existing: true, | ||
TenantID: serverutils.TestTenantID(), | ||
Settings: settings, | ||
Stopper: tenantStoppers[1], | ||
}) | ||
log.TestingClearServerIdentifiers() | ||
tenantSecondSQL := sqlutils.MakeSQLRunner(tenantSecondDB) | ||
tenantSecondSQL.CheckQueryResults(t, "SELECT table_name FROM [SHOW TABLES]", | ||
[][]string{ | ||
{"temp_table"}, | ||
}) | ||
tenantSecondSQL.Exec(t, "SET experimental_enable_temp_tables = 'on'") | ||
tenantSecondSQL.Exec(t, "CREATE TEMP TABLE temp_table2 (x INT PRIMARY KEY, y INT);") | ||
tenantSecondSQL.CheckQueryResults(t, "SELECT table_name FROM [SHOW TABLES]", | ||
[][]string{ | ||
{"temp_table"}, | ||
{"temp_table2"}, | ||
}) | ||
// Stop the second node, we should one be left with a single temp table. | ||
tenantStoppers[1].Stop(ctx) | ||
// Session should expire in 5 seconds, but | ||
// we will wait for up to 15 seconds. | ||
{ | ||
tEnd := timeutil.Now().Add(time.Second * 15) | ||
found := false | ||
lastResult := [][]string{} | ||
expectedResult := [][]string{ | ||
{"temp_table"}, | ||
} | ||
for tEnd.After(timeutil.Now()) { | ||
lastResult = tenantSQL.QueryStr(t, "SELECT table_name FROM [SHOW TABLES]") | ||
if reflect.DeepEqual(lastResult, expectedResult) { | ||
found = true | ||
break | ||
} | ||
} | ||
if !found { | ||
log.Fatalf(ctx, "temporary table was not correctly dropped, expected %v and got %v", expectedResult, lastResult) | ||
} | ||
} | ||
|
||
// Close the primary DB, there should be no temporary | ||
// tables left. | ||
tenantPrimaryDB.Close() | ||
// Prevent a logging assertion that the server ID is initialized multiple times. | ||
log.TestingClearServerIdentifiers() | ||
// Once we restart the tenant, no sessions should exist | ||
// so all temporary tables should be cleaned up. | ||
_, tenantPrimaryDB = serverutils.StartTenant(t, tc.Server(0), | ||
base.TestTenantArgs{ | ||
Existing: true, | ||
TenantID: serverutils.TestTenantID(), | ||
Settings: settings, | ||
Stopper: tenantStoppers[0]}) | ||
tenantSQL = sqlutils.MakeSQLRunner(tenantPrimaryDB) | ||
tenantSQL.CheckQueryResultsRetry(t, "SELECT table_name FROM [SHOW TABLES]", | ||
[][]string{}) | ||
tenantStoppers[0].Stop(ctx) | ||
tc.Stopper().Stop(ctx) | ||
} |
This file contains 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 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 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 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 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
Oops, something went wrong.