Skip to content

Commit bdbd8ce

Browse files
committed
remove more diskwriter lock unwrap
1 parent 30f3583 commit bdbd8ce

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

src/parseable/streams.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -559,18 +559,18 @@ impl Stream {
559559
Ok(())
560560
}
561561

562-
pub fn flush(&self, forced: bool) {
562+
pub fn flush(&self, forced: bool) -> Result<(), StagingError> {
563563
let _span = info_span!("flush", stream_name = %self.stream_name, forced).entered();
564564
// Swap out stale writers under the lock, drop them after releasing it.
565565
// DiskWriter::Drop does I/O (IPC finish + file rename) so dropping
566566
// outside the lock avoids blocking concurrent push() calls.
567567
let stale_writers = {
568-
let mut writer = self.writer.lock().unwrap_or_else(|_| {
569-
panic!(
570-
"Writer lock poisoned while flushing data for stream {}",
571-
self.stream_name
572-
)
573-
});
568+
let mut writer = self.writer.lock().map_err(|poisoned| {
569+
StagingError::PoisonError(PoisonError::new(format!(
570+
"Writer lock poisoned while flushing data for stream {} - {}",
571+
self.stream_name, poisoned
572+
)))
573+
})?;
574574
writer.mem.clear();
575575

576576
let mut old_disk = HashMap::new();
@@ -586,6 +586,7 @@ impl Stream {
586586
};
587587
// DiskWriter::Drop I/O happens here, outside the lock
588588
drop(stale_writers);
589+
Ok(())
589590
}
590591

591592
fn parquet_writer_props(
@@ -1325,7 +1326,7 @@ impl Stream {
13251326
// Force flush for init or shutdown signals to convert all .part files to .arrows
13261327
// For regular cycles, use false to only flush non-current writers
13271328
let forced = init_signal || shutdown_signal;
1328-
self.flush(forced);
1329+
self.flush(forced)?;
13291330
info!(
13301331
"Flushing stream ({}) took: {}s",
13311332
self.stream_name,
@@ -1736,7 +1737,7 @@ mod tests {
17361737
StreamType::UserDefined,
17371738
)
17381739
.unwrap();
1739-
staging.flush(true);
1740+
staging.flush(true).unwrap();
17401741
}
17411742

17421743
#[test]

0 commit comments

Comments
 (0)