@@ -9,17 +9,17 @@ import (
9
9
"encoding/json"
10
10
"fmt"
11
11
"io"
12
+ "math/rand"
12
13
"mime/multipart"
13
14
"net"
14
15
"net/http"
15
16
"strings"
16
17
"time"
17
18
18
- "github.com/google/uuid"
19
- "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
20
-
21
19
"github.com/avast/retry-go"
20
+ "github.com/google/uuid"
22
21
"github.com/pkg/errors"
22
+ "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
23
23
)
24
24
25
25
type AuthMethod string
@@ -178,6 +178,7 @@ func NewAPIClientFromConfig(cfg *Config) *APIClient {
178
178
password : cfg .Password ,
179
179
sessionState : & sessionState ,
180
180
sessionStateRaw : & sessionStateRaw ,
181
+ routeHint : randRouteHint (),
181
182
182
183
accessTokenLoader : initAccessTokenLoader (cfg ),
183
184
statsTracker : cfg .StatsTracker ,
@@ -476,7 +477,7 @@ func (c *APIClient) startQueryRequest(ctx context.Context, request *QueryRequest
476
477
// fmt.Printf("start query %v %v\n", c.GetQueryID(), request.SQL)
477
478
478
479
if ! c .inActiveTransaction () {
479
- c .routeHint = ""
480
+ c .routeHint = randRouteHint ()
480
481
}
481
482
482
483
path := "/v1/query"
@@ -498,7 +499,7 @@ func (c *APIClient) startQueryRequest(ctx context.Context, request *QueryRequest
498
499
// e.g. transaction state need to be updated if commit fail
499
500
c .applySessionState (& resp )
500
501
// save route hint for the next following http requests
501
- if len (respHeaders ) > 0 {
502
+ if len (respHeaders ) > 0 && len ( respHeaders . Get ( DatabendRouteHintHeader )) > 0 {
502
503
c .routeHint = respHeaders .Get (DatabendRouteHintHeader )
503
504
}
504
505
return & resp , nil
@@ -720,3 +721,12 @@ func (c *APIClient) UploadToStageByAPI(ctx context.Context, stage *StageLocation
720
721
721
722
return nil
722
723
}
724
+
725
+ func randRouteHint () string {
726
+ charset := "abcdef0123456789"
727
+ b := make ([]byte , 16 )
728
+ for i := range b {
729
+ b [i ] = charset [rand .Intn (len (charset ))]
730
+ }
731
+ return string (b )
732
+ }
0 commit comments