Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
Support pause/resume in single-transaction downloads
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Gerasimov <[email protected]>
  • Loading branch information
Anton Gerasimov committed Dec 11, 2018
1 parent fdff394 commit d810a39
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/libaktualizr/primary/aktualizr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ void Aktualizr::AddSecondary(const std::shared_ptr<Uptane::SecondaryInterface> &

void Aktualizr::Shutdown() {
if (!shutdown_) {
uptane_client_->pause();
shutdown_ = true;
api_queue_.shutDown();
}
Expand Down
14 changes: 9 additions & 5 deletions src/libaktualizr/primary/aktualizr_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void process_events_FullNoUpdates(const std::shared_ptr<event::BaseEvent>& event
FAIL();
default:
std::cout << "event #" << num_events_FullNoUpdates << " is: " << event->variant << "\n";
EXPECT_EQ(event->variant, "");
EXPECT_TRUE((event->variant == "") || (event->variant == "DownloadPaused"));
}
++num_events_FullNoUpdates;
}
Expand Down Expand Up @@ -234,7 +234,7 @@ void process_events_FullWithUpdates(const std::shared_ptr<event::BaseEvent>& eve
FAIL();
default:
std::cout << "event #" << num_events_FullWithUpdates << " is: " << event->variant << "\n";
EXPECT_EQ(event->variant, "");
EXPECT_TRUE((event->variant == "") || (event->variant == "DownloadPaused"));
}
++num_events_FullWithUpdates;
}
Expand Down Expand Up @@ -422,11 +422,15 @@ void process_events_FullMultipleSecondaries(const std::shared_ptr<event::BaseEve
allcomplete_FullMultipleSecondaries = true;
} else if (event->variant == "PutManifestComplete") {
manifest_FullMultipleSecondaries = true;
} else if (event->variant == "DownloadPaused") {
// phony event on shutdown, ignore
return;
}
// It is possible for the PutManifestComplete to come before we get the
// InstallTargetComplete depending on the threading, so check for both.
if (allcomplete_FullMultipleSecondaries && complete_FullMultipleSecondaries == 2 &&
manifest_FullMultipleSecondaries) {
LOG_ERROR << "SETVALUE";
promise_FullMultipleSecondaries.set_value();
}
}
Expand Down Expand Up @@ -504,7 +508,7 @@ void process_events_CheckWithUpdates(const std::shared_ptr<event::BaseEvent>& ev
FAIL();
default:
std::cout << "event #" << num_events_CheckWithUpdates << " is: " << event->variant << "\n";
EXPECT_EQ(event->variant, "");
EXPECT_TRUE((event->variant == "") || (event->variant == "DownloadPaused"));
}
++num_events_CheckWithUpdates;
}
Expand Down Expand Up @@ -589,7 +593,7 @@ void process_events_DownloadWithUpdates(const std::shared_ptr<event::BaseEvent>&
FAIL();
default:
std::cout << "event #" << num_events_DownloadWithUpdates << " is: " << event->variant << "\n";
EXPECT_EQ(event->variant, "");
EXPECT_TRUE((event->variant == "") || (event->variant == "DownloadPaused"));
}
++num_events_DownloadWithUpdates;
}
Expand Down Expand Up @@ -731,7 +735,7 @@ void process_events_InstallWithUpdates(const std::shared_ptr<event::BaseEvent>&
FAIL();
default:
std::cout << "event #" << num_events_InstallWithUpdates << " is: " << event->variant << "\n";
EXPECT_EQ(event->variant, "");
EXPECT_TRUE((event->variant == "") || (event->variant == "DownloadPaused"));
}
++num_events_InstallWithUpdates;
}
Expand Down
11 changes: 10 additions & 1 deletion src/libaktualizr/uptane/fetcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,16 @@ bool Fetcher::fetchVerifyTarget(const Target& target) {
throw Exception("image", "Could not download file, error: " + response.error_message);
}
if (pause_) {
std::lock_guard<std::mutex> lock(*pause_mutex_);
// entering pause, save the file and free the handler
ds.fhandle->wcommit();
fhandle.reset();

std::lock_guard<std::mutex> lock(*pause_mutex_); // waiting on this mutex while paused

// exiting pause, restore the file context
auto target_handle = storage->openTargetFile(target);
fhandle = target_handle->toWriteHandle();
ds.fhandle = fhandle.get();
retry = true;
}
} while (retry);
Expand Down

0 comments on commit d810a39

Please sign in to comment.