JingsongLi commented on code in PR #8219:
URL: https://github.com/apache/paimon/pull/8219#discussion_r3445301688
##########
paimon-api/src/main/java/org/apache/paimon/rest/HttpClientUtils.java:
##########
@@ -86,9 +88,69 @@ private static HttpClientConnectionManager
configureConnectionManager() {
public static InputStream getAsInputStream(String uri) throws IOException {
HttpGet httpGet = new HttpGet(uri);
CloseableHttpResponse response = DEFAULT_HTTP_CLIENT.execute(httpGet);
- if (response.getCode() != 200) {
- throw new RuntimeException("HTTP error code: " +
response.getCode());
+ int statusCode = response.getCode();
+ if (statusCode != HttpStatus.SC_OK) {
+ try {
+ throw httpError(statusCode);
+ } finally {
+ response.close();
+ }
}
return response.getEntity().getContent();
}
+
+ /**
+ * Checks whether an HTTP resource exists. HEAD is attempted first; when
HEAD does not return
+ * 200, a lightweight GET with {@code Range: bytes=0-0} is used to verify
readability. This
+ * avoids treating signed or GET-only URLs as missing when HEAD is
rejected or returns a
+ * different status than GET.
+ */
+ public static boolean exists(String uri) throws IOException {
+ int headStatusCode = headStatusCode(uri);
+ if (headStatusCode == HttpStatus.SC_OK) {
+ return true;
+ }
+ int rangeStatusCode = getRangeStatusCode(uri);
+ if (rangeStatusCode == HttpStatus.SC_OK
Review Comment:
The range fallback still treats a valid empty HTTP resource as an error. If
HEAD is rejected or unavailable, `Range: bytes=0-0` against a zero-length
object commonly returns 416 because the requested range is unsatisfiable, even
though a normal GET would succeed with an empty body. In that case `exists()`
throws here, so Flink writes using `blob-write-null-on-missing-file` can fail
for existing empty HTTP blobs. Could we handle 416 as an existing resource for
this probe (or fall back to a full GET) and add a test with HEAD disabled plus
an empty response?
--
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]