Skip to content

Commit 4d03ca8

Browse files
committed
make MemWriter optional
1 parent a92e2ee commit 4d03ca8

2 files changed

Lines changed: 36 additions & 31 deletions

File tree

src/parseable/staging/writer.rs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,6 @@ static ARROW_FLUSH_SIZE_LIMIT: Lazy<usize> = Lazy::new(|| {
6969
}
7070
});
7171

72-
const ONE_PARQUET_PER_ARROW_VAR: &str = "ONE_PARQUET_PER_ARROW";
73-
static ONE_PARQUET_PER_ARROW: Lazy<bool> = Lazy::new(|| {
74-
if let Ok(var) = std::env::var(ONE_PARQUET_PER_ARROW_VAR)
75-
&& let Ok(var) = var.parse::<bool>()
76-
{
77-
var
78-
} else {
79-
false
80-
}
81-
});
82-
8372
const ENABLE_MEMORY_STAGING_VAR: &str = "ENABLE_MEMORY_STAGING";
8473
pub static ENABLE_MEMORY_STAGING: Lazy<bool> = Lazy::new(|| {
8574
if let Ok(var) = std::env::var(ENABLE_MEMORY_STAGING_VAR)
@@ -91,13 +80,28 @@ pub static ENABLE_MEMORY_STAGING: Lazy<bool> = Lazy::new(|| {
9180
}
9281
});
9382

94-
#[derive(Default)]
83+
// #[derive(Default)]
9584
pub struct Writer {
96-
pub mem: MemWriter<4096>,
85+
pub mem: Option<MemWriter<4096>>,
9786
pub disk: HashMap<String, DiskWriter>,
9887
disk_pending: HashMap<String, PendingDiskBatch>,
9988
}
10089

90+
impl Default for Writer {
91+
fn default() -> Self {
92+
let mem = if *ENABLE_MEMORY_STAGING {
93+
Some(MemWriter::default())
94+
} else {
95+
None
96+
};
97+
Self {
98+
mem,
99+
disk: Default::default(),
100+
disk_pending: Default::default(),
101+
}
102+
}
103+
}
104+
101105
impl Writer {
102106
#[cfg_attr(feature = "hotpath", hotpath::measure)]
103107
pub fn push_disk(
@@ -256,13 +260,10 @@ impl DiskWriter {
256260
range: TimeRange,
257261
) -> Result<Self, StagingError> {
258262
let mut path = path.into();
259-
// a rudimentary way to ensure one parquet per arrow file
260-
if *ONE_PARQUET_PER_ARROW {
261-
path.set_extension(Ulid::new().to_string());
262-
path.add_extension(PART_FILE_EXTENSION);
263-
} else {
264-
path.set_extension(PART_FILE_EXTENSION);
265-
}
263+
264+
path.set_extension(Ulid::new().to_string());
265+
path.add_extension(PART_FILE_EXTENSION);
266+
266267
let file = OpenOptions::new()
267268
.write(true)
268269
.truncate(true)

src/parseable/streams.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ use crate::{
6161
metadata::{LogStreamMetadata, SchemaVersion},
6262
metrics,
6363
option::Mode,
64-
parseable::{DEFAULT_TENANT, PARSEABLE, staging::writer::ENABLE_MEMORY_STAGING},
64+
parseable::{DEFAULT_TENANT, PARSEABLE},
6565
storage::{StreamType, object_storage::to_bytes, retention::Retention},
6666
sync::FLUSH_AND_CONVERT_RUNTIME,
6767
utils::time::{Minute, TimeRange},
@@ -202,8 +202,8 @@ impl Stream {
202202
guard.push_disk(filename, record, file_path, range, *DISK_WRITE_BATCH_ROWS)?;
203203
}
204204

205-
if *ENABLE_MEMORY_STAGING {
206-
guard.mem.push(schema_key, record)?;
205+
if let Some(mem) = guard.mem.as_mut() {
206+
mem.push(schema_key, record)?;
207207
}
208208

209209
Ok(())
@@ -560,22 +560,23 @@ impl Stream {
560560
&self,
561561
schema: &Arc<Schema>,
562562
) -> Result<Vec<RecordBatch>, StagingError> {
563-
let writer = self.writer.lock().map_err(|poisoned| {
563+
let mut writer = self.writer.lock().map_err(|poisoned| {
564564
StagingError::PoisonError(PoisonError::new(format!(
565565
"Writer lock poisoned while cloning record batches for stream {} - {}",
566566
self.stream_name, poisoned
567567
)))
568568
})?;
569569

570-
if *ENABLE_MEMORY_STAGING {
571-
writer.mem.recordbatch_cloned(schema)
570+
if let Some(mem) = writer.mem.as_mut() {
571+
mem.recordbatch_cloned(schema)
572572
} else {
573573
Ok(Vec::new())
574574
}
575575
}
576576

577577
pub fn clear(&self) -> Result<(), StagingError> {
578-
self.writer
578+
if let Some(m) = self
579+
.writer
579580
.lock()
580581
.map_err(|poisoned| {
581582
StagingError::PoisonError(PoisonError::new(format!(
@@ -584,7 +585,10 @@ impl Stream {
584585
)))
585586
})?
586587
.mem
587-
.clear();
588+
.as_mut()
589+
{
590+
m.clear()
591+
}
588592
Ok(())
589593
}
590594

@@ -601,9 +605,9 @@ impl Stream {
601605
self.stream_name, poisoned
602606
)))
603607
})?;
604-
// why clean Writer.MemWriter?
605-
if *ENABLE_MEMORY_STAGING {
606-
writer.mem.clear();
608+
609+
if let Some(mem) = writer.mem.as_mut() {
610+
mem.clear();
607611
}
608612
writer.take_flushable_disk(forced)
609613
};

0 commit comments

Comments
 (0)