bokket commented on code in PR #3763:
URL:
https://github.com/apache/incubator-opendal/pull/3763#discussion_r1428680646
##########
core/src/services/hdfs/backend.rs:
##########
@@ -262,12 +317,36 @@ impl Accessor for HdfsBackend {
open_options.write(true);
}
- let f = open_options
- .async_open(&p)
- .await
- .map_err(new_std_io_error)?;
+ if let Some(tmp_path) = &tmp_path {
+ let mut t = open_options
+ .async_open(tmp_path.to_str().unwrap())
+ .await
+ .map_err(new_std_io_error)?;
- Ok((RpWrite::new(), HdfsWriter::new(f)))
+ let tmp_path = tmp_path.clone();
+ let target_path = target_path.clone();
+
+ t.flush().await.map_err(new_std_io_error)?;
+ t.close().await.map_err(new_std_io_error)?;
+
+ self.client
+ .rename_file(tmp_path.to_str().unwrap(),
target_path.to_str().unwrap())
Review Comment:
This is exactly what I wanted to do at the beginning.So can we initialize
`client: Arc<hdrs::Client>`?
```rust
pub struct HdfsWriter<F> {
f: F,
client: Arc<hdrs::Client>,
}
impl<F> HdfsWriter<F> {
pub fn new(f: F,client: Arc<hdrs::Client>) -> Self {
Self {
f,
client,
}
}
}
#[async_trait]
impl oio::Write for HdfsWriter<hdrs::AsyncFile> {
fn poll_close(&mut self, cx: &mut Context<'_>) -> Poll<Result<()>> {
let tmp_path = self.tmp_path.clone();
let target_path = self.target_path.clone();
Pin::new(&mut self.f)
.poll_close(cx)
.map_err(new_std_io_error)
self.client
.rename_file(tmp_path.to_str().unwrap(),
target_path.to_str().unwrap())
.map_err(new_std_io_error)?;
}
}
```
This requires us to introduce into `self.client`
```rust
Ok((RpWrite::new(), HdfsWriter::new(f,target_path,tmp_path,Self.client)))
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]