Skip to content
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

[SPARK-44835][CONNECT] Make INVALID_CURSOR.DISCONNECTED a retriable error #42818

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,23 @@ private[sql] object GrpcRetryHandler extends Logging {
*/
private[client] def retryException(e: Throwable): Boolean = {
e match {
case e: StatusRuntimeException => e.getStatus.getCode == Status.Code.UNAVAILABLE
case e: StatusRuntimeException =>
val statusCode: Status.Code = e.getStatus.getCode

if (List(Status.Code.INTERNAL)
juliuszsompolski marked this conversation as resolved.
Show resolved Hide resolved
.contains(statusCode)) {
val msg: String = e.toString

// This error happens if another RPC preempts this RPC.
if (msg.contains("INVALID_CURSOR.DISCONNECTED")) {
return true
}
}

if (statusCode == Status.Code.UNAVAILABLE) {
return true
}
false
case _ => false
}
}
Expand Down
31 changes: 28 additions & 3 deletions python/pyspark/sql/connect/client/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,11 +585,36 @@ class SparkConnectClient(object):

@classmethod
def retry_exception(cls, e: Exception) -> bool:
if isinstance(e, grpc.RpcError):
return e.code() == grpc.StatusCode.UNAVAILABLE
else:
"""
Helper function that is used to identify if an exception thrown by the server
can be retried or not.

Parameters
----------
e : Exception
The GRPC error as received from the server. Typed as Exception, because other exception
thrown during client processing can be passed here as well.

Returns
-------
True if the exception can be retried, False otherwise.

"""
if not isinstance(e, grpc.RpcError):
return False

if e.code() in [grpc.StatusCode.INTERNAL]:
msg = str(e)

# This error happens if another RPC preempts this RPC.
if "INVALID_CURSOR.DISCONNECTED" in msg:
return True

if e.code() == grpc.StatusCode.UNAVAILABLE:
return True

return False

def __init__(
self,
connection: Union[str, ChannelBuilder],
Expand Down