Archive: a segment damaged before its first event reads as an empty one

Aperta
#1,855 0 commenti 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
go

Direzione di ricerca

Start by tracing how readRecordsWith in core/session/archive/reader.go reports truncation through Page and Earlier in core/session/archive/read.go, then check replay callers in core/session/archive/replay.go and the pre-first-record branch in core/sessionapi/export.go. The issue leaves open whether to propagate the flag or return an error for damage before the first event, so check the compatibility implications for callers outside this repo. Add the garbage-first-bytes test expecting HTTP 500, and update the export comments and docs/session-export.md once the behavior is settled.

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

Descrizione

Split out of the #1830 review.

What happens

readRecordsWith (core/session/archive/reader.go) reports a torn tail or an
undecodable line as truncated=true, err=nil — a property of the data, not a
failure. Page then discards that flag (_, err := readSegment(...) in
core/session/archive/read.go:57), so no caller above it can tell a damaged
segment from a complete one.

For the paging endpoints that is the intended, documented behaviour: serve the
readable prefix. But a segment damaged before its first event has no readable
prefix, so it contributes nothing and is indistinguishable from an empty archive:

segment -> 39 bytes of non-zstd garbage   GET /v1/export  200 application/x-ndjson ""
segment -> symlink loop (ELOOP)           GET /v1/export  500 {"error":"archive read failed"}

Only a segment that cannot be opened produces an error today. GET /v1/export
(#1830) documents this as the tolerated case, and docs/session-export.md says an
export is not a way to detect a corrupt archive — but "nothing happened this month"
and "this month will not decode" really are different answers, and a backup/export
consumer is exactly who wants to tell them apart.

What to do

Hand truncated up from Page/Earlier, or distinguish "torn before the first
event in a non-empty file" from "torn tail" and return that as an error. Then
handleExport's pre-first-record branch catches it and answers 500, and the
claims in core/sessionapi/export.go and docs/session-export.md can be
strengthened back.

This is an archive-package change with paging and replay as callers, which is why
it is not in #1830. core/ is consumed outside this repo, so a signature change
needs the usual care.

Scope

  • core/session/archive/{reader,read,replay}.go
  • core/sessionapi/export.go comments + docs/session-export.md once it lands
  • a test with a segment whose first bytes are garbage, asserting 500 rather than an empty 200

Refs #1810, #1830

Assisted-By: Claude (Anthropic AI) [email protected]

Lingua principale
Go
Stelle
31
Fork
49
Merge medio
9h 43m
PR unite (30g)
367

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 rossoctl/cortex

Tutte le issue di rossoctl/cortex

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.