Xuanwo commented on code in PR #5617:
URL: https://github.com/apache/opendal/pull/5617#discussion_r1959079610
##########
core/src/services/hdfs_native/reader.rs:
##########
@@ -15,23 +15,27 @@
// specific language governing permissions and limitations
// under the License.
+use bytes::Bytes;
use hdfs_native::file::FileReader;
use crate::raw::*;
+use crate::services::hdfs_native::error::parse_hdfs_error;
use crate::*;
pub struct HdfsNativeReader {
- _f: FileReader,
+ f: FileReader,
+ size: usize,
}
impl HdfsNativeReader {
- pub fn new(f: FileReader) -> Self {
- HdfsNativeReader { _f: f }
+ pub fn new(f: FileReader, size: usize) -> Self {
+ HdfsNativeReader { f, size }
}
}
impl oio::Read for HdfsNativeReader {
async fn read(&mut self) -> Result<Buffer> {
- todo!()
+ let bytes: Bytes =
self.f.read(self.size).await.map_err(parse_hdfs_error)?;
Review Comment:
This will read all data in memory at once. Please use `read_range_stream` to
get a bytes stream and yield bytes everytime users call `read`.
##########
core/src/services/hdfs_native/backend.rs:
##########
@@ -239,9 +249,13 @@ impl Access for HdfsNativeBackend {
}
async fn list(&self, path: &str, _args: OpList) -> Result<(RpList,
Self::Lister)> {
- let p = build_rooted_abs_path(&self.root, path);
- let l = HdfsNativeLister::new(p, self.client.clone());
- Ok((RpList::default(), Some(l)))
+ let iter = self.client.list_status_iter(path, true);
Review Comment:
Hi, please use `OpList::recursive` instead of always using `true`.
##########
core/src/services/hdfs_native/writer.rs:
##########
@@ -15,28 +15,41 @@
// specific language governing permissions and limitations
// under the License.
+use bytes::Buf;
+use bytes::Bytes;
use hdfs_native::file::FileWriter;
-use crate::raw::oio;
+use crate::raw::*;
+use crate::services::hdfs_native::error::parse_hdfs_error;
use crate::*;
pub struct HdfsNativeWriter {
- _f: FileWriter,
+ f: FileWriter,
}
impl HdfsNativeWriter {
pub fn new(f: FileWriter) -> Self {
- HdfsNativeWriter { _f: f }
+ HdfsNativeWriter { f }
}
}
impl oio::Write for HdfsNativeWriter {
- async fn write(&mut self, _bs: Buffer) -> Result<()> {
- todo!()
+ async fn write(&mut self, mut bs: Buffer) -> Result<()> {
+ while bs.has_remaining() {
Review Comment:
`Bytes::copy_from_slice` will copy the entire buffer while writing, it will
add much cost here. How about this:
```
while let Some(bs) = bs.next() {
self.f.write(bs).await
}
```
--
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]