Skip to content

Commit

Permalink
[Feature] add a cache to the FetchResult codepath to avoid API calls (#…
Browse files Browse the repository at this point in the history
…45)

lint: fix `ConnectionId`

Fix CI for current master (#47)

* lint: fix `ConnectionId`

* Test fixes for previous change (`41c90a09`)

* nit: tweaks to dsn-test

Co-authored-by: Agam Brahma <agam@sigmacomputing.com>

fix var inits (#46)
  • Loading branch information
mhseiden authored and Agam Brahma committed Jun 8, 2022
1 parent f004e09 commit 294bd4d
Show file tree
Hide file tree
Showing 5 changed files with 243 additions and 79 deletions.
7 changes: 7 additions & 0 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type snowflakeConn struct {
SQLState string
telemetry *snowflakeTelemetry
internal InternalClient
execRespCache *execRespCache
}

var (
Expand Down Expand Up @@ -223,6 +224,9 @@ func (sc *snowflakeConn) cleanup() {
// must flush log buffer while the process is running.
sc.rest = nil
sc.cfg = nil

releaseExecRespCache(sc.execRespCache)
sc.execRespCache = nil
}

func (sc *snowflakeConn) Close() (err error) {
Expand Down Expand Up @@ -502,6 +506,9 @@ func buildSnowflakeConn(ctx context.Context, config Config) (*snowflakeConn, err
if sc.cfg.DisableTelemetry {
sc.telemetry = &snowflakeTelemetry{enabled: false}
}
if sc.cfg.ConnectionID != "" {
sc.execRespCache = acquireExecRespCache(sc.cfg.ConnectionID)
}

// authenticate
sc.rest = &snowflakeRestful{
Expand Down
14 changes: 14 additions & 0 deletions dsn.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"strconv"
"strings"
"time"

"github.com/google/uuid"
)

const (
Expand Down Expand Up @@ -80,6 +82,10 @@ type Config struct {
Transporter http.RoundTripper // RoundTripper to intercept HTTP requests and responses

DisableTelemetry bool // indicates whether to disable telemetry

// An identifier for this Config. Used to associate multiple connection instances with
// a single logical sql.DB connection.
ConnectionID string
}

// ocspMode returns the OCSP mode in string INSECURE, FAIL_OPEN, FAIL_CLOSED
Expand Down Expand Up @@ -195,6 +201,10 @@ func DSN(cfg *Config) (dsn string, err error) {

params.Add("validateDefaultParameters", strconv.FormatBool(cfg.ValidateDefaultParameters != ConfigBoolFalse))

if cfg.ConnectionID != "" {
params.Add("connectionId", cfg.ConnectionID)
}

dsn = fmt.Sprintf("%v:%v@%v:%v", url.QueryEscape(cfg.User), url.QueryEscape(cfg.Password), cfg.Host, cfg.Port)
if params.Encode() != "" {
dsn += "?" + params.Encode()
Expand Down Expand Up @@ -419,6 +429,10 @@ func fillMissingConfigParameters(cfg *Config) error {
cfg.ValidateDefaultParameters = ConfigBoolTrue
}

if cfg.ConnectionID == "" {
cfg.ConnectionID = uuid.New().String()
}

if strings.HasSuffix(cfg.Host, defaultDomain) && len(cfg.Host) == len(defaultDomain) {
return &SnowflakeError{
Number: ErrCodeFailedToParseHost,
Expand Down

0 comments on commit 294bd4d

Please sign in to comment.