Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TrackWriter return incorrect written_size #278

Open
nooberfsh opened this issue Jun 26, 2024 · 0 comments
Open

TrackWriter return incorrect written_size #278

nooberfsh opened this issue Jun 26, 2024 · 0 comments

Comments

@nooberfsh
Copy link
Contributor

#[tokio::main]
async fn main() -> Result<()> {
    let wsize = Arc::new(AtomicI64::new(0));
    let mut w = make_writer(wsize.clone()).await?;

    let data = "hello, opendal";
    for _ in 0..1_000_000 {
        w.write_all(data.as_bytes()).await?
    }

    w.shutdown().await?;
    let wsize = wsize.load(std::sync::atomic::Ordering::SeqCst);
    println!("written size: {wsize}");

    Ok(())
}

async fn make_writer(wsize: Arc<AtomicI64>) -> 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, wsize))
}

Full code can be found in this repo

The above code write a simple string literal "hello, opendal" to local file test.txt 1_000_000 times using TrackWriter.
The expected written_size should be 14000000, but the above code print 14000326 on my machine which does not match the file size.

Related code:

match Pin::new(&mut self.writer).poll_write(cx, buf) {
std::task::Poll::Ready(Ok(n)) => {
self.written_size
.fetch_add(buf.len() as i64, std::sync::atomic::Ordering::Relaxed);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant