CurtHagenlocher commented on code in PR #3302:
URL: https://github.com/apache/arrow-adbc/pull/3302#discussion_r2291683248
##########
csharp/src/Drivers/Apache/Hive2/HiveServer2Statement.cs:
##########
@@ -52,6 +53,10 @@ internal class HiveServer2Statement : TracingStatement,
IHiveServer2Statement
protected const string PrimaryKeyPrefix = "PK_";
protected const string ForeignKeyPrefix = "FK_";
+ // Lock to ensure consistent access to TokenSource and OperationHandle
Review Comment:
nit: this comment is misleading insofar as the lock does not appear to be
directly related to `OperationHandle` access.
##########
csharp/src/Drivers/Apache/Hive2/HiveServer2Statement.cs:
##########
@@ -1006,5 +1028,72 @@ public bool TryGetDirectResults(IResponse response, out
TSparkDirectResults? dir
directResults = null;
return false;
}
+
+ /// <inheritdoc/>
+ public override void Cancel()
+ {
+ this.TraceActivity(_ =>
+ {
+ // This will cancel any operation using the current token
source
+ CancelTokenSource();
+ });
+ }
+
+ private async Task CancelOperationAsync(Activity? activity,
TOperationHandle? operationHandle)
+ {
+ if (operationHandle == null)
+ {
+ return;
+ }
+ using CancellationTokenSource cancellationTokenSource =
ApacheUtility.GetCancellationTokenSource(QueryTimeoutSeconds,
ApacheUtility.TimeUnit.Seconds);
+ try
+ {
+ activity?.AddEvent(
+ "db.operation.cancel_operation.starting",
+ [new(SemanticConventions.Db.Operation.OperationId, new
Guid(operationHandle.OperationId.Guid).ToString("N"))]);
+ TCancelOperationReq req = new(operationHandle);
+ TCancelOperationResp resp = await Client.CancelOperation(req,
cancellationTokenSource.Token);
+ HiveServer2Connection.HandleThriftResponse(resp.Status,
activity);
+ activity?.AddEvent(
+ "db.operation.cancel_operation.completed",
+ [new(SemanticConventions.Db.Response.StatusCode,
resp.Status.StatusCode.ToString())]);
+ }
+ catch (Exception ex)
+ {
+ activity?.AddException(ex);
+ }
+ }
+
+ private CancellationTokenSource SetTokenSource()
+ {
+ lock (_tokenSourceLock)
+ {
+ _executeTokenSource?.Dispose();
Review Comment:
Should this throw an exception if `_executeTokenSource` is non-null? We
don't support executing two simultaneous queries against the same statement, do
we?
##########
csharp/src/Drivers/Apache/ApacheUtility.cs:
##########
@@ -33,7 +33,21 @@ public enum TimeUnit
Milliseconds
}
+ public static CancellationTokenSource GetCancellationTokenSource(int
timeout, TimeUnit timeUnit)
+ {
+ TimeSpan timeSpan = CalculateTimeSpan(timeout, timeUnit);
+ return new CancellationTokenSource(timeSpan);
+
Review Comment:
nit: extra blank line
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]