Core: REST catalog commit whose response is lost is reported as a failure, not as an unknown commit state
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 20/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Estancado
- Stack tecnológico
- apache, java
- Área
- backend-api-design, databases
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- Java
- Estrellas
- 9.4k
- Forks
- 3.7k
- Merge medio
- 2 d 15 h
- PR fusionados (30 d)
- 169
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de apache/iceberg
-
Spark: Test INSERT targets with computed IDENTIFIER expressionsPosiblemente ocupada @shivadarshan-devadiga la tomó hace 7 días. Abiertoimprovement
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
[Core] TestAvroPartitionStatsHandler fails on Windows due to unclosed partition statistics scanPosiblemente ocupada @Ankitkj1999 la tomó hace 9 días. Abierto
Dificultad 1/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
Flink: JdbcLockFactory concurrent lock-table creation can fail with "table already exists" and restart the jobPosiblemente ocupada @adiranjan25 la tomó hace 16 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
apache/iceberg#18797 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Core: TableMetadata.Builder allows adding encryption keys to v1/v2 tablesPosiblemente ocupada @yusufyildiz34 la tomó hace 29 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
apache/iceberg#18632 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Kafka: Filter empty strings and whitespace in IcebergSinkConfig stringToListPosiblemente ocupada @mohamed-elbrik la tomó hace 34 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
Todos los issues de apache/iceberg
Issues similares
-
documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
erkamyaman/rust-anything#371 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
open-telemetry/opentelemetry-java-instrumentation#21429 ·
Los mantenedores suelen responder en 1 día
-
enhancement lane:backlog
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Sanne/incus-spawn#2544 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
speakeasy-api/speakeasy#2159 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
apache/flink-agents#1440 ·
Los mantenedores suelen responder en 2 días