From mboxrd@z Thu Jan 1 00:00:00 1970
Return-Path: <d.csapak@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature RSA-PSS (2048 bits))
(No client certificate requested)
by lists.proxmox.com (Postfix) with ESMTPS id 8BCFE697F9
for <pbs-devel@lists.proxmox.com>; Tue, 19 Jan 2021 12:04:50 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
by firstgate.proxmox.com (Proxmox) with ESMTP id 7D8A91D4B6
for <pbs-devel@lists.proxmox.com>; Tue, 19 Jan 2021 12:04:50 +0100 (CET)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
[212.186.127.180])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature RSA-PSS (2048 bits))
(No client certificate requested)
by firstgate.proxmox.com (Proxmox) with ESMTPS id AD38B1D4AD
for <pbs-devel@lists.proxmox.com>; Tue, 19 Jan 2021 12:04:48 +0100 (CET)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 6DF474607B
for <pbs-devel@lists.proxmox.com>; Tue, 19 Jan 2021 12:04:48 +0100 (CET)
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Date: Tue, 19 Jan 2021 12:04:47 +0100
Message-Id: <20210119110447.8281-1-d.csapak@proxmox.com>
X-Mailer: git-send-email 2.20.1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results: 0
AWL 0.268 Adjusted score from AWL reputation of From: address
KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/,
medium trust
SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record
SPF_PASS -0.001 SPF: sender matches SPF record
URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
information. [reader.rs]
Subject: [pbs-devel] [PATCH proxmox-backup] api2/reader: asyncify the reader
worker task
X-BeenThere: pbs-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Backup Server development discussion
<pbs-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pbs-devel>,
<mailto:pbs-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pbs-devel/>
List-Post: <mailto:pbs-devel@lists.proxmox.com>
List-Help: <mailto:pbs-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel>,
<mailto:pbs-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Tue, 19 Jan 2021 11:04:50 -0000
this way, the code is much more readable
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
src/api2/reader.rs | 64 +++++++++++++++++++++-------------------------
1 file changed, 29 insertions(+), 35 deletions(-)
diff --git a/src/api2/reader.rs b/src/api2/reader.rs
index 72b6e33a..224a78de 100644
--- a/src/api2/reader.rs
+++ b/src/api2/reader.rs
@@ -113,7 +113,9 @@ fn upgrade_to_backup_reader_protocol(
let worker_id = format!("{}:{}/{}/{:08X}", store, backup_type, backup_id, backup_dir.backup_time());
- WorkerTask::spawn("reader", Some(worker_id), auth_id.clone(), true, move |worker| {
+ WorkerTask::spawn("reader", Some(worker_id), auth_id.clone(), true, move |worker| async move {
+ let _guard = _guard;
+
let mut env = ReaderEnvironment::new(
env_type,
auth_id,
@@ -128,42 +130,34 @@ fn upgrade_to_backup_reader_protocol(
let service = H2Service::new(env.clone(), worker.clone(), &READER_API_ROUTER, debug);
- let abort_future = worker.abort_future();
-
- let req_fut = hyper::upgrade::on(Request::from_parts(parts, req_body))
- .map_err(Error::from)
- .and_then({
- let env = env.clone();
- move |conn| {
- env.debug("protocol upgrade done");
-
- let mut http = hyper::server::conn::Http::new();
- http.http2_only(true);
- // increase window size: todo - find optiomal size
- let window_size = 32*1024*1024; // max = (1 << 31) - 2
- http.http2_initial_stream_window_size(window_size);
- http.http2_initial_connection_window_size(window_size);
- http.http2_max_frame_size(4*1024*1024);
-
- http.serve_connection(conn, service)
- .map_err(Error::from)
- }
- });
- let abort_future = abort_future
+ let mut abort_future = worker.abort_future()
.map(|_| Err(format_err!("task aborted")));
- use futures::future::Either;
- futures::future::select(req_fut, abort_future)
- .map(move |res| {
- let _guard = _guard;
- match res {
- Either::Left((Ok(res), _)) => Ok(res),
- Either::Left((Err(err), _)) => Err(err),
- Either::Right((Ok(res), _)) => Ok(res),
- Either::Right((Err(err), _)) => Err(err),
- }
- })
- .map_ok(move |_| env.log("reader finished successfully"))
+ let env2 = env.clone();
+ let req_fut = async move {
+ let conn = hyper::upgrade::on(Request::from_parts(parts, req_body)).await?;
+ env2.debug("protocol upgrade done");
+
+ let mut http = hyper::server::conn::Http::new();
+ http.http2_only(true);
+ // increase window size: todo - find optiomal size
+ let window_size = 32*1024*1024; // max = (1 << 31) - 2
+ http.http2_initial_stream_window_size(window_size);
+ http.http2_initial_connection_window_size(window_size);
+ http.http2_max_frame_size(4*1024*1024);
+
+ http.serve_connection(conn, service)
+ .map_err(Error::from).await
+ };
+
+ futures::select!{
+ req = req_fut.fuse() => req?,
+ abort = abort_future => abort?,
+ };
+
+ env.log("reader finished successfully");
+
+ Ok(())
})?;
let response = Response::builder()
--
2.20.1