Skip to content

feat(csharp): logging enhancements#28

Draft
davidhcoe wants to merge 7 commits intoadbc-drivers:mainfrom
davidhcoe:dev/parallel-and-logging
Draft

feat(csharp): logging enhancements#28
davidhcoe wants to merge 7 commits intoadbc-drivers:mainfrom
davidhcoe:dev/parallel-and-logging

Conversation

@davidhcoe
Copy link
Copy Markdown
Collaborator

What's Changed

  • Make sub calls in GetColumnsExtendedAsync parallel (although gated a bit by the ThriftClient)
  • Enhance logging
  • Fix bug where StatusCode was causing logging to fail on serialization and not capturing all data

@davidhcoe davidhcoe requested a review from Copilot March 21, 2026 20:07
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves observability and metadata retrieval behavior by adding Activity-based tracing around HiveServer2 metadata operations, parallelizing parts of GetColumnsExtendedAsync, and fixing a logging serialization issue for Thrift status codes.

Changes:

  • Wrap multiple metadata methods with TraceActivityAsync, adding events/tags for richer tracing.
  • Run GetColumnsAsync, GetPrimaryKeysAsync, and FK lookup in parallel inside GetColumnsExtendedAsync.
  • Store Thrift StatusCode as an int tag value to avoid serialization failures.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
csharp/src/Hive2/HiveServer2Statement.cs Adds tracing + parallelizes extended columns metadata retrieval and optimizes relationship processing.
csharp/src/Hive2/HiveServer2Connection.cs Fixes Activity tag serialization by casting StatusCode to int.
csharp/arrow-adbc Updates the Arrow ADBC submodule pointer.
csharp/Directory.Packages.props Bumps Microsoft.NET.Test.Sdk version.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +745 to +752
// 1. Launch all three independent metadata calls in parallel
activity?.AddEvent("hive2.statement.get_columns_extended.launching_parallel_calls");
var columnsTask = GetColumnsAsync(cancellationToken);
var pkTask = GetPrimaryKeysAsync(cancellationToken);
// For FK lookup, we need to pass in the current catalog/schema/table as the foreign table
var fkTask = GetCrossReferenceAsForeignTableAsync(cancellationToken);

await Task.WhenAll(columnsTask, pkTask, fkTask).ConfigureAwait(false);
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running these metadata calls in parallel can concurrently use the same underlying Connection / Thrift client. If the Thrift client or connection pipeline is not explicitly thread-safe for concurrent requests, this can cause intermittent protocol errors or corrupted responses. A robust approach is to enforce a connection-level async lock (e.g., SemaphoreSlim) around Thrift invocations, or to make parallelism conditional (feature flag / capability check) so callers can opt out when using non-concurrent transports.

Copilot uses AI. Check for mistakes.
David Coe and others added 2 commits March 21, 2026 16:27
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@birschick-bq
Copy link
Copy Markdown
Collaborator

@davidhcoe

I was adding a test for GetColumnsExtendedHive and found it is throwing some exceptions that seem related to the issue of trying to use the Thrift transport object for concurrent calls: Using THttpTransport using interleaved asynchronous calls may throw exception

AdbcDrivers.HiveServer2.Hive2.HiveServer2Exception : An unexpected error occurred while fetching results. 'One or more errors occurred. (Couldn't connect to server: System.Net.Http.HttpRequestException: Sent 0 request content bytes, but Content-Length promised 294.
   at System.Net.Http.HttpConnection.SendRequestContentAsync(HttpRequestMessage request, HttpContentWriteStream stream, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnection.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnection.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.DiagnosticsHandler.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.DecompressionHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
   at Thrift.Transport.Client.THttpTransport.FlushAsync(CancellationToken cancellationToken)): (1) Couldn't connect to server: System.Net.Http.HttpRequestException: Sent 0 request content bytes, but Content-Length promised 294.
   at System.Net.Http.HttpConnection.SendRequestContentAsync(HttpRequestMessage request, HttpContentWriteStream stream, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnection.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnection.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.DiagnosticsHandler.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.DecompressionHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
   at Thrift.Transport.Client.THttpTransport.FlushAsync(CancellationToken cancellationToken)'
---- System.AggregateException : One or more errors occurred. (Couldn't connect to server: System.Net.Http.HttpRequestException: Sent 0 request content bytes, but Content-Length promised 294.
   at System.Net.Http.HttpConnection.SendRequestContentAsync(HttpRequestMessage request, HttpContentWriteStream stream, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnection.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnection.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.DiagnosticsHandler.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.DecompressionHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
   at Thrift.Transport.Client.THttpTransport.FlushAsync(CancellationToken cancellationToken))
-------- Thrift.Transport.TTransportException : Couldn't connect to server: System.Net.Http.HttpRequestException: Sent 0 request content bytes, but Content-Length promised 294.
   at System.Net.Http.HttpConnection.SendRequestContentAsync(HttpRequestMessage request, HttpContentWriteStream stream, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnection.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnection.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.DiagnosticsHandler.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.DecompressionHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
   at Thrift.Transport.Client.THttpTransport.FlushAsync(CancellationToken cancellationToken)
------------ System.Net.Http.HttpRequestException : Sent 0 request content bytes, but Content-Length promised 294.

@davidhcoe
Copy link
Copy Markdown
Collaborator Author

Well, that's disappointing. I recall the issue, but I didn't face it in my testing I was doing. I guess I need to remove the Task.WhenAll logic.

@davidhcoe davidhcoe marked this pull request as draft March 27, 2026 02:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants