@@ -50,7 +50,7 @@ func (n *checkExternalConnectionNode) startExec(params runParams) error {
50
50
return err
51
51
}
52
52
53
- ctx , span := tracing .ChildSpan (params .ctx , "CheckExternalConnection" )
53
+ ctx , span := tracing .ChildSpan (params .ctx , "CheckExternalConnection-planning " )
54
54
defer span .Finish ()
55
55
56
56
store , err := params .ExecCfg ().DistSQLSrv .ExternalStorageFromURI (ctx , n .loc , params .p .User ())
@@ -90,7 +90,7 @@ func (n *checkExternalConnectionNode) startExec(params runParams) error {
90
90
time .Duration (tree .MustBeDInt (nanos )),
91
91
))
92
92
}
93
- n .rows = make (chan tree.Datums , int64 ( len (sqlInstanceIDs )) * n .params . Concurrency )
93
+ n .rows = make (chan tree.Datums , len (sqlInstanceIDs )* getCloudCheckConcurrency ( n .params ) )
94
94
rowWriter := NewCallbackResultWriter (func (ctx context.Context , row tree.Datums ) error {
95
95
// collapse the two pairs of bytes+time to a single string rate each.
96
96
res := make (tree.Datums , len (row )- 1 )
@@ -103,9 +103,16 @@ func (n *checkExternalConnectionNode) startExec(params runParams) error {
103
103
return nil
104
104
})
105
105
106
- grp := ctxgroup .WithContext (ctx )
107
- n .execGrp = grp
108
- grp .GoCtx (func (ctx context.Context ) error {
106
+ workerStarted := make (chan struct {})
107
+ n .execGrp = ctxgroup .WithContext (params .ctx )
108
+ n .execGrp .GoCtx (func (ctx context.Context ) error {
109
+ // Derive a separate tracing span since the planning one will be
110
+ // finished when the main goroutine exits from startExec.
111
+ ctx , span := tracing .ChildSpan (ctx , "CheckExternalConnection-execution" )
112
+ defer span .Finish ()
113
+ // Unblock the main goroutine after having created the tracing span.
114
+ close (workerStarted )
115
+
109
116
recv := MakeDistSQLReceiver (
110
117
ctx ,
111
118
rowWriter ,
@@ -124,13 +131,18 @@ func (n *checkExternalConnectionNode) startExec(params runParams) error {
124
131
return nil
125
132
})
126
133
134
+ // Block until the worker goroutine has started. This allows us to guarantee
135
+ // that params.ctx contains a tracing span that hasn't been finished.
136
+ // TODO(yuzefovich): this is a bit hacky. The issue is that
137
+ // planNodeToRowSource has already created a new tracing span for this
138
+ // checkExternalConnectionNode and has updated params.ctx accordingly; then,
139
+ // if the query is canceled before the worker goroutine starts, the tracing
140
+ // span is finished, yet it will have already been captured by the ctxgroup.
141
+ <- workerStarted
127
142
return nil
128
143
}
129
144
130
145
func (n * checkExternalConnectionNode ) Next (params runParams ) (bool , error ) {
131
- if n .rows == nil {
132
- return false , nil
133
- }
134
146
select {
135
147
case <- params .ctx .Done ():
136
148
return false , params .ctx .Err ()
@@ -149,7 +161,6 @@ func (n *checkExternalConnectionNode) Values() tree.Datums {
149
161
150
162
func (n * checkExternalConnectionNode ) Close (_ context.Context ) {
151
163
_ = n .execGrp .Wait ()
152
- n .rows = nil
153
164
}
154
165
155
166
func (n * checkExternalConnectionNode ) parseParams (params runParams ) error {
0 commit comments