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

fix(services/hdfs): fix poll_close when retry #4309

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions core/src/services/hdfs/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub struct HdfsWriter<F> {
tmp_path: Option<String>,
f: Option<F>,
client: Arc<hdrs::Client>,
fut: Option<BoxFuture<'static, Result<()>>>,
fut: Option<BoxFuture<'static, (F, Result<()>)>>,
}

/// # Safety
Expand Down Expand Up @@ -76,7 +76,11 @@ impl oio::Write for HdfsWriter<hdrs::AsyncFile> {
if let Some(fut) = self.fut.as_mut() {
let res = ready!(fut.poll_unpin(cx));
self.fut = None;
return Poll::Ready(res);
if let Err(e) = res.1 {
self.f = Some(res.0);
return Poll::Ready(Err(e));
}
return Poll::Ready(Ok(()));
}

let mut f = self.f.take().expect("HdfsWriter must be initialized");
Expand All @@ -86,15 +90,21 @@ impl oio::Write for HdfsWriter<hdrs::AsyncFile> {
let client = self.client.clone();

self.fut = Some(Box::pin(async move {
f.close().await.map_err(new_std_io_error)?;
if let Err(e) = f.close().await.map_err(new_std_io_error) {
// Reserve the original file handle for retry.
return (f, Err(e));
}

if let Some(tmp_path) = tmp_path {
client
if let Err(e) = client
.rename_file(&tmp_path, &target_path)
.map_err(new_std_io_error)?;
.map_err(new_std_io_error)
{
return (f, Err(e));
}
}

Ok(())
(f, Ok(()))
}));
}
}
Expand Down
Loading