AWS driver: initDB fails with MySQL 1205 while a running instance holds coordination-row locks across S3/witness I/O

Aperta
#1,207 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
aws, go, mysql

Direzione di ricerca

Start in storage/aws/aws.go at mySQLSequencer.initDB, around L1018 and L1040–1060, then trace publishCheckpoint and consumeEntries where FOR UPDATE spans f(...). Reproduce with two instances and delayed S3 or witness I/O; done means a second NewAppender no longer times out with MySQL 1205 while the first instance is active.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Summary

With the AWS storage driver, a new process can fail to start while another instance of the same log is running, whenever that instance's S3 or witness I/O is slow. The new process's initDB blocks on coordination-table row locks that the running instance holds FOR UPDATE across network I/O. After InnoDB's lock wait (innodb_lock_wait_timeout, 50s by default), NewAppender fails with:

failed to init appender lifecycle: failed to create MySQL sequencer: failed to initDB: Error 1205 (HY000): Lock wait timeout exceeded; try restarting transaction

Observed on v1.0.3. The relevant code is unchanged on v1.0.4 and on main.

Mechanism (storage/aws/aws.go)

At every startup, mySQLSequencer.initDB does two things (main, around L1018 and L1040–1060):

  • ALTER TABLE PubCoord ADD COLUMN size ..., expecting ER_DUP_FIELDNAME;
  • INSERT IGNORE INTO each coordination table (Tessera, SeqCoord, IntCoord, PubCoord, GCCoord).

The INSERT IGNORE on an existing row takes a lock on that row, and the ALTER TABLE needs a metadata lock on PubCoord.

Running instances hold those rows FOR UPDATE while calling out:

  • publishCheckpoint takes SELECT publishedAt, size FROM PubCoord WHERE id = ? FOR UPDATE, then runs f(ctx, fromSeq, rootHash) before commit. That call builds, signs and witnesses the checkpoint and writes it to object storage.
  • consumeEntries takes SELECT seq, rootHash FROM IntCoord WHERE id = ? FOR UPDATE (plus Seq ... FOR UPDATE), then runs f(ctx, fromSeq, entries), which integrates and writes tiles and bundles to object storage, before commit.

So any stall in that I/O extends the lock hold, and a starting instance's initDB waits on it. In our case, S3 requests were being rejected with RequestTimeTooSkewed for about 15 minutes. Every new instance started during that window failed with 1205 and crash-looped until the I/O recovered.

Repro sketch

  1. Run one instance of a log on the AWS driver, with a steady trickle of Adds so that integration and publication run.
  2. Make object-storage writes slow, for example by injecting delay into the S3 client or at the network. The goal is for the f(...) inside consumeEntries/publishCheckpoint to take longer than innodb_lock_wait_timeout.
  3. Start a second instance against the same DB. NewAppender returns the 1205 error above after about 50s.

Suggestions (either would fix it for us)

  • Make initDB lock-free when the schema already exists. Check information_schema.COLUMNS before the ALTER TABLE. Replace the unconditional INSERT IGNOREs with a read (SELECT 1 ... WHERE id = 0, which needs no row lock under InnoDB consistent reads), and insert only when the row is missing. Then a started instance never contends with a running one.
  • Or release the coordination row locks before the network I/O, for example with an optimistic compare-and-set on the row after f() completes, so the lock span is bounded by DB latency rather than object-storage or witness latency. That is a bigger change, but it would also bound contention between concurrent running instances.

We're working around it downstream by retrying NewAppender on 1205 with a short backoff. That only helps if the lock clears within the caller's startup budget. Happy to test a fix.

Lingua principale
Go
Stelle
262
Fork
64
Merge medio
1g 6h
PR unite (30g)
20

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di transparency-dev/tessera

Tutte le issue di transparency-dev/tessera

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.