@@ -19,6 +19,7 @@ import (
1919 "github.com/cockroachdb/cockroach/pkg/build"
2020 "github.com/cockroachdb/cockroach/pkg/cmd/roachtest/cluster"
2121 "github.com/cockroachdb/cockroach/pkg/cmd/roachtest/option"
22+ "github.com/cockroachdb/cockroach/pkg/cmd/roachtest/roachtestutil"
2223 "github.com/cockroachdb/cockroach/pkg/cmd/roachtest/test"
2324 "github.com/cockroachdb/cockroach/pkg/roachpb"
2425 "github.com/cockroachdb/cockroach/pkg/roachprod/install"
@@ -156,10 +157,22 @@ func LatestPatchRelease(series string) (*Version, error) {
156157// associated with the given database connection.
157158// NB: version means major.minor[-internal]; the patch level isn't
158159// returned. For example, a binary of version 19.2.4 will return 19.2.
159- func BinaryVersion (ctx context.Context , db * gosql.DB ) (roachpb.Version , error ) {
160+ func BinaryVersion (ctx context.Context , l * logger. Logger , db * gosql.DB ) (roachpb.Version , error ) {
160161 zero := roachpb.Version {}
161162 var sv string
162- if err := db .QueryRowContext (ctx , `SELECT crdb_internal.node_executable_version();` ).Scan (& sv ); err != nil {
163+ rows , err := roachtestutil .QueryWithRetry (
164+ ctx , l , db , roachtestutil .ClusterSettingRetryOpts , `SELECT crdb_internal.node_executable_version();` ,
165+ )
166+ if err != nil {
167+ return zero , err
168+ }
169+ defer rows .Close ()
170+
171+ if ! rows .Next () {
172+ return zero , fmt .Errorf ("no rows returned" )
173+ }
174+
175+ if err := rows .Scan (& sv ); err != nil {
163176 return zero , err
164177 }
165178
@@ -176,10 +189,22 @@ func BinaryVersion(ctx context.Context, db *gosql.DB) (roachpb.Version, error) {
176189// in the background plus gossip asynchronicity.
177190// NB: cluster versions are always major.minor[-internal]; there isn't
178191// a patch level.
179- func ClusterVersion (ctx context.Context , db * gosql.DB ) (roachpb.Version , error ) {
192+ func ClusterVersion (ctx context.Context , l * logger. Logger , db * gosql.DB ) (roachpb.Version , error ) {
180193 zero := roachpb.Version {}
181194 var sv string
182- if err := db .QueryRowContext (ctx , `SHOW CLUSTER SETTING version` ).Scan (& sv ); err != nil {
195+ rows , err := roachtestutil .QueryWithRetry (
196+ ctx , l , db , roachtestutil .ClusterSettingRetryOpts , `SHOW CLUSTER SETTING version` ,
197+ )
198+ if err != nil {
199+ return zero , err
200+ }
201+ defer rows .Close ()
202+
203+ if ! rows .Next () {
204+ return zero , fmt .Errorf ("no rows returned" )
205+ }
206+
207+ if err := rows .Scan (& sv ); err != nil {
183208 return zero , err
184209 }
185210
@@ -477,7 +502,7 @@ func WaitForClusterUpgrade(
477502 timeout time.Duration ,
478503) error {
479504 firstNode := nodes [0 ]
480- newVersion , err := BinaryVersion (ctx , dbFunc (firstNode ))
505+ newVersion , err := BinaryVersion (ctx , l , dbFunc (firstNode ))
481506 if err != nil {
482507 return err
483508 }
@@ -490,7 +515,7 @@ func WaitForClusterUpgrade(
490515 retryCtx , cancel := context .WithTimeout (ctx , timeout )
491516 defer cancel ()
492517 err := opts .Do (retryCtx , func (ctx context.Context ) error {
493- currentVersion , err := ClusterVersion (ctx , dbFunc (node ))
518+ currentVersion , err := ClusterVersion (ctx , l , dbFunc (node ))
494519 if err != nil {
495520 return err
496521 }
0 commit comments