Repository navigation
fix(arrow/ipc): keep zstd decoders with the reader that made them - #1630
Conversation
- A zstd.Decoder owns a channel, and a channel made inside a testing/synctest bubble must not be used outside it. The process-wide decoder pool handed decoders made in a bubble to readers elsewhere, which aborted the process. - Reader and FileReader now reuse their own decoders. FileReader keeps as many as were in use at once, since RecordBatchAt may run concurrently. - Encoders stay pooled process-wide: they are only used through the streaming API, which keeps no channel between streams.
There was a problem hiding this comment.
Seems fine. Though it looks like there's an opportunity to do a little refactor rather than just the minimal change here. This PR makes readDictionary, loadRecordBatch, etc become aware of the shared Zstd decoders, e.g.,
- return readDictionary(&f.memo, msg.meta, msg.body, f.swapEndianness, f.mem)
+ return readDictionary(&f.memo, msg.meta, msg.body, f.swapEndianness, f.mem, &f.zstd)Could Reader and FileReader embed and internal IpcDecoder struct like,
type ipcDecoder struct {
schema *arrow.Schema
memo dictutils.Memo
mem memory.Allocator
swapEndianness bool
zstd zstdDecoders
}Dictionary and record loading could then be methods on it:
func (d *ipcDecoder) readDictionary(meta, body *memory.Buffer) (dictutils.Kind, error)This simplifies the existing call site (which has already grown) to just r.readDictionary(msg.meta, msg.body).
Reader and FileReader embed an ipcDecoder holding the schema, dictionary memo, allocator, endianness flag and zstd decoders. readDictionary, newRecordBatch and loadRecordBatch become methods on it instead of taking each of those as a parameter.
|
Thanks @amoeba, good suggestion. Done in the second commit: |
Rationale for this change
Fixes #1629.
Since #1331, zstd decoders come from a process-wide
sync.Pool. Azstd.Decoderowns a channel that everyDecodeAllreceives from, and a channel made inside atesting/synctestbubble must not be used outside that bubble. When a reader inside a bubble created a decoder, the pool could hand it to a reader outside the bubble or in another bubble, and the runtime aborted withfatal error: receive on synctest channel from outside bubble. A decoder made outside a bubble is safe to use inside one, so the crash only happens after a decoder was created in a bubble.What changes are included in this PR?
ReaderandFileReadereach keep their own idle zstd decoders, and the process-wide decoder pool is removed. Go's HTTP/2 server made the same change for the same problem (net/http: http2 server use with synctest sometimes causes fatal error "select on synctest channel from outside bubble" golang/go#75674).FileReader.RecordBatchAtmay be called concurrently, so aFileReaderkeeps as many decoders as were in use at once.zstdEncoderPoolsrecords whyEncodeAllmust not be used there.Cost, from
BenchmarkReaderCompressed, which creates a new reader on every iteration: one decoder per reader, about 1.5 KiB and 11 allocations, with no measurable change in time.Are these changes tested?
Yes.
Are there any user-facing changes?
Reading zstd-compressed IPC data inside
testing/synctestbubbles no longer crashes the process. There is no API change.