Core: REST catalog commit whose response is lost is reported as a failure, not as an unknown commit state
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 20/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Ferma
- Stack tecnologico
- apache, java
- Ambito
- backend-api-design, databases
Direzione di ricerca
Read HTTPClient.execute, ErrorHandlers.tableCommitHandler(), RESTTableOperations.commit, and RESTSessionCatalog.commitTransaction, then inspect the REST client tests mentioned in the issue. Reproduce a transport failure after a commit is applied and verify that commit requests report an unknown state and trigger reconciliation where supported. An open linked pull request (#18903) indicates work is already underway.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Apache Iceberg version
1.12.0 (latest release)
Query engine
Spark
Please describe the bug 🐞
If the connection fails after a commit request has been sent to a REST catalog (no response, a
connection reset, a read timeout), the Java client reports an ordinary failure:
org.apache.iceberg.exceptions.RESTException: Error occurred while processing POST request
Caused by: org.apache.hc.core5.http.NoHttpResponseException: 127.0.0.1:43911 failed to respond
The server may well have applied the commit. In that case the outcome is unknown, just as for a
5xx response, but the client doesn't say so:
- It is not a
CommitStateUnknownException, so callers have no warning that the commit may have
landed. An application or scheduler that retries the failed operation writes the data twice. RESTTableOperations.commitnever attempts the reconciliation it already does for 5xx
responses, where it reloads the table and checks whether the snapshot it added is there.
For comparison, the same commit answered with a 504 is reconciled: Spark reports success, with one
copy of the data.
Cause
HTTPClient.execute wraps any IOException in a plain RESTException, so a transport failure
never reaches ErrorHandlers.tableCommitHandler(), which maps 500/502/503/504 on a commit to
CommitStateUnknownException. RESTTableOperations already carries a note about this:
// TODO: ensure that the HTTP client lib passes HTTP client errors to the error handler
RESTSessionCatalog.commitTransaction (multi-table transactions) has the same problem.
To reproduce
With Iceberg's own reference catalog (apache/iceberg-rest-fixture) and a small proxy between Spark
and the catalog that forwards one table commit, lets the catalog apply it, and then closes the
connection instead of relaying the response:
"""Forwards HTTP to a REST catalog. After GET /__arm, the next table commit is
forwarded (so the catalog applies it) but its response is never sent: the
connection is closed instead, as a network failure would."""
import http.client, http.server, re, sys, threading
LISTEN, UPSTREAM = int(sys.argv[1]), int(sys.argv[2])
armed = threading.Event()
COMMIT = re.compile(r"/namespaces/[^/]+/tables/[^/]+$")
SKIP = {"host", "connection", "content-length", "transfer-encoding"}
class Handler(http.server.BaseHTTPRequestHandler):
protocol_version = "HTTP/1.1"
def forward(self):
if self.path == "/__arm":
armed.set()
self.send_response(200); self.send_header("Content-Length", "0"); self.end_headers()
return
n = int(self.headers.get("Content-Length") or 0)
body = self.rfile.read(n) if n else None
upstream = http.client.HTTPConnection("127.0.0.1", UPSTREAM)
upstream.request(self.command, self.path, body, {k: v for k, v in self.headers.items() if k.lower() not in SKIP})
resp = upstream.getresponse()
data = resp.read()
if self.command == "POST" and COMMIT.search(self.path.split("?")[0]) and armed.is_set():
armed.clear()
print(f"proxy: catalog answered {resp.status} to POST {self.path}; dropping the connection instead", flush=True)
self.close_connection = True
return
self.send_response(resp.status)
for k, v in resp.getheaders():
if k.lower() not in SKIP:
self.send_header(k, v)
self.send_header("Content-Length", str(len(data)))
self.end_headers()
if self.command != "HEAD":
self.wfile.write(data)
do_GET = do_POST = do_DELETE = do_HEAD = do_PUT = forward
def log_message(self, *args):
pass
http.server.ThreadingHTTPServer(("127.0.0.1", LISTEN), Handler).serve_forever()
docker run -d --network host -e CATALOG_WAREHOUSE=file:///tmp/wh/ -v /tmp/wh:/tmp/wh apache/iceberg-rest-fixture
python3 proxy.py 18291 8181
Then, in Spark 3.5 with iceberg-spark-runtime-3.5_2.12-1.12.0, with catalog via pointing at the
proxy (http://127.0.0.1:18291) and catalog direct at the catalog (http://127.0.0.1:8181):
CREATE NAMESPACE via.x;
CREATE TABLE via.x.t (id bigint) USING iceberg;
INSERT INTO via.x.t VALUES (1);
-- GET http://127.0.0.1:18291/__arm
INSERT INTO via.x.t VALUES (2); -- RESTException: Error occurred while processing POST request
SELECT count(*) FROM direct.x.t WHERE id = 2; -- 1: the commit landed
INSERT INTO via.x.t VALUES (2); -- the obvious retry succeeds
SELECT count(*) FROM direct.x.t WHERE id = 2; -- 2: duplicated
The proxy logs that the catalog answered the dropped commit with a 200.
Other engines and operations behave the same way. Checked with another REST catalog that can inject
the same fault:
| operation | engine reports | did the commit land? |
|---|---|---|
Spark INSERT, catalog answers 504 after applying it |
success (reconciled) | yes, one copy |
Spark INSERT, connection closed after applying it |
RESTException |
yes |
Trino INSERT, connection closed after applying it |
Failed to commit the transaction during insert: Error occurred while processing POST request |
yes |
Trino DELETE, connection closed after applying it |
Failed to commit the transaction during write: Error occurred while processing POST request |
yes |
The same holds for Spark rewrite_data_files, CTAS, CREATE OR REPLACE TABLE … AS SELECT and
DELETE, and Trino CTAS and optimize. In every case the engines kept the data files, so the
tables themselves stay consistent; the risk is a retry.
Related
- #6778 reported this in 2023. It was closed as fixed by #8397 and #8599, which made engines clean up
only after failures markedCleanableFailure. That stopped the data loss: the engines above all
keep their files. But the commit is still reported as an ordinary failure, and still isn't
reconciled, which is what this issue is about. The concern raised there was converting every
IOExceptioninHTTPClient; the fix proposed below applies only to commit requests and keeps a
failure to connect as an ordinary failure. - #12792 hit the same cause in
rewrite_manifests(RESTExceptioncaused by
SocketTimeoutException: Read timed out), and the discussion there agreed anIOExceptionon a
commit should be aCommitStateUnknownException. No fix followed for that part. - #14320 added the reconciliation for 5xx that this would extend to transport failures.
Proposed fix
Report a transport failure on a commit request as CommitStateUnknownException, so that it is
handled like a 5xx: snapshot-add-only commits are reconciled, and anything else is reported as
unknown rather than failed. A ConnectException proves the request was never sent, so it can stay
an ordinary failure. This applies to RESTTableOperations.commit and
RESTSessionCatalog.commitTransaction.
With that change, the Spark INSERT whose connection was closed after the commit reports success
with one copy, the same as for the 504, against both the reference catalog and another REST catalog.
The change applies cleanly to main, where the REST client tests pass.
Willingness to contribute
- I can contribute a fix for this bug independently
- I would be willing to contribute a fix for this bug with guidance from the Iceberg community
- I cannot contribute a fix for this bug at this time
- Lingua principale
- Java
- Stelle
- 9.4k
- Fork
- 3.7k
- Merge medio
- 2g 16h
- PR unite (30g)
- 160
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di apache/iceberg
-
Spark: Test INSERT targets with computed IDENTIFIER expressionsForse già presa @shivadarshan-devadiga l’ha presa 7 giorni fa. Apertaimprovement
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
[Core] TestAvroPartitionStatsHandler fails on Windows due to unclosed partition statistics scanForse già presa @Ankitkj1999 l’ha presa 9 giorni fa. Aperta
Difficoltà 1/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Flink: JdbcLockFactory concurrent lock-table creation can fail with "table already exists" and restart the jobForse già presa @adiranjan25 l’ha presa 16 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
apache/iceberg#18797 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Core: TableMetadata.Builder allows adding encryption keys to v1/v2 tablesForse già presa @yusufyildiz34 l’ha presa 29 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
apache/iceberg#18632 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Kafka: Filter empty strings and whitespace in IcebergSinkConfig stringToListForse già presa @mohamed-elbrik l’ha presa 34 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di apache/iceberg
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
speakeasy-api/speakeasy#2159 ·
I maintainer di solito rispondono entro 1 giorno
-
area: cli
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
vitruv-tools/NeoJoin#415 ·
I maintainer di solito rispondono entro 1 giorno
-
Quick Installation step 2 installs from the plugin manager, but the plugin isn't published yetAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
jenkinsci/user-guide-ai-chatbot-plugin#132 ·
I maintainer di solito rispondono entro 6 giorni
-
account assessment course feature lecture
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
I maintainer di solito rispondono entro 1 giorno
-
[Bug] 连接达梦时报错,agent 进程启动即退Apertabug db/dameng user-priority/P2
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno