Skip to content

Commit 2b8a0ae

Browse files
craig[bot]cthumuluru-crdb
andcommitted
Merge #147693
147693: upgrade: consolidate RPC clients creation r=cthumuluru-crdb a=cthumuluru-crdb This commit consolidates migration RPC client creation logic in the upgrade package. It is a continuation of the work done in #147606. Epic: CRDB-48923 Informs: #147757 Release note: none Co-authored-by: Chandra Thumuluru <[email protected]>
2 parents 65877a4 + aebecd1 commit 2b8a0ae

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

pkg/server/serverpb/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ go_library(
102102
name = "serverpb",
103103
srcs = [
104104
"admin.go",
105+
"rpc_clients.go",
105106
"status.go",
106107
],
107108
embed = [":serverpb_go_proto"],
@@ -110,6 +111,7 @@ go_library(
110111
deps = [
111112
"//pkg/gossip",
112113
"//pkg/roachpb",
114+
"//pkg/rpc/rpcbase",
113115
"//pkg/util/errorutil",
114116
"//pkg/util/metric",
115117
"@com_github_prometheus_client_model//go",

pkg/server/serverpb/rpc_clients.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2025 The Cockroach Authors.
2+
//
3+
// Use of this software is governed by the CockroachDB Software License
4+
// included in the /LICENSE file.
5+
6+
package serverpb
7+
8+
import (
9+
context "context"
10+
11+
roachpb "github.com/cockroachdb/cockroach/pkg/roachpb"
12+
"github.com/cockroachdb/cockroach/pkg/rpc/rpcbase"
13+
)
14+
15+
// DialMigrationClient establishes a DRPC connection if enabled; otherwise,
16+
// it falls back to gRPC. The established connection is used to create a
17+
// MigrationClient.
18+
func DialMigrationClient(
19+
nd rpcbase.NodeDialer, ctx context.Context, nodeID roachpb.NodeID, class rpcbase.ConnectionClass,
20+
) (MigrationClient, error) {
21+
if !rpcbase.TODODRPC {
22+
conn, err := nd.Dial(ctx, nodeID, class)
23+
if err != nil {
24+
return nil, err
25+
}
26+
return NewMigrationClient(conn), nil
27+
}
28+
return nil, nil
29+
}

pkg/upgrade/upgradecluster/cluster.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,10 @@ func (c *Cluster) ForEveryNodeOrServer(
139139
grp.GoCtx(func(ctx context.Context) error {
140140
defer alloc.Release()
141141

142-
conn, err := c.c.Dialer.Dial(ctx, node.ID, rpcbase.DefaultClass)
142+
client, err := serverpb.DialMigrationClient(c.c.Dialer, ctx, node.ID, rpcbase.DefaultClass)
143143
if err != nil {
144144
return err
145145
}
146-
client := serverpb.NewMigrationClient(conn)
147146
return fn(ctx, client)
148147
})
149148
}

pkg/upgrade/upgradecluster/tenant_cluster.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"github.com/cockroachdb/cockroach/pkg/util/retry"
2626
"github.com/cockroachdb/errors"
2727
"github.com/cockroachdb/redact"
28-
"google.golang.org/grpc"
2928
)
3029

3130
// TenantCluster represents the set of sql nodes running in a secondary tenant.
@@ -225,7 +224,7 @@ func (t *TenantCluster) ForEveryNodeOrServer(
225224
grp.GoCtx(func(ctx context.Context) error {
226225
defer alloc.Release()
227226

228-
var conn *grpc.ClientConn
227+
var client serverpb.MigrationClient
229228
retryOpts := retry.Options{
230229
InitialBackoff: 1 * time.Millisecond,
231230
MaxRetries: 20,
@@ -235,12 +234,11 @@ func (t *TenantCluster) ForEveryNodeOrServer(
235234
// test flakes due to network issues.
236235
if err := retry.WithMaxAttempts(ctx, retryOpts, retryOpts.MaxRetries+1, func() error {
237236
var err error
238-
conn, err = t.Dialer.Dial(ctx, roachpb.NodeID(instance.InstanceID), rpcbase.DefaultClass)
237+
client, err = serverpb.DialMigrationClient(t.Dialer, ctx, roachpb.NodeID(instance.InstanceID), rpcbase.DefaultClass)
239238
return err
240239
}); err != nil {
241240
return annotateDialError(err)
242241
}
243-
client := serverpb.NewMigrationClient(conn)
244242
return fn(ctx, client)
245243
})
246244
}

0 commit comments

Comments
 (0)