gardenia commented on code in PR #18903:
URL: https://github.com/apache/iceberg/pull/18903#discussion_r4727461648
##########
core/src/main/java/org/apache/iceberg/rest/RESTTableOperations.java:
##########
@@ -240,6 +252,38 @@ public void commit(TableMetadata base, TableMetadata
metadata) {
updateCurrentMetadata(response);
}
+ /**
+ * Sends a commit request, reporting a transport failure as an unknown
commit state.
+ *
+ * <p>If the connection fails once the request may have been sent (no
response, a reset, a read
+ * timeout), the server may have applied the commit, so the outcome is
unknown just as for a 5xx
+ * response. Failures that happen before anything is sent stay ordinary
failures. Any other
+ * transport failure is treated as unknown: reporting a commit that was
applied as failed invites
+ * a retry that applies it twice, while reporting one that wasn't as unknown
at worst leaves
+ * orphan files.
+ */
+ static <T> T commitRequest(Supplier<T> request) {
+ try {
+ return request.get();
+ } catch (RESTException e) {
+ if (e.getCause() instanceof IOException &&
!failedBeforeSending(e.getCause())) {
Review Comment:
@timothyw553 - Good catch, that case wasn't handled. The same applied to a
keyed POST that got a 503, was retried, and then had the connection refused.
I've moved the tracking into `HTTPClient` as you suggested. It now uses an
HttpClient interceptor that tracks how each attempt ended, so if any attempt
may have reached the server, the final error says so, whatever happened on the
last try. `RESTTableOperations` then only has to turn that into a
`CommitStateUnknownException`, without digging through exception causes.
I added real `HTTPClient` tests for a lost keyed-POST reply followed by
connection refusal, a 503 followed by connection refusal, a read timeout, a
malformed response, and a refused first attempt (which stays an ordinary
failure).
@developer-rpai this also moves the "never sent" checks into HTTPClient,
including the two HttpClient 5 ones. That's the follow-up we discussed, but it
made more sense to do it here given @timothyw553's suggestion. It's a bit
different from the version you approved, so worth another look if you have time.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]