Skip to content

Commit 2a813ac

Browse files
Log execution status/state and fix flaw in cancel logic.
Logging status/state returned by executing a statement. The logic for handling context cancel/timeout was not working correctly in the case where there are no direct results returned from execute statement. Signed-off-by: Raymond Cypher <[email protected]>
1 parent 332b8cb commit 2a813ac

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

connection.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ func (c *conn) executeStatement(ctx context.Context, query string, args []driver
317317
return false
318318
}
319319
hasHandle := resp.OperationHandle != nil
320-
isOpen := resp.DirectResults != nil && resp.DirectResults.CloseOperation == nil
320+
isOpen := resp.DirectResults == nil || resp.DirectResults.CloseOperation == nil
321321
return hasHandle && isOpen
322322
}
323323

internal/client/client.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ func (tsc *ThriftServiceClient) ExecuteStatement(ctx context.Context, req *cli_s
165165
// We use context.Background to fix a problem where on context done the query would not be cancelled.
166166
resp, err := tsc.TCLIServiceClient.ExecuteStatement(context.Background(), req)
167167
log, ctx = LoggerAndContext(ctx, resp)
168+
logExecStatementState(resp, log)
168169
defer log.Duration(msg, start)
169170
if err != nil {
170171
err = handleClientMethodError(ctx, err)
@@ -431,6 +432,20 @@ func guidFromHasSessionHandle(c any) (guid string) {
431432
return
432433
}
433434

435+
func logExecStatementState(resp *cli_service.TExecuteStatementResp, log *logger.DBSQLLogger) {
436+
if resp != nil {
437+
if resp.DirectResults != nil {
438+
state := resp.DirectResults.GetOperationStatus().GetOperationState()
439+
log.Debug().Msgf("execute statement state: %s", state)
440+
status := resp.DirectResults.GetOperationStatus().GetStatus().StatusCode
441+
log.Debug().Msgf("execute statement status: %s", status)
442+
} else {
443+
status := resp.GetStatus().StatusCode
444+
log.Debug().Msgf("execute statement status: %s", status)
445+
}
446+
}
447+
}
448+
434449
var retryableStatusCodes = map[int]any{http.StatusTooManyRequests: struct{}{}, http.StatusServiceUnavailable: struct{}{}}
435450

436451
func isRetryableServerResponse(resp *http.Response) bool {

0 commit comments

Comments
 (0)