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

Improve read session expired error message #1311

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next
* Issue #1290: Stopped using metadata for optimized count path
* PR #1311 : Improve read session expired error message

## 0.41.0 - 2024-09-05

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Multimap;
import io.grpc.Status;
import io.grpc.Status.Code;
import io.grpc.StatusRuntimeException;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -82,6 +83,9 @@ public class BigQueryUtil {
"HTTP/2 error code: INTERNAL_ERROR",
"Connection closed with unknown cause",
"Received unexpected EOS on DATA frame from server");

static final String READ_SESSION_EXPIRED_ERROR_MESSAGE = "session expired at";

private static final String PROJECT_PATTERN = "\\S+";
private static final String DATASET_PATTERN = "\\w+";
// Allow all non-whitespace beside ':' and '.'.
Expand Down Expand Up @@ -118,6 +122,19 @@ static boolean isRetryableInternalError(Throwable t) {
return false;
}

public static boolean isReadSessionExpired(Throwable cause) {
return getCausalChain(cause).stream().anyMatch(BigQueryUtil::isReadSessionExpiredInternalError);
}

static boolean isReadSessionExpiredInternalError(Throwable t) {
if (t instanceof StatusRuntimeException) {
StatusRuntimeException statusRuntimeException = (StatusRuntimeException) t;
return statusRuntimeException.getStatus().getCode() == Code.FAILED_PRECONDITION
&& statusRuntimeException.getMessage().contains(READ_SESSION_EXPIRED_ERROR_MESSAGE);
}
return false;
}

static BigQueryException convertToBigQueryException(BigQueryError error) {
return new BigQueryException(UNKNOWN_CODE, error.getMessage(), error);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,19 @@ public void onError(Throwable t) {
newConnection(this, builder);
retries++;
} else {
stopWithError(t);
if (BigQueryUtil.isReadSessionExpired(t)) {
RuntimeException runtimeException =
new RuntimeException(
"Read session expired after 6 hours. Dataframes on BigQuery tables cannot be "
+ "operated on beyond this time-limit. Your options: "
+ "(1) try finishing within 6 hours, "
+ "(2) use Spark dataframe caching, "
+ "(3) read from a newly created BigQuery dataframe.",
t);
stopWithError(runtimeException);
} else {
stopWithError(t);
}
}
}

Expand Down
Loading