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 madisonchamberlain committed Feb 8, 2023
1 parent 371f4e9 commit ae2d378
Show file tree
Hide file tree
Showing 5 changed files with 243 additions and 79 deletions.
10 changes: 10 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 @@ -228,6 +229,9 @@ func (sc *snowflakeConn) cleanup() {
}
sc.rest = nil
sc.cfg = nil

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

func (sc *snowflakeConn) Close() (err error) {
Expand Down Expand Up @@ -504,6 +508,12 @@ func buildSnowflakeConn(ctx context.Context, config Config) (*snowflakeConn, err
} else {
tokenAccessor = getSimpleTokenAccessor()
}
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
11 changes: 11 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 @@ -87,6 +89,9 @@ type Config struct {
IDToken string // Internally used to cache the Id Token for external browser
ClientRequestMfaToken ConfigBool // When true the MFA token is cached in the credential manager. True by default in Windows/OSX. False for Linux.
ClientStoreTemporaryCredential ConfigBool // When true the ID token is cached in the credential manager. True by default in Windows/OSX. False for Linux.
// 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 @@ -211,6 +216,8 @@ func DSN(cfg *Config) (dsn string, err error) {

if cfg.ClientStoreTemporaryCredential != configBoolNotSet {
params.Add("clientStoreTemporaryCredential", strconv.FormatBool(cfg.ClientStoreTemporaryCredential != 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)
Expand Down Expand Up @@ -437,6 +444,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
Loading

0 comments on commit ae2d378

Please sign in to comment.