Repository navigation
fix(kernel): honor the CloudFetch connection option #536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
aakash-saravanan-db
merged 21 commits into
main
from
aakash-saravanan_data/fix/cloudfetch-disabled
Nov 13, 2026
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
43c8c79
fix(kernel): honor the CloudFetch connection option
aakash-saravanan-db 315fb64
docs: describe CloudFetch connection support on both backends
aakash-saravanan-db 1b17d10
test(kernel): verify complete results with CloudFetch disabled
aakash-saravanan-db 87c49fc
test(kernel): block storage access in the inline result test
aakash-saravanan-db c7c9345
fix: give the CloudFetch option precedence over legacy result settings
aakash-saravanan-db 52efc7f
test: clarify CloudFetch configuration precedence
aakash-saravanan-db 2577513
test: preserve unsupported result-delivery errors
aakash-saravanan-db 1f1218a
fix: surface conflicting CloudFetch settings during backend recovery
aakash-saravanan-db abf8398
refactor: name the legacy CloudFetch configuration key
aakash-saravanan-db b28e348
test: preserve disabled downloads during backend recovery
aakash-saravanan-db 7356c8d
fix: limit CloudFetch configuration warnings
aakash-saravanan-db ff05afc
docs: explain migration from legacy inline configuration
aakash-saravanan-db 2950a4b
fix: identify overridden CloudFetch configuration keys
aakash-saravanan-db c091a5e
test: cover CloudFetch configuration migration warnings
aakash-saravanan-db 3ef7e85
docs: clarify migration for existing CloudFetch disable options
aakash-saravanan-db 1c5bbb4
fix(kernel): delegate CloudFetch policy to native client configuration
aakash-saravanan-db 5b35361
test: verify the standard disable option without a duplicate client s…
aakash-saravanan-db b4c9ba0
fix(logging): show the forwarded CloudFetch option before session open
aakash-saravanan-db 52b6a88
Clarify CloudFetch option logging and normalize proxy authority
aakash-saravanan-db a50d75a
Keep native option errors and connection docs consistent
aakash-saravanan-db b08ba0c
docs: remove CloudFetch release and validation process notes
aakash-saravanan-db File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 6f4b6d607a61bdde61dcda2cf82bc8e80fd32cb9 | ||
| 0b5d0edfed32c0745d5abc2468fc3070e2eb2a17 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| //go:build cgo && databricks_kernel | ||
|
|
||
| package dbsql | ||
|
|
||
| import ( | ||
| "context" | ||
| "crypto/sha256" | ||
| "crypto/sha512" | ||
| "database/sql" | ||
| "fmt" | ||
| "io" | ||
| "net" | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "strconv" | ||
| "strings" | ||
| "sync/atomic" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestE2EKernelCloudFetchDisabledLargeResults(t *testing.T) { | ||
|
oss-reviewer-bot[bot] marked this conversation as resolved.
Resolved
|
||
| if testing.Short() { | ||
| t.Skip("skipping large inline result in -short mode") | ||
| } | ||
| host, httpPath, token := pecoTestingCreds(t) | ||
| _, workspaceHost := parseHostName(host) | ||
| workspaceAuthority := net.JoinHostPort(workspaceHost, "443") | ||
| var workspaceConnections, blockedConnections atomic.Int64 | ||
| proxy := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| if r.Method != http.MethodConnect || !strings.EqualFold(r.Host, workspaceAuthority) { | ||
| blockedConnections.Add(1) | ||
|
oss-reviewer-bot[bot] marked this conversation as resolved.
Resolved
|
||
| http.Error(w, "Only the SQL workspace is reachable", http.StatusForbidden) | ||
| return | ||
| } | ||
| upstream, err := net.DialTimeout("tcp", r.Host, 10*time.Second) | ||
| if err != nil { | ||
| http.Error(w, "Workspace connection failed", http.StatusBadGateway) | ||
| return | ||
| } | ||
| defer upstream.Close() //nolint:errcheck | ||
| hijacker, ok := w.(http.Hijacker) | ||
| if !ok { | ||
| http.Error(w, "Proxy tunneling is unavailable", http.StatusInternalServerError) | ||
| return | ||
| } | ||
| client, buffered, err := hijacker.Hijack() | ||
| if err != nil { | ||
| return | ||
| } | ||
| defer client.Close() //nolint:errcheck | ||
| workspaceConnections.Add(1) | ||
| _, _ = buffered.WriteString("HTTP/1.1 200 Connection Established\r\n\r\n") | ||
| if err := buffered.Flush(); err != nil { | ||
| return | ||
| } | ||
| go func() { _, _ = io.Copy(upstream, buffered) }() | ||
| _, _ = io.Copy(client, upstream) | ||
| })) | ||
| defer proxy.Close() | ||
| connector, err := NewConnector( | ||
| WithServerHostname(host), WithHTTPPath(httpPath), WithAccessToken(token), | ||
| WithUseKernel(true), WithCloudFetch(false), | ||
| WithKernelProxy(KernelProxy{URL: proxy.URL}), | ||
| WithRetries(-1, time.Millisecond, time.Millisecond), | ||
| ) | ||
| require.NoError(t, err) | ||
| db := sql.OpenDB(connector) | ||
| defer db.Close() //nolint:errcheck | ||
| ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute) | ||
| defer cancel() | ||
| rows, err := db.QueryContext(ctx, "SELECT id, sha2(CAST(id AS STRING), 512) AS payload FROM range(250000) ORDER BY id") | ||
| require.NoError(t, err) | ||
| defer rows.Close() //nolint:errcheck | ||
| var count int64 | ||
| var payloadBytes int | ||
| digest := sha256.New() | ||
| for rows.Next() { | ||
| var id int64 | ||
| var payload string | ||
| require.NoError(t, rows.Scan(&id, &payload)) | ||
| require.Equal(t, count, id) | ||
| require.Equal(t, fmt.Sprintf("%x", sha512.Sum512([]byte(strconv.FormatInt(id, 10)))), payload) | ||
| _, _ = fmt.Fprintf(digest, "%d\t%s\n", id, payload) | ||
| payloadBytes += len(payload) | ||
| count++ | ||
| } | ||
| require.NoError(t, rows.Err()) | ||
| require.Positive(t, workspaceConnections.Load(), "SQL traffic must use the restricted proxy") | ||
| require.Zero(t, blockedConnections.Load(), "no non-workspace connections are allowed") | ||
| require.Equal(t, int64(250000), count) | ||
| require.Equal(t, 32000000, payloadBytes) | ||
| require.Equal(t, "a25ada4c6c476b53e97eb6e8a945e9ce4c14cc432c7ad672dc6fb607d660c86a", fmt.Sprintf("%x", digest.Sum(nil))) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| //go:build cgo && databricks_kernel | ||
|
|
||
| package dbsql | ||
|
|
||
| import ( | ||
| "context" | ||
| "database/sql" | ||
| "encoding/json" | ||
| "fmt" | ||
| "io" | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "strings" | ||
| "sync/atomic" | ||
| "testing" | ||
| "time" | ||
|
|
||
| dbsqlerr "github.com/databricks/databricks-sql-go/errors" | ||
| "github.com/databricks/databricks-sql-go/internal/backend" | ||
| "github.com/databricks/databricks-sql-go/internal/cli_service" | ||
| "github.com/databricks/databricks-sql-go/internal/client" | ||
| "github.com/databricks/databricks-sql-go/internal/config" | ||
| "github.com/databricks/databricks-sql-go/internal/warehouse_cache" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestKernelCloudFetchDisabledPreservesUnsupportedServerError(t *testing.T) { | ||
| for _, automaticRecovery := range []bool{false, true} { | ||
| for _, rejectSession := range []bool{false, true} { | ||
| t.Run(fmt.Sprintf("recovery=%t/session_rejected=%t", automaticRecovery, rejectSession), func(t *testing.T) { | ||
| testKernelCloudFetchDisabledUnsupportedServer(t, automaticRecovery, rejectSession) | ||
| }) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func testKernelCloudFetchDisabledUnsupportedServer(t *testing.T, automaticRecovery, rejectSession bool) { | ||
| t.Helper() | ||
| defer warehouse_cache.ClearCache() | ||
| var sessions atomic.Int64 | ||
| var executions atomic.Int64 | ||
| server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| w.Header().Set("Content-Type", "application/json") | ||
| switch { | ||
| case r.Method == http.MethodPost && strings.HasSuffix(r.URL.Path, "/sessions"): | ||
| sessions.Add(1) | ||
| var body struct { | ||
| SessionConfs map[string]string `json:"session_confs"` | ||
| } | ||
| if err := json.NewDecoder(r.Body).Decode(&body); err != nil || body.SessionConfs["can_cloud_download"] != "false" { | ||
|
oss-reviewer-bot[bot] marked this conversation as resolved.
Resolved
|
||
| http.Error(w, "missing disabled download capability", http.StatusBadRequest) | ||
| return | ||
| } | ||
| for key := range body.SessionConfs { | ||
| if strings.EqualFold(key, "cloudfetch_enabled") || (strings.EqualFold(key, "can_cloud_download") && key != "can_cloud_download") { | ||
| http.Error(w, "conflicting download parameter", http.StatusBadRequest) | ||
| return | ||
| } | ||
| } | ||
| if rejectSession { | ||
| w.WriteHeader(http.StatusBadRequest) | ||
| _, _ = io.WriteString(w, `{"error_code":"CONFIG_NOT_AVAILABLE","message":"Configuration can_cloud_download is not available. SQLSTATE: 42K0I"}`) | ||
| return | ||
| } | ||
| _, _ = io.WriteString(w, `{"session_id":"test-session"}`) | ||
| case r.Method == http.MethodPost && strings.HasSuffix(r.URL.Path, "/statements"): | ||
| executions.Add(1) | ||
| _, _ = io.WriteString(w, `{"statement_id":"unsupported-inline","status":{"state":"FAILED","sql_state":"42K0I","error":{"error_code":"CONFIG_NOT_AVAILABLE","message":"Configuration can_cloud_download is not available"}}}`) | ||
| default: | ||
| _, _ = io.WriteString(w, `{}`) | ||
| } | ||
| })) | ||
| defer server.Close() | ||
| dbConnector, err := NewConnector( | ||
| WithServerHostname(server.URL), WithHTTPPath("/sql/1.0/warehouses/test"), | ||
| WithAccessToken("test-token"), WithUseKernel(true), WithCloudFetch(false), | ||
| WithSessionParams(map[string]string{"CAN_CLOUD_DOWNLOAD": "true"}), | ||
| WithSkipTLSHostVerify(), WithRetries(-1, time.Millisecond, time.Millisecond), | ||
| ) | ||
| require.NoError(t, err) | ||
| var thriftAttempts atomic.Int64 | ||
| if automaticRecovery { | ||
| c := dbConnector.(*connector) | ||
| c.cfg.UseKernel = false | ||
| c.thriftBackendFactory = func(context.Context, *config.Config, *http.Client) (backend.Backend, error) { | ||
| thriftAttempts.Add(1) | ||
| sqlState := "KP001" | ||
| return &fakeThriftBackend{openSessionErr: client.CheckOpenSessionStatus(&cli_service.TOpenSessionResp{ | ||
| Status: &cli_service.TStatus{StatusCode: cli_service.TStatusCode_ERROR_STATUS, SqlState: &sqlState}, | ||
| })}, nil | ||
| } | ||
| } | ||
| db := sql.OpenDB(dbConnector) | ||
| defer db.Close() //nolint:errcheck | ||
| ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) | ||
| defer cancel() | ||
| connection, err := db.Conn(ctx) | ||
| if rejectSession { | ||
| require.Error(t, err) | ||
| require.Contains(t, err.Error(), "CONFIG_NOT_AVAILABLE") | ||
| require.Contains(t, err.Error(), "42K0I") | ||
| require.Equal(t, int64(0), executions.Load()) | ||
| } else { | ||
| require.NoError(t, err) | ||
| defer connection.Close() //nolint:errcheck | ||
| _, err = connection.ExecContext(ctx, "SELECT 1") | ||
| require.Error(t, err) | ||
| var executionError dbsqlerr.DBExecutionError | ||
| require.ErrorAs(t, err, &executionError) | ||
| require.Equal(t, "42K0I", executionError.SqlState()) | ||
| require.Contains(t, err.Error(), "CONFIG_NOT_AVAILABLE") | ||
| require.Equal(t, int64(1), executions.Load(), "unsupported delivery must not fall back") | ||
| } | ||
| require.Equal(t, int64(1), sessions.Load(), "unsupported delivery must not reopen the session") | ||
| if automaticRecovery { | ||
| require.Equal(t, int64(1), thriftAttempts.Load(), "backend recovery must not repeat") | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.