Repository navigation
Complete native Volume transfers for ExecContext #560
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
base: main
Are you sure you want to change the base?
Changes from all commits
5b07a0f
9af910f
3cd1040
26f142a
f0c6f41
3629843
809e8e6
f62f469
35a41a6
71a4ad8
362f762
855cca1
4393f2a
0f849de
6218f29
513f8e7
886f7ee
21ca49b
74d74f9
0f9be07
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 0b5d0edfed32c0745d5abc2468fc3070e2eb2a17 | ||
| d9fcf834d36dc7f3de1621225db716200151fa0f |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ import "C" | |
| import ( | ||
| "context" | ||
| "database/sql/driver" | ||
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
| "sync" | ||
|
|
@@ -35,8 +36,7 @@ import ( | |
| // client-timeout path, let an in-flight cancel finish in the background so | ||
| // it cannot extend the client deadline | ||
| // | ||
| // Binds any query parameters (bindParams) before executing; staging statements | ||
| // are rejected up front by Execute, so none reach here. | ||
| // Binds any query parameters (bindParams) before executing. | ||
| func (k *KernelBackend) execute(ctx context.Context, req backend.ExecRequest) (backend.Operation, error) { | ||
| // Log the SQL length, not the text: query bodies can carry PII/secrets in | ||
| // WHERE/INSERT/SET, and this goes to stderr. Matches the driver's own | ||
|
|
@@ -384,11 +384,70 @@ func (o *kernelOp) Results(ctx context.Context, callbacks *dbsqlrows.TelemetryCa | |
| return newKernelRows(ctx, o, stream, callbacks) | ||
| } | ||
|
|
||
| // IsStaging reports whether this is a staging (PUT/GET/REMOVE) operation. Always | ||
| // false on the kernel path: staging statements are rejected up front in | ||
| // Execute (isStagingStatement), so no kernelOp is ever produced for one — there | ||
| // is nothing for conn.execStagingOperation to act on here. | ||
| func (o *kernelOp) IsStaging(ctx context.Context) (bool, error) { return false, nil } | ||
| func (o *kernelOp) IsStaging(ctx context.Context) (bool, error) { | ||
| if o.exec == nil { | ||
| return false, nil | ||
| } | ||
| var marked C.bool | ||
| err := call(func() C.KernelStatusCode { | ||
| return C.kernel_executed_statement_is_volume_operation(o.exec, &marked) | ||
| }) | ||
| return bool(marked), err | ||
| } | ||
|
|
||
| func (o *kernelOp) CompleteStaging(ctx context.Context) error { | ||
| if err := ctx.Err(); err != nil { | ||
| return err | ||
| } | ||
| var stream *C.kernel_result_stream_t | ||
| if err := call(func() C.KernelStatusCode { | ||
| return C.kernel_executed_statement_get_result_stream(o.exec, &stream) | ||
|
peco-review-bot[bot] marked this conversation as resolved.
Resolved
peco-review-bot[bot] marked this conversation as resolved.
Resolved
peco-review-bot[bot] marked this conversation as resolved.
Resolved
|
||
| }); err != nil { | ||
|
peco-review-bot[bot] marked this conversation as resolved.
Resolved
peco-review-bot[bot] marked this conversation as resolved.
Resolved
|
||
| return toStatementError(err) | ||
|
peco-review-bot[bot] marked this conversation as resolved.
Resolved
peco-review-bot[bot] marked this conversation as resolved.
Resolved
peco-review-bot[bot] marked this conversation as resolved.
Resolved
peco-review-bot[bot] marked this conversation as resolved.
Resolved
peco-review-bot[bot] marked this conversation as resolved.
Resolved
peco-review-bot[bot] marked this conversation as resolved.
Resolved
|
||
| } | ||
|
peco-review-bot[bot] marked this conversation as resolved.
Resolved
peco-review-bot[bot] marked this conversation as resolved.
Resolved
peco-review-bot[bot] marked this conversation as resolved.
Resolved
|
||
| defer C.kernel_result_stream_close(stream) | ||
| var canceller *C.kernel_result_stream_canceller_t | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 Low — |
||
| if err := call(func() C.KernelStatusCode { | ||
| return C.kernel_result_stream_canceller_new(stream, &canceller) | ||
| }); err != nil { | ||
| return toStatementError(err) | ||
| } | ||
| defer C.kernel_result_stream_canceller_free(canceller) | ||
| done, stopped := make(chan struct{}), make(chan struct{}) | ||
| go func() { | ||
| defer close(stopped) | ||
| select { | ||
| case <-ctx.Done(): | ||
| C.kernel_result_stream_canceller_cancel(canceller) | ||
| case <-done: | ||
| } | ||
| }() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 Low —
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I checked the reachable error sources before adding eviction. kernel_executed_statement_get_result_stream only validates/takes the existing synchronous stream ( Completion can encounter both result transport and presigned-storage failures. Their shared kernel error codes do not establish that the SQL session is dead; applying evictIfSessionFatal indiscriminately could discard a healthy SQL connection on a storage authentication/permission failure. I have not found a demonstrated session-origin failure requiring a change here. No message-prefix classifier or new error-origin framework was added for this hypothetical case. The native source pin is updated to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right about |
||
| defer func() { close(done); <-stopped }() | ||
| encoded, err := json.Marshal(driverctx.StagingPathsFromContext(ctx)) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| paths := newCStr(string(encoded)) | ||
| defer paths.free() | ||
| var outcome C.int32_t | ||
| err = call(func() C.KernelStatusCode { | ||
| return C.kernel_result_stream_complete_volume_operation(stream, paths.c, true, &outcome) | ||
| }) | ||
| if err != nil { | ||
| var ke *KernelError | ||
| if !errors.As(err, &ke) || (ke.ErrorCode != "VOLUME_STORAGE_HTTP_ERROR" && ke.ErrorCode != "VOLUME_STORAGE_NETWORK_ERROR") { | ||
| o.backend.evictIfSessionFatal(err) | ||
| } | ||
| if ctx.Err() != nil { | ||
| return fmt.Errorf("kernel: volume transfer cancelled: %w (kernel error: %w)", ctx.Err(), toStatementError(err)) | ||
| } | ||
| return toStatementError(err) | ||
| } | ||
| if outcome != 2 { | ||
| return errors.New("kernel: volume operation requires a local file instruction") | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // Close best-effort closes the executed statement and its statement handle. It is | ||
| // idempotent (a second call, or a call after Rows.Close already tore the | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.