Xuanwo commented on code in PR #2192:
URL:
https://github.com/apache/incubator-opendal/pull/2192#discussion_r1187006585
##########
core/src/services/sftp/writer.rs:
##########
@@ -15,31 +15,38 @@
// specific language governing permissions and limitations
// under the License.
+use std::time::Duration;
+
use async_trait::async_trait;
-use bb8::PooledConnection;
use bytes::Bytes;
+use openssh_sftp_client::file::File;
+use tokio::time::sleep;
-use super::backend::Manager;
use crate::raw::oio;
use crate::{Error, ErrorKind, Result};
pub struct SftpWriter {
- conn: PooledConnection<'static, Manager>,
- path: String,
+ file: File,
}
impl SftpWriter {
- pub fn new(conn: PooledConnection<'static, Manager>, path: String) -> Self
{
- SftpWriter { conn, path }
+ pub fn new(file: File) -> Self {
+ SftpWriter { file }
}
}
#[async_trait]
impl oio::Write for SftpWriter {
async fn write(&mut self, bs: Bytes) -> Result<()> {
- let mut file = self.conn.sftp.create(&self.path).await?;
-
- file.write_all(&bs).await?;
+ tokio::select! {
+ _ = self.file.write_all(&bs) => {},
+ _ = sleep(Duration::from_secs(30)) => {
Review Comment:
Btw, timeout should be catched from upper layer, we should not select in
`write`.
##########
core/src/services/sftp/writer.rs:
##########
@@ -15,31 +15,38 @@
// specific language governing permissions and limitations
// under the License.
+use std::time::Duration;
+
use async_trait::async_trait;
-use bb8::PooledConnection;
use bytes::Bytes;
+use openssh_sftp_client::file::File;
+use tokio::time::sleep;
-use super::backend::Manager;
use crate::raw::oio;
use crate::{Error, ErrorKind, Result};
pub struct SftpWriter {
- conn: PooledConnection<'static, Manager>,
- path: String,
+ file: File,
}
impl SftpWriter {
- pub fn new(conn: PooledConnection<'static, Manager>, path: String) -> Self
{
- SftpWriter { conn, path }
+ pub fn new(file: File) -> Self {
+ SftpWriter { file }
}
}
#[async_trait]
impl oio::Write for SftpWriter {
async fn write(&mut self, bs: Bytes) -> Result<()> {
- let mut file = self.conn.sftp.create(&self.path).await?;
-
- file.write_all(&bs).await?;
+ tokio::select! {
Review Comment:
Maybe we should make sure the input `File` has been closed?
--
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]