A retried `upsert` inserts a key that a concurrent writer already inserted

Ouverte
#4,194 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
54/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
Active
Stack technique
python, sqlite

Piste de recherche

Start by tracing the upsert commit retry and _FastAppendFiles._validate_concurrency; the issue says that path currently fails to detect a concurrent insert. Reproduce the two-writer example with the supplied SQLite catalog and PyArrow table, then compare the behavior with version 0.11.1. Done means a retry does not leave duplicate keys, and concurrent add_files does not register the same file twice.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

kind:bug
Apache Iceberg version

0.12.0 (latest release)

Please describe the bug 🐞

Currently, a commit retry replays the upsert's append, and _FastAppendFiles._validate_concurrency checks nothing, so a key another writer inserted after the read is inserted a second time. 0.11.1 raises CommitFailedException here.

import tempfile
import pyarrow as pa
from pyiceberg.catalog.sql import SqlCatalog
from pyiceberg.schema import Schema
from pyiceberg.types import LongType, NestedField, StringType

cat = SqlCatalog("c", uri="sqlite:///:memory:", warehouse=f"file://{tempfile.mkdtemp()}")
cat.create_namespace("ns")
schema = Schema(NestedField(1, "k", LongType(), required=True), NestedField(2, "v", StringType()), identifier_field_ids=[1])
t = cat.create_table("ns.t", schema=schema)
row = lambda k, v: pa.Table.from_pylist([{"k": k, "v": v}], schema=schema.as_arrow())
t.append(row(1, "a"))

a = cat.load_table("ns.t")
b = cat.load_table("ns.t")
b.upsert(row(2, "b"))
a.upsert(row(2, "a"))
# Commit failed due to a concurrent update, retrying (1/4) in 106 ms
print(sorted(cat.load_table("ns.t").scan().to_arrow().to_pylist(), key=str))
# [{'k': 1, 'v': 'a'}, {'k': 2, 'v': 'a'}, {'k': 2, 'v': 'b'}], should hold k 2 once

Two writers calling add_files on the same file register it twice the same way, and every row in it reads back twice.

tested on pyiceberg 0.12.0 and main

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
Langage dominant
Python
Étoiles
1.2k
Forks
654
Merge moyen
2 j 11 h
PR mergées (30 j)
122

Préparer son environnement

  • Aucun Dockerfile ni fichier Docker Compose
  • Propose un modèle de pull request
  • Aucun guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de apache/iceberg-python

Toutes les issues de apache/iceberg-python

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.