#[tokio::main]
async fn main() -> Result<()> {
let mut w = make_writer().await?;
let data = "hello, opendal";
for _ in 0..1_000_000 {
w.write_all(data.as_bytes()).await?
}
w.shutdown().await?;
let wsize = w.written_size.load(std::sync::atomic::Ordering::SeqCst);
println!("written size: {wsize}");
Ok(())
}
async fn make_writer() -> Result<TrackWriter> {
let mut builder = Fs::default();
builder.root(".");
let op: Operator = Operator::new(builder)?.finish();
let w = op
.writer("test.txt")
.await
.unwrap()
.into_futures_async_write();
Ok(TrackWriter::new(w))
}
// Copied from https://github.com/icelake-io/icelake/blob/main/icelake/src/io/parquet/track_writer.rs
/// `TrackWriter` is used to track the written size.
pub struct TrackWriter {
writer: FuturesAsyncWriter,
written_size: Arc<AtomicU64>,
}
impl tokio::io::AsyncWrite for TrackWriter { ... }
The above code write a simple string literal "hello, opendal" to local file test.txt 1_000_000 times using FuturesAsyncWriter.
The expected written_size should be 14000000, but the above code print 14000326 on my machine which does not match the file size.
That piece of code is from icelake, It was originally use the returned n, this commit changed it to buf.len().
I didn't aware it was changed, sorry for the bother. I will open an issue in icelake.
Full code can be found in this repo
The above code write a simple string literal
"hello, opendal"
to local filetest.txt
1_000_000 times usingFuturesAsyncWriter
. The expectedwritten_size
should be 14000000, but the above code print 14000326 on my machine which does not match the file size.opendal version: 0.47.1 rustc version: rustc 1.79.0 (129f3b996 2024-06-10)