Skip to content

Commit

Permalink
SNOW-894815 Fix access to params from htap
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-pfus committed Oct 16, 2023
1 parent 3a29554 commit 77d1785
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 8 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:
env:
PARAMETERS_SECRET: ${{ secrets.PARAMETERS_SECRET }}
CLOUD_PROVIDER: ${{ matrix.cloud }}
GORACE: history_size=7
run: ./ci/test.sh
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
Expand Down
3 changes: 2 additions & 1 deletion chunk_downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ func (r *largeResultSetReader) Read(p []byte) (n int, err error) {
}

func downloadChunk(ctx context.Context, scd *snowflakeChunkDownloader, idx int) {
logger.Infof("download start chunk: %v", idx+1)
logger.Infof("download start chunk: %v (goid: %v, sc: %p, cfg: %p)", idx+1, safeGoid(), scd.sc, scd.sc.cfg)
defer logger.Infof("downloaded chunk %v finished (goid: %v, sc: %p, cfg: %p)", idx+1, safeGoid(), scd.sc, scd.sc.cfg)
defer scd.DoneDownloadCond.Broadcast()

if err := scd.FuncDownloadHelper(ctx, scd, idx); err != nil {
Expand Down
41 changes: 41 additions & 0 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ import (
"database/sql/driver"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"net/url"
"os"
"regexp"
"runtime"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -243,7 +246,45 @@ func (sc *snowflakeConn) BeginTx(
return &snowflakeTx{sc, ctx}, nil
}

var (
goroutinePrefix = []byte("goroutine ")
errBadStack = errors.New("invalid runtime.Stack output")
)

func goid() (int, error) {
buf := make([]byte, 32)
n := runtime.Stack(buf, false)
buf = buf[:n]
// goroutine 1 [running]: ...

buf, ok := bytes.CutPrefix(buf, goroutinePrefix)

Check failure on line 260 in connection.go

View workflow job for this annotation

GitHub Actions / GCP Go 1.19 on Ubuntu

undefined: bytes.CutPrefix (compile)

Check failure on line 260 in connection.go

View workflow job for this annotation

GitHub Actions / GCP Go 1.19 on Ubuntu

undefined: bytes.CutPrefix (compile)

Check failure on line 260 in connection.go

View workflow job for this annotation

GitHub Actions / AWS Go 1.19 on Ubuntu

undefined: bytes.CutPrefix (compile)

Check failure on line 260 in connection.go

View workflow job for this annotation

GitHub Actions / AWS Go 1.19 on Ubuntu

undefined: bytes.CutPrefix (compile)

Check failure on line 260 in connection.go

View workflow job for this annotation

GitHub Actions / AWS Go 1.19 on Mac

undefined: bytes.CutPrefix (compile)

Check failure on line 260 in connection.go

View workflow job for this annotation

GitHub Actions / AWS Go 1.19 on Mac

undefined: bytes.CutPrefix (compile)

Check failure on line 260 in connection.go

View workflow job for this annotation

GitHub Actions / AZURE Go 1.19 on Ubuntu

undefined: bytes.CutPrefix (compile)

Check failure on line 260 in connection.go

View workflow job for this annotation

GitHub Actions / AZURE Go 1.19 on Ubuntu

undefined: bytes.CutPrefix (compile)

Check failure on line 260 in connection.go

View workflow job for this annotation

GitHub Actions / AZURE Go 1.19 on Mac

undefined: bytes.CutPrefix (compile)

Check failure on line 260 in connection.go

View workflow job for this annotation

GitHub Actions / AZURE Go 1.19 on Mac

undefined: bytes.CutPrefix (compile)

Check failure on line 260 in connection.go

View workflow job for this annotation

GitHub Actions / GCP Go 1.19 on Mac

undefined: bytes.CutPrefix (compile)

Check failure on line 260 in connection.go

View workflow job for this annotation

GitHub Actions / GCP Go 1.19 on Mac

undefined: bytes.CutPrefix (compile)

Check failure on line 260 in connection.go

View workflow job for this annotation

GitHub Actions / GCP Go 1.19 on Windows

undefined: bytes.CutPrefix

Check failure on line 260 in connection.go

View workflow job for this annotation

GitHub Actions / GCP Go 1.19 on Windows

undefined: bytes.CutPrefix

Check failure on line 260 in connection.go

View workflow job for this annotation

GitHub Actions / GCP Go 1.19 on Windows

undefined: bytes.CutPrefix

Check failure on line 260 in connection.go

View workflow job for this annotation

GitHub Actions / GCP Go 1.19 on Windows

undefined: bytes.CutPrefix

Check failure on line 260 in connection.go

View workflow job for this annotation

GitHub Actions / GCP Go 1.19 on Windows

undefined: bytes.CutPrefix

Check failure on line 260 in connection.go

View workflow job for this annotation

GitHub Actions / GCP Go 1.19 on Windows

undefined: bytes.CutPrefix

Check failure on line 260 in connection.go

View workflow job for this annotation

GitHub Actions / GCP Go 1.19 on Windows

undefined: bytes.CutPrefix

Check failure on line 260 in connection.go

View workflow job for this annotation

GitHub Actions / GCP Go 1.19 on Windows

undefined: bytes.CutPrefix

Check failure on line 260 in connection.go

View workflow job for this annotation

GitHub Actions / AZURE Go 1.19 on Windows

undefined: bytes.CutPrefix

Check failure on line 260 in connection.go

View workflow job for this annotation

GitHub Actions / AZURE Go 1.19 on Windows

undefined: bytes.CutPrefix

Check failure on line 260 in connection.go

View workflow job for this annotation

GitHub Actions / AZURE Go 1.19 on Windows

undefined: bytes.CutPrefix

Check failure on line 260 in connection.go

View workflow job for this annotation

GitHub Actions / AZURE Go 1.19 on Windows

undefined: bytes.CutPrefix

Check failure on line 260 in connection.go

View workflow job for this annotation

GitHub Actions / AZURE Go 1.19 on Windows

undefined: bytes.CutPrefix

Check failure on line 260 in connection.go

View workflow job for this annotation

GitHub Actions / AZURE Go 1.19 on Windows

undefined: bytes.CutPrefix

Check failure on line 260 in connection.go

View workflow job for this annotation

GitHub Actions / AZURE Go 1.19 on Windows

undefined: bytes.CutPrefix

Check failure on line 260 in connection.go

View workflow job for this annotation

GitHub Actions / AZURE Go 1.19 on Windows

undefined: bytes.CutPrefix

Check failure on line 260 in connection.go

View workflow job for this annotation

GitHub Actions / AWS Go 1.19 on Windows

undefined: bytes.CutPrefix

Check failure on line 260 in connection.go

View workflow job for this annotation

GitHub Actions / AWS Go 1.19 on Windows

undefined: bytes.CutPrefix

Check failure on line 260 in connection.go

View workflow job for this annotation

GitHub Actions / AWS Go 1.19 on Windows

undefined: bytes.CutPrefix

Check failure on line 260 in connection.go

View workflow job for this annotation

GitHub Actions / AWS Go 1.19 on Windows

undefined: bytes.CutPrefix

Check failure on line 260 in connection.go

View workflow job for this annotation

GitHub Actions / AWS Go 1.19 on Windows

undefined: bytes.CutPrefix

Check failure on line 260 in connection.go

View workflow job for this annotation

GitHub Actions / AWS Go 1.19 on Windows

undefined: bytes.CutPrefix

Check failure on line 260 in connection.go

View workflow job for this annotation

GitHub Actions / AWS Go 1.19 on Windows

undefined: bytes.CutPrefix

Check failure on line 260 in connection.go

View workflow job for this annotation

GitHub Actions / AWS Go 1.19 on Windows

undefined: bytes.CutPrefix
if !ok {
return 0, errBadStack
}

i := bytes.IndexByte(buf, ' ')
if i < 0 {
return 0, errBadStack
}

return strconv.Atoi(string(buf[:i]))
}

func safeGoid() int {
id, err := goid()
if err != nil {
println("failed to get goroutine, %v", err)
}
return id
}

func (sc *snowflakeConn) cleanup() {
id, err := goid()
if err == nil {
fmt.Printf("cleanup, goroutine id = %v, sc: %p, cfg: %p", id, sc, sc.cfg)
} else {
println("failed to get goroutine, ", err)
}
// must flush log buffer while the process is running.
if sc.rest != nil && sc.rest.Client != nil {
sc.rest.Client.CloseIdleConnections()
Expand Down
9 changes: 3 additions & 6 deletions connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,13 +476,11 @@ func TestExecWithServerSideError(t *testing.T) {
}

func TestConcurrentReadOnParams(t *testing.T) {
t.Skip("Fails randomly")
config, err := ParseDSN(dsn)
db, err := sql.Open("snowflake", dsn)
if err != nil {
t.Fatal("Failed to parse dsn")
t.Fatalf("Error while opening connection: %v", err)
}
connector := NewConnector(SnowflakeDriver{}, *config)
db := sql.OpenDB(connector)
defer db.Close()
wg := sync.WaitGroup{}
for i := 0; i < 10; i++ {
wg.Add(1)
Expand All @@ -505,7 +503,6 @@ func TestConcurrentReadOnParams(t *testing.T) {
}()
}
wg.Wait()
defer db.Close()
}

func postQueryTest(_ context.Context, _ *snowflakeRestful, _ *url.Values, headers map[string]string, _ []byte, _ time.Duration, _ UUID, _ *Config) (*execResponse, error) {
Expand Down
2 changes: 1 addition & 1 deletion driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ var logger = CreateDefaultLogger()

func init() {
sql.Register("snowflake", &SnowflakeDriver{})
logger.SetLogLevel("error")
logger.SetLogLevel("info")
if runningOnGithubAction() {
logger.SetLogLevel("fatal")
}
Expand Down

0 comments on commit 77d1785

Please sign in to comment.