-
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.
70586: sql,server: enable tenant status server to work with persisted SQL stats r=maryliag,dhartunian a=Azhng Previsouly, tenant status server was not able to work with the new persisted SQL Stats. This result in SQL Stats RPC not able to return or reset persisted SQL stats. This commit addresses this issue to update tenant status server's implementation to be able to work with persisted SQL Stats. Resolves #70585 #70529 #68177 Release Justification: Bug fixes and low-risk updates to new functionality Release note (bug fix): Statement/Transaction Page now is able to display and reset persisted SQL Stats. 70707: clusterversion,storage: cluster version that uses Pebble's SetWithDelete r=sumeerbhola a=sumeerbhola This is a backwards incompatible change in Pebble to provide SingleDelete semantics that are clean and robust to programming error. This is being done post v21.2-beta but before GA since this was deemed a GA blocker and not a release blocker. It allows for upgrading beta clusters to the GA version. For more on these discussions see the following threads cockroachdb/pebble#1255 (comment), https://cockroachlabs.slack.com/archives/C4A9ALLRL/p1631213490022600 (Cockroach Labs internal link). Informs cockroachdb/pebble#1255 Informs #69891 Release note: None Release justification: high-severity bug fix Co-authored-by: Azhng <archer.xn@gmail.com> Co-authored-by: sumeerbhola <sumeer@cockroachlabs.com>
- Loading branch information
Showing
21 changed files
with
981 additions
and
494 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
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,148 @@ | ||
// 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 serverccl | ||
|
||
import ( | ||
"context" | ||
gosql "database/sql" | ||
"testing" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/base" | ||
"github.com/cockroachdb/cockroach/pkg/roachpb" | ||
"github.com/cockroachdb/cockroach/pkg/security" | ||
"github.com/cockroachdb/cockroach/pkg/server/serverpb" | ||
"github.com/cockroachdb/cockroach/pkg/sql/pgwire" | ||
"github.com/cockroachdb/cockroach/pkg/sql/sqlstats/persistedsqlstats" | ||
"github.com/cockroachdb/cockroach/pkg/sql/tests" | ||
"github.com/cockroachdb/cockroach/pkg/testutils/serverutils" | ||
"github.com/cockroachdb/cockroach/pkg/testutils/sqlutils" | ||
"github.com/cockroachdb/cockroach/pkg/util/log" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type testTenant struct { | ||
tenant serverutils.TestTenantInterface | ||
tenantConn *gosql.DB | ||
tenantDB *sqlutils.SQLRunner | ||
tenantStatus serverpb.SQLStatusServer | ||
tenantSQLStats *persistedsqlstats.PersistedSQLStats | ||
} | ||
|
||
func newTestTenant( | ||
t *testing.T, server serverutils.TestServerInterface, existing bool, tenantID roachpb.TenantID, | ||
) *testTenant { | ||
t.Helper() | ||
|
||
tenantParams := tests.CreateTestTenantParams(tenantID) | ||
tenantParams.Existing = existing | ||
|
||
log.TestingClearServerIdentifiers() | ||
tenant, tenantConn := serverutils.StartTenant(t, server, tenantParams) | ||
sqlDB := sqlutils.MakeSQLRunner(tenantConn) | ||
status := tenant.StatusServer().(serverpb.SQLStatusServer) | ||
sqlStats := tenant.PGServer().(*pgwire.Server).SQLServer. | ||
GetSQLStatsProvider().(*persistedsqlstats.PersistedSQLStats) | ||
|
||
return &testTenant{ | ||
tenant: tenant, | ||
tenantConn: tenantConn, | ||
tenantDB: sqlDB, | ||
tenantStatus: status, | ||
tenantSQLStats: sqlStats, | ||
} | ||
} | ||
|
||
func (h *testTenant) cleanup(t *testing.T) { | ||
require.NoError(t, h.tenantConn.Close()) | ||
} | ||
|
||
type tenantTestHelper struct { | ||
hostCluster serverutils.TestClusterInterface | ||
|
||
// Creating two separate tenant clusters. This allows unit tests to test | ||
// the isolation between different tenants are properly enforced. | ||
tenantTestCluster tenantCluster | ||
tenantControlCluster tenantCluster | ||
} | ||
|
||
func newTestTenantHelper(t *testing.T, tenantClusterSize int) *tenantTestHelper { | ||
t.Helper() | ||
|
||
params, _ := tests.CreateTestServerParams() | ||
testCluster := serverutils.StartNewTestCluster(t, 3 /* numNodes */, base.TestClusterArgs{ | ||
ServerArgs: params, | ||
}) | ||
server := testCluster.Server(0) | ||
|
||
return &tenantTestHelper{ | ||
hostCluster: testCluster, | ||
tenantTestCluster: newTenantCluster( | ||
t, | ||
server, | ||
tenantClusterSize, | ||
security.EmbeddedTenantIDs()[0], | ||
), | ||
tenantControlCluster: newTenantCluster( | ||
t, | ||
server, | ||
tenantClusterSize, | ||
security.EmbeddedTenantIDs()[1], | ||
), | ||
} | ||
} | ||
|
||
func (h *tenantTestHelper) testCluster() tenantCluster { | ||
return h.tenantTestCluster | ||
} | ||
|
||
func (h *tenantTestHelper) controlCluster() tenantCluster { | ||
return h.tenantControlCluster | ||
} | ||
|
||
func (h *tenantTestHelper) cleanup(ctx context.Context, t *testing.T) { | ||
t.Helper() | ||
h.hostCluster.Stopper().Stop(ctx) | ||
h.tenantTestCluster.cleanup(t) | ||
h.tenantControlCluster.cleanup(t) | ||
} | ||
|
||
type tenantCluster []*testTenant | ||
|
||
func newTenantCluster( | ||
t *testing.T, server serverutils.TestServerInterface, tenantClusterSize int, tenantID uint64, | ||
) tenantCluster { | ||
t.Helper() | ||
|
||
cluster := make([]*testTenant, tenantClusterSize) | ||
existing := false | ||
for i := 0; i < tenantClusterSize; i++ { | ||
cluster[i] = newTestTenant(t, server, existing, roachpb.MakeTenantID(tenantID)) | ||
existing = true | ||
} | ||
|
||
return cluster | ||
} | ||
|
||
func (c tenantCluster) tenantConn(idx int) *sqlutils.SQLRunner { | ||
return c[idx].tenantDB | ||
} | ||
|
||
func (c tenantCluster) tenantSQLStats(idx int) *persistedsqlstats.PersistedSQLStats { | ||
return c[idx].tenantSQLStats | ||
} | ||
|
||
func (c tenantCluster) tenantStatusSrv(idx int) serverpb.SQLStatusServer { | ||
return c[idx].tenantStatus | ||
} | ||
|
||
func (c tenantCluster) cleanup(t *testing.T) { | ||
for _, tenant := range c { | ||
tenant.cleanup(t) | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.