Xuanwo commented on code in PR #2006:
URL: 
https://github.com/apache/incubator-opendal/pull/2006#discussion_r1169589797


##########
core/src/layers/madsim.rs:
##########
@@ -0,0 +1,358 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use crate::ops::{OpList, OpRead, OpScan, OpWrite};
+use crate::raw::oio::Entry;
+use crate::raw::{oio, Accessor, Layer, LayeredAccessor, RpList, RpRead, 
RpScan, RpWrite};
+use async_trait::async_trait;
+use bytes::Bytes;
+use madsim::net::Endpoint;
+use madsim::net::Payload;
+use std::collections::HashMap;
+use std::fmt::Debug;
+use std::io::Result;
+use std::io::SeekFrom;
+use std::net::SocketAddr;
+use std::sync::Arc;
+use std::sync::Mutex;
+use std::task::{Context, Poll};
+
+#[derive(Debug, Copy, Clone)]
+pub struct MadsimLayer {

Review Comment:
   Please add docs for this public struct.



##########
core/src/docs/concepts.rs:
##########
@@ -19,7 +19,7 @@
 //!
 //! OpenDAL provides a unified abstraction for all storage services.
 //!
-//! There are three core concepts in OpenDAL:
+//! There are two core concepts in OpenDAL:

Review Comment:
   Please update with main branch.



##########
core/src/layers/madsim.rs:
##########
@@ -0,0 +1,358 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use crate::ops::{OpList, OpRead, OpScan, OpWrite};
+use crate::raw::oio::Entry;
+use crate::raw::{oio, Accessor, Layer, LayeredAccessor, RpList, RpRead, 
RpScan, RpWrite};
+use async_trait::async_trait;
+use bytes::Bytes;
+use madsim::net::Endpoint;
+use madsim::net::Payload;
+use std::collections::HashMap;
+use std::fmt::Debug;
+use std::io::Result;
+use std::io::SeekFrom;
+use std::net::SocketAddr;
+use std::sync::Arc;
+use std::sync::Mutex;
+use std::task::{Context, Poll};
+
+#[derive(Debug, Copy, Clone)]
+pub struct MadsimLayer {
+    sim_server_socket: SocketAddr,
+}
+
+impl MadsimLayer {
+    pub fn new(sim_server_socket: SocketAddr) -> Self {
+        Self { sim_server_socket }
+    }
+}
+
+impl<A: Accessor> Layer<A> for MadsimLayer {
+    type LayeredAccessor = MadsimAccessor;
+
+    fn layer(&self, _inner: A) -> Self::LayeredAccessor {

Review Comment:
   Please use `_: A` if we don't use it.



##########
core/src/layers/madsim.rs:
##########
@@ -0,0 +1,358 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use crate::ops::{OpList, OpRead, OpScan, OpWrite};
+use crate::raw::oio::Entry;
+use crate::raw::{oio, Accessor, Layer, LayeredAccessor, RpList, RpRead, 
RpScan, RpWrite};
+use async_trait::async_trait;
+use bytes::Bytes;
+use madsim::net::Endpoint;
+use madsim::net::Payload;
+use std::collections::HashMap;
+use std::fmt::Debug;
+use std::io::Result;
+use std::io::SeekFrom;
+use std::net::SocketAddr;
+use std::sync::Arc;
+use std::sync::Mutex;
+use std::task::{Context, Poll};
+
+#[derive(Debug, Copy, Clone)]
+pub struct MadsimLayer {
+    sim_server_socket: SocketAddr,
+}
+
+impl MadsimLayer {
+    pub fn new(sim_server_socket: SocketAddr) -> Self {
+        Self { sim_server_socket }
+    }
+}
+
+impl<A: Accessor> Layer<A> for MadsimLayer {
+    type LayeredAccessor = MadsimAccessor;
+
+    fn layer(&self, _inner: A) -> Self::LayeredAccessor {
+        MadsimAccessor {
+            sim_server_socket: self.sim_server_socket,
+        }
+    }
+}
+
+#[derive(Debug)]
+pub struct MadsimAccessor {
+    sim_server_socket: SocketAddr,
+}
+
+#[async_trait]
+impl LayeredAccessor for MadsimAccessor {
+    type Inner = ();
+    type Reader = MadsimReader;
+    type BlockingReader = MadsimReader;
+    type Writer = MadsimWriter;
+    type BlockingWriter = MadsimWriter;
+    type Pager = MadsimPager;
+    type BlockingPager = MadsimPager;
+
+    fn inner(&self) -> &Self::Inner {
+        &()
+    }
+
+    async fn read(&self, path: &str, args: OpRead) -> crate::Result<(RpRead, 
Self::Reader)> {
+        let req = Request::Read(path.to_string(), args);
+        let ep = Endpoint::connect(self.sim_server_socket)
+            .await
+            .expect("fail to connect to sim server");
+        let (tx, mut rx) = ep
+            .connect1(self.sim_server_socket)
+            .await
+            .expect("fail to connect1 to sim server");
+        tx.send(Box::new(req))
+            .await
+            .expect("fail to send request to sim server");
+        let resp = rx
+            .recv()
+            .await
+            .expect("fail to recv response from sim server");
+        let resp = resp
+            .downcast::<ReadResponse>()
+            .expect("fail to downcast response to ReadResponse");
+        let content_length = resp.data.as_ref().map(|b| b.len()).unwrap_or(0);
+        Ok((
+            RpRead::new(content_length as u64),
+            MadsimReader { data: resp.data },
+        ))
+    }
+
+    async fn write(&self, path: &str, args: OpWrite) -> 
crate::Result<(RpWrite, Self::Writer)> {
+        Ok((
+            RpWrite::default(),
+            MadsimWriter {
+                path: path.to_string(),
+                args,
+                sim_server_socket: self.sim_server_socket,
+            },
+        ))
+    }
+
+    async fn list(&self, path: &str, args: OpList) -> crate::Result<(RpList, 
Self::Pager)> {
+        todo!()

Review Comment:
   Return `Err(Error::new(ErrorKind::Unsupport))` instead.



##########
core/src/layers/madsim.rs:
##########
@@ -0,0 +1,316 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use crate::ops::{OpList, OpRead, OpScan, OpWrite};
+use crate::raw::oio::Entry;
+use crate::raw::{oio, Accessor, Layer, LayeredAccessor, RpList, RpRead, 
RpScan, RpWrite};
+use crate::{EntryMode, Metadata};
+use async_trait::async_trait;
+use bytes::Bytes;
+use madsim::plugin::simulator;
+use madsim::plugin::Simulator;
+use madsim::rand::GlobalRng;
+use madsim::runtime::Handle;
+use madsim::task::NodeId;
+use madsim::time::TimeHandle;
+use madsim::Config;
+use std::collections::HashMap;
+use std::fmt::Debug;
+use std::io::SeekFrom;
+use std::sync::{Arc, Mutex};
+use std::task::{Context, Poll};
+
+#[derive(Debug, Copy, Clone)]
+pub struct MadsimLayer {
+    service_sim_node: NodeId,
+}
+
+impl MadsimLayer {
+    pub fn new() -> Self {
+        let service_sim_node = Handle::current().create_node().build().id();
+        Self { service_sim_node }
+    }
+}
+
+impl<A: Accessor> Layer<A> for MadsimLayer {
+    type LayeredAccessor = MadsimAccessor;
+
+    fn layer(&self, _inner: A) -> Self::LayeredAccessor {
+        let handle = simulator::<ServiceSim>().get_node(self.service_sim_node);
+        MadsimAccessor { handle }
+    }
+}
+
+#[derive(Debug)]
+pub struct MadsimAccessor {
+    handle: ServiceNodeHandle,
+}
+
+#[async_trait]
+impl LayeredAccessor for MadsimAccessor {
+    type Inner = ();
+    type Reader = MadsimReader;
+    type BlockingReader = MadsimReader;
+    type Writer = MadsimWriter;
+    type BlockingWriter = MadsimWriter;
+    type Pager = MadsimPager;
+    type BlockingPager = MadsimPager;
+
+    fn inner(&self) -> &Self::Inner {
+        &()
+    }
+
+    async fn read(&self, path: &str, args: OpRead) -> crate::Result<(RpRead, 
Self::Reader)> {
+        let handle = self.handle.inner.lock().unwrap();
+        let length = handle
+            .get(path)
+            .map(|(_, data)| data.len())
+            .unwrap_or_default();
+        Ok((
+            RpRead::new(length as u64),
+            MadsimReader {
+                path: path.to_string(),
+                args,
+                handle: self.handle.clone(),
+            },
+        ))
+    }
+
+    async fn write(&self, path: &str, args: OpWrite) -> 
crate::Result<(RpWrite, Self::Writer)> {
+        Ok((
+            RpWrite::new(),
+            MadsimWriter {
+                path: path.to_string(),
+                args,
+                handle: self.handle.clone(),
+            },
+        ))
+    }
+
+    async fn list(&self, path: &str, args: OpList) -> crate::Result<(RpList, 
Self::Pager)> {
+        unimplemented!("currently not supported, will be implemented in the 
future")
+    }
+
+    async fn scan(&self, path: &str, args: OpScan) -> crate::Result<(RpScan, 
Self::Pager)> {
+        unimplemented!("currently not supported, will be implemented in the 
future")
+    }
+
+    fn blocking_read(
+        &self,
+        path: &str,
+        args: OpRead,
+    ) -> crate::Result<(RpRead, Self::BlockingReader)> {
+        unimplemented!("currently not supported, will be implemented in the 
future")
+    }
+
+    fn blocking_write(
+        &self,
+        path: &str,
+        args: OpWrite,
+    ) -> crate::Result<(RpWrite, Self::BlockingWriter)> {
+        unimplemented!("currently not supported, will be implemented in the 
future")
+    }
+
+    fn blocking_list(
+        &self,
+        path: &str,
+        args: OpList,
+    ) -> crate::Result<(RpList, Self::BlockingPager)> {
+        unimplemented!("currently not supported, will be implemented in the 
future")
+    }
+
+    fn blocking_scan(
+        &self,
+        path: &str,
+        args: OpScan,
+    ) -> crate::Result<(RpScan, Self::BlockingPager)> {
+        unimplemented!("currently not supported, will be implemented in the 
future")
+    }
+}
+
+pub struct MadsimReader {
+    path: String,
+    args: OpRead,
+    handle: ServiceNodeHandle,
+}
+
+impl oio::Read for MadsimReader {
+    fn poll_read(&mut self, _cx: &mut Context<'_>, buf: &mut [u8]) -> 
Poll<crate::Result<usize>> {
+        let mut inner = self.handle.inner.lock().unwrap();
+        if let Some((_meta, data)) = inner.get(&self.path) {
+            buf.copy_from_slice(data);
+            Poll::Ready(Ok(data.len()))
+        } else {
+            Poll::Ready(Err(crate::Error::new(
+                crate::ErrorKind::NotFound,
+                "not found",
+            )))
+        }
+    }
+
+    fn poll_seek(&mut self, cx: &mut Context<'_>, pos: SeekFrom) -> 
Poll<crate::Result<u64>> {
+        unimplemented!("currently not supported, will be implemented in the 
future")
+    }
+
+    fn poll_next(&mut self, cx: &mut Context<'_>) -> 
Poll<Option<crate::Result<Bytes>>> {
+        unimplemented!("currently not supported, will be implemented in the 
future")
+    }
+}
+
+impl oio::BlockingRead for MadsimReader {
+    fn read(&mut self, buf: &mut [u8]) -> crate::Result<usize> {
+        unimplemented!("currently not supported, will be implemented in the 
future")
+    }
+
+    fn seek(&mut self, pos: SeekFrom) -> crate::Result<u64> {
+        unimplemented!("currently not supported, will be implemented in the 
future")
+    }
+
+    fn next(&mut self) -> Option<crate::Result<Bytes>> {
+        unimplemented!("currently not supported, will be implemented in the 
future")
+    }
+}
+
+pub struct MadsimWriter {
+    path: String,
+    args: OpWrite,
+    handle: ServiceNodeHandle,
+}
+
+impl oio::BlockingWrite for MadsimWriter {
+    fn write(&mut self, bs: Bytes) -> crate::Result<()> {
+        unimplemented!("currently not supported, will be implemented in the 
future")
+    }
+
+    fn append(&mut self, bs: Bytes) -> crate::Result<()> {
+        unimplemented!("currently not supported, will be implemented in the 
future")
+    }
+
+    fn close(&mut self) -> crate::Result<()> {
+        unimplemented!("currently not supported, will be implemented in the 
future")
+    }
+}
+
+#[async_trait]
+impl oio::Write for MadsimWriter {

Review Comment:
   `reqwest` takes our input as a whole and there is no place for us to 
implement `poll_write` :rofl: 



##########
core/src/layers/madsim.rs:
##########
@@ -0,0 +1,358 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use crate::ops::{OpList, OpRead, OpScan, OpWrite};
+use crate::raw::oio::Entry;
+use crate::raw::{oio, Accessor, Layer, LayeredAccessor, RpList, RpRead, 
RpScan, RpWrite};
+use async_trait::async_trait;
+use bytes::Bytes;
+use madsim::net::Endpoint;
+use madsim::net::Payload;
+use std::collections::HashMap;
+use std::fmt::Debug;
+use std::io::Result;
+use std::io::SeekFrom;
+use std::net::SocketAddr;
+use std::sync::Arc;
+use std::sync::Mutex;
+use std::task::{Context, Poll};
+
+#[derive(Debug, Copy, Clone)]
+pub struct MadsimLayer {
+    sim_server_socket: SocketAddr,
+}
+
+impl MadsimLayer {
+    pub fn new(sim_server_socket: SocketAddr) -> Self {
+        Self { sim_server_socket }
+    }
+}
+
+impl<A: Accessor> Layer<A> for MadsimLayer {
+    type LayeredAccessor = MadsimAccessor;
+
+    fn layer(&self, _inner: A) -> Self::LayeredAccessor {
+        MadsimAccessor {
+            sim_server_socket: self.sim_server_socket,
+        }
+    }
+}
+
+#[derive(Debug)]
+pub struct MadsimAccessor {
+    sim_server_socket: SocketAddr,
+}
+
+#[async_trait]
+impl LayeredAccessor for MadsimAccessor {
+    type Inner = ();
+    type Reader = MadsimReader;
+    type BlockingReader = MadsimReader;
+    type Writer = MadsimWriter;
+    type BlockingWriter = MadsimWriter;
+    type Pager = MadsimPager;
+    type BlockingPager = MadsimPager;
+
+    fn inner(&self) -> &Self::Inner {
+        &()
+    }
+
+    async fn read(&self, path: &str, args: OpRead) -> crate::Result<(RpRead, 
Self::Reader)> {
+        let req = Request::Read(path.to_string(), args);
+        let ep = Endpoint::connect(self.sim_server_socket)
+            .await
+            .expect("fail to connect to sim server");
+        let (tx, mut rx) = ep
+            .connect1(self.sim_server_socket)
+            .await
+            .expect("fail to connect1 to sim server");
+        tx.send(Box::new(req))
+            .await
+            .expect("fail to send request to sim server");
+        let resp = rx
+            .recv()
+            .await
+            .expect("fail to recv response from sim server");
+        let resp = resp
+            .downcast::<ReadResponse>()
+            .expect("fail to downcast response to ReadResponse");
+        let content_length = resp.data.as_ref().map(|b| b.len()).unwrap_or(0);
+        Ok((
+            RpRead::new(content_length as u64),
+            MadsimReader { data: resp.data },
+        ))
+    }
+
+    async fn write(&self, path: &str, args: OpWrite) -> 
crate::Result<(RpWrite, Self::Writer)> {
+        Ok((
+            RpWrite::default(),
+            MadsimWriter {
+                path: path.to_string(),
+                args,
+                sim_server_socket: self.sim_server_socket,
+            },
+        ))
+    }
+
+    async fn list(&self, path: &str, args: OpList) -> crate::Result<(RpList, 
Self::Pager)> {
+        todo!()
+    }
+
+    async fn scan(&self, path: &str, args: OpScan) -> crate::Result<(RpScan, 
Self::Pager)> {
+        todo!()
+    }
+
+    fn blocking_read(
+        &self,
+        path: &str,
+        args: OpRead,
+    ) -> crate::Result<(RpRead, Self::BlockingReader)> {
+        panic!("blocking_read is not supported in MadsimLayer");
+    }
+
+    fn blocking_write(
+        &self,
+        path: &str,
+        args: OpWrite,
+    ) -> crate::Result<(RpWrite, Self::BlockingWriter)> {
+        panic!("blocking_write is not supported in MadsimLayer");
+    }
+
+    fn blocking_list(
+        &self,
+        path: &str,
+        args: OpList,
+    ) -> crate::Result<(RpList, Self::BlockingPager)> {
+        panic!("blocking_list is not supported in MadsimLayer");
+    }
+
+    fn blocking_scan(
+        &self,
+        path: &str,
+        args: OpScan,
+    ) -> crate::Result<(RpScan, Self::BlockingPager)> {
+        panic!("blocking_scan is not supported in MadsimLayer");
+    }
+}
+
+pub struct MadsimReader {
+    data: Option<Bytes>,
+}
+
+impl oio::Read for MadsimReader {
+    fn poll_read(&mut self, _cx: &mut Context<'_>, buf: &mut [u8]) -> 
Poll<crate::Result<usize>> {
+        if let Some(ref data) = self.data {
+            let len = data.len();
+            buf[..len].copy_from_slice(data);
+            Poll::Ready(Ok(len))
+        } else {
+            Poll::Ready(Ok(0))
+        }
+    }
+
+    fn poll_seek(&mut self, cx: &mut Context<'_>, pos: SeekFrom) -> 
Poll<crate::Result<u64>> {
+        todo!()
+    }
+
+    fn poll_next(&mut self, cx: &mut Context<'_>) -> 
Poll<Option<crate::Result<Bytes>>> {
+        todo!()
+    }
+}
+
+impl oio::BlockingRead for MadsimReader {
+    fn read(&mut self, buf: &mut [u8]) -> crate::Result<usize> {
+        todo!()
+    }
+
+    fn seek(&mut self, pos: SeekFrom) -> crate::Result<u64> {
+        todo!()
+    }
+
+    fn next(&mut self) -> Option<crate::Result<Bytes>> {
+        todo!()
+    }
+}
+
+pub struct MadsimWriter {
+    path: String,
+    args: OpWrite,
+    sim_server_socket: SocketAddr,
+}
+
+impl oio::BlockingWrite for MadsimWriter {
+    fn write(&mut self, bs: Bytes) -> crate::Result<()> {
+        todo!()
+    }
+
+    fn append(&mut self, bs: Bytes) -> crate::Result<()> {
+        todo!()
+    }
+
+    fn close(&mut self) -> crate::Result<()> {
+        todo!()
+    }
+}
+
+#[async_trait]
+impl oio::Write for MadsimWriter {
+    async fn write(&mut self, bs: Bytes) -> crate::Result<()> {
+        let req = Request::Write(self.path.to_string(), bs);
+        let ep = Endpoint::connect(self.sim_server_socket)
+            .await
+            .expect("fail to connect to sim server");
+        let (tx, mut rx) = ep
+            .connect1(self.sim_server_socket)
+            .await
+            .expect("fail to connect1 to sim server");
+        tx.send(Box::new(req))
+            .await
+            .expect("fail to send request to sim server");
+        rx.recv()
+            .await
+            .expect("fail to recv response from sim server");
+        Ok(())
+    }
+
+    async fn append(&mut self, bs: Bytes) -> crate::Result<()> {
+        todo!()
+    }
+
+    async fn abort(&mut self) -> crate::Result<()> {
+        todo!()
+    }
+
+    async fn close(&mut self) -> crate::Result<()> {
+        Ok(())
+    }
+}
+
+pub struct MadsimPager {}
+
+#[async_trait]
+impl oio::Page for MadsimPager {
+    async fn next(&mut self) -> crate::Result<Option<Vec<Entry>>> {
+        todo!()
+    }
+}
+
+impl oio::BlockingPage for MadsimPager {
+    fn next(&mut self) -> crate::Result<Option<Vec<Entry>>> {
+        todo!()
+    }
+}
+
+/// A simulated server.
+#[derive(Default, Clone)]
+pub struct SimServer;

Review Comment:
   How about use `MadsimServer`? Also, please add a docs on how to use it.
   
   Maybe we can use the following code for reference.
   
   
https://github.com/risingwavelabs/risingwave/blob/a76cae7056aadc83955894ffaf18d02dc601ff25/src/tests/simulation/src/cluster.rs#L196-L207



##########
core/src/layers/madsim.rs:
##########
@@ -0,0 +1,358 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use crate::ops::{OpList, OpRead, OpScan, OpWrite};
+use crate::raw::oio::Entry;
+use crate::raw::{oio, Accessor, Layer, LayeredAccessor, RpList, RpRead, 
RpScan, RpWrite};
+use async_trait::async_trait;
+use bytes::Bytes;
+use madsim::net::Endpoint;
+use madsim::net::Payload;
+use std::collections::HashMap;
+use std::fmt::Debug;
+use std::io::Result;
+use std::io::SeekFrom;
+use std::net::SocketAddr;
+use std::sync::Arc;
+use std::sync::Mutex;
+use std::task::{Context, Poll};
+
+#[derive(Debug, Copy, Clone)]
+pub struct MadsimLayer {
+    sim_server_socket: SocketAddr,

Review Comment:
   How about using `addr`?



##########
core/src/layers/madsim.rs:
##########
@@ -0,0 +1,358 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use crate::ops::{OpList, OpRead, OpScan, OpWrite};
+use crate::raw::oio::Entry;
+use crate::raw::{oio, Accessor, Layer, LayeredAccessor, RpList, RpRead, 
RpScan, RpWrite};
+use async_trait::async_trait;
+use bytes::Bytes;
+use madsim::net::Endpoint;
+use madsim::net::Payload;
+use std::collections::HashMap;
+use std::fmt::Debug;
+use std::io::Result;
+use std::io::SeekFrom;
+use std::net::SocketAddr;
+use std::sync::Arc;
+use std::sync::Mutex;
+use std::task::{Context, Poll};
+
+#[derive(Debug, Copy, Clone)]
+pub struct MadsimLayer {
+    sim_server_socket: SocketAddr,
+}
+
+impl MadsimLayer {
+    pub fn new(sim_server_socket: SocketAddr) -> Self {
+        Self { sim_server_socket }
+    }
+}
+
+impl<A: Accessor> Layer<A> for MadsimLayer {
+    type LayeredAccessor = MadsimAccessor;
+
+    fn layer(&self, _inner: A) -> Self::LayeredAccessor {
+        MadsimAccessor {
+            sim_server_socket: self.sim_server_socket,
+        }
+    }
+}
+
+#[derive(Debug)]
+pub struct MadsimAccessor {
+    sim_server_socket: SocketAddr,
+}
+
+#[async_trait]
+impl LayeredAccessor for MadsimAccessor {
+    type Inner = ();
+    type Reader = MadsimReader;
+    type BlockingReader = MadsimReader;
+    type Writer = MadsimWriter;
+    type BlockingWriter = MadsimWriter;
+    type Pager = MadsimPager;
+    type BlockingPager = MadsimPager;
+
+    fn inner(&self) -> &Self::Inner {
+        &()
+    }
+
+    async fn read(&self, path: &str, args: OpRead) -> crate::Result<(RpRead, 
Self::Reader)> {
+        let req = Request::Read(path.to_string(), args);
+        let ep = Endpoint::connect(self.sim_server_socket)
+            .await
+            .expect("fail to connect to sim server");
+        let (tx, mut rx) = ep
+            .connect1(self.sim_server_socket)
+            .await
+            .expect("fail to connect1 to sim server");
+        tx.send(Box::new(req))
+            .await
+            .expect("fail to send request to sim server");
+        let resp = rx
+            .recv()
+            .await
+            .expect("fail to recv response from sim server");
+        let resp = resp
+            .downcast::<ReadResponse>()
+            .expect("fail to downcast response to ReadResponse");
+        let content_length = resp.data.as_ref().map(|b| b.len()).unwrap_or(0);
+        Ok((
+            RpRead::new(content_length as u64),
+            MadsimReader { data: resp.data },
+        ))
+    }
+
+    async fn write(&self, path: &str, args: OpWrite) -> 
crate::Result<(RpWrite, Self::Writer)> {
+        Ok((
+            RpWrite::default(),
+            MadsimWriter {
+                path: path.to_string(),
+                args,
+                sim_server_socket: self.sim_server_socket,
+            },
+        ))
+    }
+
+    async fn list(&self, path: &str, args: OpList) -> crate::Result<(RpList, 
Self::Pager)> {
+        todo!()
+    }
+
+    async fn scan(&self, path: &str, args: OpScan) -> crate::Result<(RpScan, 
Self::Pager)> {
+        todo!()
+    }
+
+    fn blocking_read(
+        &self,
+        path: &str,
+        args: OpRead,
+    ) -> crate::Result<(RpRead, Self::BlockingReader)> {
+        panic!("blocking_read is not supported in MadsimLayer");

Review Comment:
   Return `Unsupported` error instead to avoid unexpected panic.



##########
core/src/layers/madsim.rs:
##########
@@ -0,0 +1,358 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use crate::ops::{OpList, OpRead, OpScan, OpWrite};
+use crate::raw::oio::Entry;
+use crate::raw::{oio, Accessor, Layer, LayeredAccessor, RpList, RpRead, 
RpScan, RpWrite};
+use async_trait::async_trait;
+use bytes::Bytes;
+use madsim::net::Endpoint;
+use madsim::net::Payload;
+use std::collections::HashMap;
+use std::fmt::Debug;
+use std::io::Result;
+use std::io::SeekFrom;
+use std::net::SocketAddr;
+use std::sync::Arc;
+use std::sync::Mutex;
+use std::task::{Context, Poll};
+
+#[derive(Debug, Copy, Clone)]
+pub struct MadsimLayer {
+    sim_server_socket: SocketAddr,
+}
+
+impl MadsimLayer {
+    pub fn new(sim_server_socket: SocketAddr) -> Self {
+        Self { sim_server_socket }
+    }
+}
+
+impl<A: Accessor> Layer<A> for MadsimLayer {
+    type LayeredAccessor = MadsimAccessor;
+
+    fn layer(&self, _inner: A) -> Self::LayeredAccessor {
+        MadsimAccessor {
+            sim_server_socket: self.sim_server_socket,
+        }
+    }
+}
+
+#[derive(Debug)]
+pub struct MadsimAccessor {
+    sim_server_socket: SocketAddr,
+}
+
+#[async_trait]
+impl LayeredAccessor for MadsimAccessor {
+    type Inner = ();
+    type Reader = MadsimReader;
+    type BlockingReader = MadsimReader;
+    type Writer = MadsimWriter;
+    type BlockingWriter = MadsimWriter;
+    type Pager = MadsimPager;
+    type BlockingPager = MadsimPager;
+
+    fn inner(&self) -> &Self::Inner {
+        &()
+    }
+

Review Comment:
   Please implement `info()` and returns correct accessor infomation.



##########
core/src/layers/madsim.rs:
##########
@@ -0,0 +1,358 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use crate::ops::{OpList, OpRead, OpScan, OpWrite};
+use crate::raw::oio::Entry;
+use crate::raw::{oio, Accessor, Layer, LayeredAccessor, RpList, RpRead, 
RpScan, RpWrite};
+use async_trait::async_trait;
+use bytes::Bytes;
+use madsim::net::Endpoint;
+use madsim::net::Payload;
+use std::collections::HashMap;
+use std::fmt::Debug;
+use std::io::Result;
+use std::io::SeekFrom;
+use std::net::SocketAddr;
+use std::sync::Arc;
+use std::sync::Mutex;
+use std::task::{Context, Poll};
+
+#[derive(Debug, Copy, Clone)]
+pub struct MadsimLayer {
+    sim_server_socket: SocketAddr,
+}
+
+impl MadsimLayer {
+    pub fn new(sim_server_socket: SocketAddr) -> Self {

Review Comment:
   How about accept an `endpoint: &str` and parse it into `SocketAddr` for 
easier to use?



##########
core/src/layers/madsim.rs:
##########
@@ -0,0 +1,358 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use crate::ops::{OpList, OpRead, OpScan, OpWrite};
+use crate::raw::oio::Entry;
+use crate::raw::{oio, Accessor, Layer, LayeredAccessor, RpList, RpRead, 
RpScan, RpWrite};
+use async_trait::async_trait;
+use bytes::Bytes;
+use madsim::net::Endpoint;
+use madsim::net::Payload;
+use std::collections::HashMap;
+use std::fmt::Debug;
+use std::io::Result;
+use std::io::SeekFrom;
+use std::net::SocketAddr;
+use std::sync::Arc;
+use std::sync::Mutex;
+use std::task::{Context, Poll};
+
+#[derive(Debug, Copy, Clone)]
+pub struct MadsimLayer {
+    sim_server_socket: SocketAddr,
+}
+
+impl MadsimLayer {
+    pub fn new(sim_server_socket: SocketAddr) -> Self {
+        Self { sim_server_socket }
+    }
+}
+
+impl<A: Accessor> Layer<A> for MadsimLayer {
+    type LayeredAccessor = MadsimAccessor;
+
+    fn layer(&self, _inner: A) -> Self::LayeredAccessor {
+        MadsimAccessor {
+            sim_server_socket: self.sim_server_socket,
+        }
+    }
+}
+
+#[derive(Debug)]
+pub struct MadsimAccessor {
+    sim_server_socket: SocketAddr,
+}
+
+#[async_trait]
+impl LayeredAccessor for MadsimAccessor {
+    type Inner = ();
+    type Reader = MadsimReader;
+    type BlockingReader = MadsimReader;
+    type Writer = MadsimWriter;
+    type BlockingWriter = MadsimWriter;
+    type Pager = MadsimPager;
+    type BlockingPager = MadsimPager;
+
+    fn inner(&self) -> &Self::Inner {
+        &()
+    }
+
+    async fn read(&self, path: &str, args: OpRead) -> crate::Result<(RpRead, 
Self::Reader)> {
+        let req = Request::Read(path.to_string(), args);
+        let ep = Endpoint::connect(self.sim_server_socket)
+            .await
+            .expect("fail to connect to sim server");
+        let (tx, mut rx) = ep
+            .connect1(self.sim_server_socket)
+            .await
+            .expect("fail to connect1 to sim server");
+        tx.send(Box::new(req))
+            .await
+            .expect("fail to send request to sim server");
+        let resp = rx
+            .recv()
+            .await
+            .expect("fail to recv response from sim server");
+        let resp = resp
+            .downcast::<ReadResponse>()
+            .expect("fail to downcast response to ReadResponse");
+        let content_length = resp.data.as_ref().map(|b| b.len()).unwrap_or(0);
+        Ok((
+            RpRead::new(content_length as u64),
+            MadsimReader { data: resp.data },
+        ))
+    }
+
+    async fn write(&self, path: &str, args: OpWrite) -> 
crate::Result<(RpWrite, Self::Writer)> {
+        Ok((
+            RpWrite::default(),
+            MadsimWriter {
+                path: path.to_string(),
+                args,
+                sim_server_socket: self.sim_server_socket,
+            },
+        ))
+    }
+
+    async fn list(&self, path: &str, args: OpList) -> crate::Result<(RpList, 
Self::Pager)> {
+        todo!()
+    }
+
+    async fn scan(&self, path: &str, args: OpScan) -> crate::Result<(RpScan, 
Self::Pager)> {
+        todo!()
+    }
+
+    fn blocking_read(
+        &self,
+        path: &str,
+        args: OpRead,
+    ) -> crate::Result<(RpRead, Self::BlockingReader)> {
+        panic!("blocking_read is not supported in MadsimLayer");
+    }
+
+    fn blocking_write(
+        &self,
+        path: &str,
+        args: OpWrite,
+    ) -> crate::Result<(RpWrite, Self::BlockingWriter)> {
+        panic!("blocking_write is not supported in MadsimLayer");
+    }
+
+    fn blocking_list(
+        &self,
+        path: &str,
+        args: OpList,
+    ) -> crate::Result<(RpList, Self::BlockingPager)> {
+        panic!("blocking_list is not supported in MadsimLayer");
+    }
+
+    fn blocking_scan(
+        &self,
+        path: &str,
+        args: OpScan,
+    ) -> crate::Result<(RpScan, Self::BlockingPager)> {
+        panic!("blocking_scan is not supported in MadsimLayer");
+    }
+}
+
+pub struct MadsimReader {
+    data: Option<Bytes>,
+}
+
+impl oio::Read for MadsimReader {
+    fn poll_read(&mut self, _cx: &mut Context<'_>, buf: &mut [u8]) -> 
Poll<crate::Result<usize>> {
+        if let Some(ref data) = self.data {
+            let len = data.len();
+            buf[..len].copy_from_slice(data);
+            Poll::Ready(Ok(len))
+        } else {
+            Poll::Ready(Ok(0))
+        }
+    }
+
+    fn poll_seek(&mut self, cx: &mut Context<'_>, pos: SeekFrom) -> 
Poll<crate::Result<u64>> {
+        todo!()
+    }
+
+    fn poll_next(&mut self, cx: &mut Context<'_>) -> 
Poll<Option<crate::Result<Bytes>>> {
+        todo!()
+    }
+}
+
+impl oio::BlockingRead for MadsimReader {

Review Comment:
   We can return `()` as `Reader` if we don't implement it.



-- 
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]


Reply via email to