Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: More logging for ongoing and get_backup #4289

Merged
merged 2 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ enum RunningState {
Running { cancel_sender: Sender<()> },

/// Cancel signal has been sent, waiting for ongoing process to be freed.
ShallStop,
ShallStop { request: Instant },
Copy link
Collaborator

@link2xt link2xt Apr 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to use SystemTime here, because we are interested in a wall clock time. Instant pauses on Android when the app goes to doze.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tough if the app goes to doze does it still execute? I want to know how long it takes to get here in application time, not in wall clock time.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an issue: rust-lang/rust#71860

This is not doing what is expected, this clock is good for comparing timestamps in a build system but not for measuring time.


/// There is no ongoing process, a new one can be allocated.
Stopped,
Expand Down Expand Up @@ -530,6 +530,9 @@ impl Context {

pub(crate) async fn free_ongoing(&self) {
let mut s = self.running_state.write().await;
if let RunningState::ShallStop { request } = *s {
info!(self, "Ongoing stopped in {:?}", request.elapsed());
}
*s = RunningState::Stopped;
}

Expand All @@ -542,9 +545,11 @@ impl Context {
warn!(self, "could not cancel ongoing: {:#}", err);
}
info!(self, "Signaling the ongoing process to stop ASAP.",);
*s = RunningState::ShallStop;
*s = RunningState::ShallStop {
request: Instant::now(),
};
}
RunningState::ShallStop | RunningState::Stopped => {
RunningState::ShallStop { .. } | RunningState::Stopped => {
info!(self, "No ongoing process to stop.",);
}
}
Expand All @@ -554,7 +559,7 @@ impl Context {
pub(crate) async fn shall_stop_ongoing(&self) -> bool {
match &*self.running_state.read().await {
RunningState::Running { .. } => false,
RunningState::ShallStop | RunningState::Stopped => true,
RunningState::ShallStop { .. } | RunningState::Stopped => true,
}
}

Expand Down
10 changes: 7 additions & 3 deletions src/imex/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use tokio_util::sync::CancellationToken;
use crate::blob::BlobDirContents;
use crate::chat::delete_and_reset_all_device_msgs;
use crate::context::Context;
use crate::qr::Qr;
use crate::qr::{self, Qr};
use crate::{e2ee, EventType};

use super::{export_database, DBFILE_BACKUP_NAME};
Expand Down Expand Up @@ -386,10 +386,14 @@ pub async fn get_backup(context: &Context, qr: Qr) -> Result<()> {
!context.is_configured().await?,
"Cannot import backups to accounts in use."
);
let _guard = context.scheduler.pause(context.clone()).await;

// Acquire global "ongoing" mutex.
let cancel_token = context.alloc_ongoing().await?;
let _guard = context.scheduler.pause(context.clone()).await;
info!(
context,
"Running get_backup for {}",
qr::format_backup(&qr)?
);
let res = tokio::select! {
biased;
res = get_backup_inner(context, qr) => res,
Expand Down