pravega-client-rust
pravega-client-rust copied to clipboard
Document how to ensure durable write with event writer
Problem description
It is not clear how to use the event writer to determine when the event has been durably persisted.
Based on logging, writer.write_event(payload).await
returns even before the event has been sent across the wire.
Problem location
EventStreamWriter.write_event()
and
https://github.com/pravega/pravega-client-rust/blob/master/examples/event_write_and_read.rs#L65
Suggestions for an improvement
The documentation for EventStreamWriter.write_event()
should be updated. Also, the example in event_write_and_read.rs should show how to await a durable write ack.
I see. In this code snippet
let result = event_stream_writer.write_event(payload).await;
assert!(result.await.is_ok());
the result
is a channel that needs to await and when that has returned ok then event is durably persisted.
Will document that to avoid confusion.
This is not a very convenient API as it requires two awaits and then a match statement to flatten the result. It gets even more complicated without the anyhow macro.
let future = writer.write_event_by_routing_key(routing_key, event);
let receiver = future.await;
let result = receiver.await; // Result<Result<(), SegmentWriterError> RecvError>
let flattened_result = match result { // Result<(), Error>
Ok(r) => r.map_err(|e| anyhow!(e)),
Err(e) => Err(anyhow!(e)),
};
Is there anyway to get rid of the intermediate future? What is the benefit of it?