Skip to content

Commit 24d8278

Browse files
committed
upgrades: remove sampling stmt diagnostics migration from 22.2
We only support upgrading to 23.2 or later from at least 22.2, so we no longer need this non-permanent migration to add "sampling probability" column to the statement diagnostics table. Release note: None
1 parent 695d4ec commit 24d8278

File tree

9 files changed

+18
-344
lines changed

9 files changed

+18
-344
lines changed

pkg/cli/clisqlclient/statement_diag.go

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ package clisqlclient
1313
import (
1414
"context"
1515
"database/sql/driver"
16-
"fmt"
1716
"io"
1817
"os"
1918
"strconv"
@@ -127,39 +126,9 @@ func StmtDiagListOutstandingRequests(
127126
return result, nil
128127
}
129128

130-
// TODO(irfansharif): Remove this in 23.1.
131-
func isAtLeast22dot2ClusterVersion(ctx context.Context, conn Conn) (bool, error) {
132-
// Check whether the upgrade to add the sampling_probability column to the
133-
// statement_diagnostics_requests system table has already been run.
134-
row, err := conn.QueryRow(ctx, `
135-
SELECT
136-
count(*)
137-
FROM
138-
[SHOW COLUMNS FROM system.statement_diagnostics_requests]
139-
WHERE
140-
column_name = 'sampling_probability';`)
141-
if err != nil {
142-
return false, err
143-
}
144-
c, ok := row[0].(int64)
145-
if !ok {
146-
return false, nil
147-
}
148-
return c == 1, nil
149-
}
150-
151129
func stmtDiagListOutstandingRequestsInternal(
152130
ctx context.Context, conn Conn,
153131
) ([]StmtDiagActivationRequest, error) {
154-
var extraColumns string
155-
atLeast22dot2, err := isAtLeast22dot2ClusterVersion(ctx, conn)
156-
if err != nil {
157-
return nil, err
158-
}
159-
if atLeast22dot2 {
160-
extraColumns = ", sampling_probability"
161-
}
162-
163132
// Converting an INTERVAL to a number of milliseconds within that interval
164133
// is a pain - we extract the number of seconds and multiply it by 1000,
165134
// then we extract the number of milliseconds and add that up to the
@@ -169,10 +138,10 @@ func stmtDiagListOutstandingRequestsInternal(
169138
EXTRACT(millisecond FROM min_execution_latency)::INT8 -
170139
EXTRACT(second FROM min_execution_latency)::INT8 * 1000`
171140
rows, err := conn.Query(ctx,
172-
fmt.Sprintf("SELECT id, statement_fingerprint, requested_at, "+getMilliseconds+`, expires_at%s
141+
"SELECT id, statement_fingerprint, requested_at, "+getMilliseconds+`, expires_at, sampling_probability
173142
FROM system.statement_diagnostics_requests
174143
WHERE NOT completed
175-
ORDER BY requested_at DESC`, extraColumns),
144+
ORDER BY requested_at DESC`,
176145
)
177146
if err != nil {
178147
return nil, err
@@ -195,10 +164,8 @@ func stmtDiagListOutstandingRequestsInternal(
195164
if e, ok := vals[4].(time.Time); ok {
196165
expiresAt = e
197166
}
198-
if atLeast22dot2 {
199-
if sp, ok := vals[5].(float64); ok {
200-
samplingProbability = sp
201-
}
167+
if sp, ok := vals[5].(float64); ok {
168+
samplingProbability = sp
202169
}
203170
info := StmtDiagActivationRequest{
204171
ID: vals[0].(int64),

pkg/clusterversion/cockroach_versions.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,6 @@ const (
201201
TODODelete_V22_2RemoveGrantPrivilege
202202
// TODODelete_V22_2MVCCRangeTombstones enables the use of MVCC range tombstones.
203203
TODODelete_V22_2MVCCRangeTombstones
204-
// TODODelete_V22_2SampledStmtDiagReqs enables installing statement diagnostic requests that
205-
// probabilistically collects stmt bundles, controlled by the user provided
206-
// sampling rate.
207-
TODODelete_V22_2SampledStmtDiagReqs
208204
// TODODelete_V22_2SystemPrivilegesTable adds system.privileges table.
209205
TODODelete_V22_2SystemPrivilegesTable
210206
// TODODelete_V22_2EnablePredicateProjectionChangefeed indicates that changefeeds support
@@ -650,10 +646,6 @@ var rawVersionsSingleton = keyedVersions{
650646
Key: TODODelete_V22_2MVCCRangeTombstones,
651647
Version: roachpb.Version{Major: 22, Minor: 1, Internal: 16},
652648
},
653-
{
654-
Key: TODODelete_V22_2SampledStmtDiagReqs,
655-
Version: roachpb.Version{Major: 22, Minor: 1, Internal: 20},
656-
},
657649
{
658650
Key: TODODelete_V22_2SystemPrivilegesTable,
659651
Version: roachpb.Version{Major: 22, Minor: 1, Internal: 24},

pkg/server/statement_diagnostics_requests.go

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ package server
1212

1313
import (
1414
"context"
15-
"fmt"
1615
"time"
1716

18-
"github.com/cockroachdb/cockroach/pkg/clusterversion"
1917
"github.com/cockroachdb/cockroach/pkg/server/authserver"
2018
"github.com/cockroachdb/cockroach/pkg/server/serverpb"
2119
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
@@ -137,25 +135,20 @@ func (s *statusServer) StatementDiagnosticsRequests(
137135

138136
var err error
139137

140-
// TODO(irfansharif): Remove this version gating in 23.1.
141-
var extraColumns string
142-
if s.st.Version.IsActive(ctx, clusterversion.TODODelete_V22_2SampledStmtDiagReqs) {
143-
extraColumns = `,
144-
sampling_probability`
145-
}
146138
// TODO(davidh): Add pagination to this request.
147139
it, err := s.internalExecutor.QueryIteratorEx(ctx, "stmt-diag-get-all", nil, /* txn */
148140
sessiondata.RootUserSessionDataOverride,
149-
fmt.Sprintf(`SELECT
141+
`SELECT
150142
id,
151143
statement_fingerprint,
152144
completed,
153145
statement_diagnostics_id,
154146
requested_at,
155147
min_execution_latency,
156-
expires_at%s
148+
expires_at,
149+
sampling_probability
157150
FROM
158-
system.statement_diagnostics_requests`, extraColumns))
151+
system.statement_diagnostics_requests`)
159152
if err != nil {
160153
return nil, err
161154
}
@@ -179,10 +172,8 @@ func (s *statusServer) StatementDiagnosticsRequests(
179172
if requestedAt, ok := row[4].(*tree.DTimestampTZ); ok {
180173
req.RequestedAt = requestedAt.Time
181174
}
182-
if extraColumns != "" {
183-
if samplingProbability, ok := row[7].(*tree.DFloat); ok {
184-
req.SamplingProbability = float64(*samplingProbability)
185-
}
175+
if samplingProbability, ok := row[7].(*tree.DFloat); ok {
176+
req.SamplingProbability = float64(*samplingProbability)
186177
}
187178

188179
if minExecutionLatency, ok := row[5].(*tree.DInterval); ok {

pkg/sql/stmtdiagnostics/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ go_library(
66
importpath = "github.com/cockroachdb/cockroach/pkg/sql/stmtdiagnostics",
77
visibility = ["//visibility:public"],
88
deps = [
9-
"//pkg/clusterversion",
109
"//pkg/multitenant",
1110
"//pkg/settings",
1211
"//pkg/settings/cluster",

pkg/sql/stmtdiagnostics/statement_diagnostics.go

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"math/rand"
1717
"time"
1818

19-
"github.com/cockroachdb/cockroach/pkg/clusterversion"
2019
"github.com/cockroachdb/cockroach/pkg/multitenant"
2120
"github.com/cockroachdb/cockroach/pkg/settings"
2221
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
@@ -292,12 +291,6 @@ func (r *Registry) insertRequestInternal(
292291
minExecutionLatency time.Duration,
293292
expiresAfter time.Duration,
294293
) (RequestID, error) {
295-
isSamplingProbabilitySupported := r.st.Version.IsActive(ctx, clusterversion.TODODelete_V22_2SampledStmtDiagReqs)
296-
if !isSamplingProbabilitySupported && samplingProbability != 0 {
297-
return 0, errors.New(
298-
"sampling probability only supported after 22.2 version migrations have completed",
299-
)
300-
}
301294
if samplingProbability != 0 {
302295
if samplingProbability < 0 || samplingProbability > 1 {
303296
return 0, errors.Newf(
@@ -641,23 +634,18 @@ func (r *Registry) InsertStatementDiagnostics(
641634
// updates r.mu.requests accordingly.
642635
func (r *Registry) pollRequests(ctx context.Context) error {
643636
var rows []tree.Datums
644-
isSamplingProbabilitySupported := r.st.Version.IsActive(ctx, clusterversion.TODODelete_V22_2SampledStmtDiagReqs)
645637

646638
// Loop until we run the query without straddling an epoch increment.
647639
for {
648640
r.mu.Lock()
649641
epoch := r.mu.epoch
650642
r.mu.Unlock()
651643

652-
var extraColumns string
653-
if isSamplingProbabilitySupported {
654-
extraColumns = ", sampling_probability"
655-
}
656644
it, err := r.db.Executor().QueryIteratorEx(ctx, "stmt-diag-poll", nil, /* txn */
657645
sessiondata.RootUserSessionDataOverride,
658-
fmt.Sprintf(`SELECT id, statement_fingerprint, min_execution_latency, expires_at%s
646+
`SELECT id, statement_fingerprint, min_execution_latency, expires_at, sampling_probability
659647
FROM system.statement_diagnostics_requests
660-
WHERE completed = false AND (expires_at IS NULL OR expires_at > now())`, extraColumns),
648+
WHERE completed = false AND (expires_at IS NULL OR expires_at > now())`,
661649
)
662650
if err != nil {
663651
return err
@@ -698,14 +686,12 @@ func (r *Registry) pollRequests(ctx context.Context) error {
698686
if e, ok := row[3].(*tree.DTimestampTZ); ok {
699687
expiresAt = e.Time
700688
}
701-
if isSamplingProbabilitySupported {
702-
if prob, ok := row[4].(*tree.DFloat); ok {
703-
samplingProbability = float64(*prob)
704-
if samplingProbability < 0 || samplingProbability > 1 {
705-
log.Warningf(ctx, "malformed sampling probability for request %d: %f (expected in range [0, 1]), resetting to 1.0",
706-
id, samplingProbability)
707-
samplingProbability = 1.0
708-
}
689+
if prob, ok := row[4].(*tree.DFloat); ok {
690+
samplingProbability = float64(*prob)
691+
if samplingProbability < 0 || samplingProbability > 1 {
692+
log.Warningf(ctx, "malformed sampling probability for request %d: %f (expected in range [0, 1]), resetting to 1.0",
693+
id, samplingProbability)
694+
samplingProbability = 1.0
709695
}
710696
}
711697
ids.Add(int(id))

pkg/upgrade/upgrades/BUILD.bazel

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ go_library(
2222
"key_visualizer_migration.go",
2323
"permanent_upgrades.go",
2424
"role_members_ids_migration.go",
25-
"sampled_stmt_diagnostics_requests.go",
2625
"schema_changes.go",
2726
"schemachanger_elements.go",
2827
"sql_stats_ttl.go",
@@ -115,7 +114,6 @@ go_test(
115114
"key_visualizer_migration_test.go",
116115
"main_test.go",
117116
"role_members_ids_migration_test.go",
118-
"sampled_stmt_diagnostics_requests_test.go",
119117
"schema_changes_external_test.go",
120118
"schema_changes_helpers_test.go",
121119
"schemachanger_elements_test.go",

pkg/upgrade/upgrades/sampled_stmt_diagnostics_requests.go

Lines changed: 0 additions & 92 deletions
This file was deleted.

0 commit comments

Comments
 (0)