serializer renderer: gracefully handle the case where we run out of disk space

we might still run out of space when writing CSVs and other outputs...
but that's at least less likely,
as long as we serialize the rendering.
This commit is contained in:
2022-08-11 18:21:46 -07:00
parent c83a44299f
commit 1928ad71cd

View File

@@ -640,9 +640,12 @@ impl SerializerRenderer {
measurements,
};
let name = self.fmt_str.replace("{step_no}", &*frame.state.step_no().to_string());
let out = BufWriter::new(File::create(name).unwrap());
//serde_cbor::to_writer(out, &snap).unwrap();
// serialize to a temporary file -- in case we run out of disk space, etc.
let temp_name = format!("{}.incomplete", name);
let out = BufWriter::new(File::create(&temp_name).unwrap());
bincode::serialize_into(out, &frame).unwrap();
// atomically complete the write.
std::fs::rename(temp_name, name).unwrap();
}
pub fn try_load<S: AbstractSim + for <'a> Deserialize<'a>>(&self) -> Option<SerializedFrame<S>> {