Skip to content

Commit

Permalink
apps: Make sure app fetch check is done once
Browse files Browse the repository at this point in the history
Make sure that the check whether app is fetched is performed only once
during a single update cycle.

- If app is not running then don't check if it is fetched since it going
  to be re-updated anyway which implies checking for missing app blobs
  and pulling them if any.

- If app is enabled for running and is running but not fetched then
  there is no need to check whether it is fetched during checking
  "reset" apps.

Signed-off-by: Mike Sul <[email protected]>
  • Loading branch information
mike-sul committed Dec 3, 2024
1 parent 25ac4f6 commit f9170de
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
24 changes: 19 additions & 5 deletions src/composeappmanager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ ComposeAppManager::AppsContainer ComposeAppManager::getApps(const Uptane::Target
}

ComposeAppManager::AppsContainer ComposeAppManager::getAppsToUpdate(const Uptane::Target& t,
AppsSyncReason& apps_and_reasons) const {
AppsSyncReason& apps_and_reasons,
std::set<std::string>& fetched_apps) const {
AppsContainer apps_to_update;

auto currently_installed_target_apps = Target::appsJson(OstreeManager::getCurrent());
Expand Down Expand Up @@ -244,16 +245,18 @@ ComposeAppManager::AppsContainer ComposeAppManager::getAppsToUpdate(const Uptane
LOG_INFO << app_name << " is not fully fetched; missing blobs will be fetched";
continue;
}
fetched_apps.insert(app_name);
}

return apps_to_update;
}

ComposeAppManager::AppsSyncReason ComposeAppManager::checkForAppsToUpdate(const Uptane::Target& target) {
AppsSyncReason apps_and_reasons;
cur_apps_to_fetch_and_update_ = getAppsToUpdate(target, apps_and_reasons);
std::set<std::string> fetched_apps;
cur_apps_to_fetch_and_update_ = getAppsToUpdate(target, apps_and_reasons, fetched_apps);
if (!!cfg_.reset_apps) {
cur_apps_to_fetch_ = getAppsToFetch(target);
cur_apps_to_fetch_ = getAppsToFetch(target, true, &cur_apps_to_fetch_and_update_, &fetched_apps);
}
are_apps_checked_ = true;
for (const auto& app : cur_apps_to_fetch_) {
Expand Down Expand Up @@ -718,15 +721,26 @@ ComposeAppManager::AppsContainer ComposeAppManager::getRequiredApps(const Config
return apps;
}

ComposeAppManager::AppsContainer ComposeAppManager::getAppsToFetch(const Uptane::Target& target,
bool check_store) const {
ComposeAppManager::AppsContainer ComposeAppManager::getAppsToFetch(const Uptane::Target& target, bool check_store,
const AppsContainer* checked_apps,
const std::set<std::string>* fetched_apps) const {
auto enabled_apps{getRequiredApps(cfg_, target)};
if (!check_store) {
return enabled_apps;
}

AppsContainer apps_to_be_fetched;
for (const auto& app : enabled_apps) {
if (checked_apps != nullptr && checked_apps->count(app.first) > 0) {
// no reason to check whether app is fetched since app is checked and marked for update because
// it is either not installed or not running;
continue;
}
if (fetched_apps != nullptr && fetched_apps->count(app.first) > 0) {
// no reason to check whether app is fetched since this check was already done before because this
// app is enabled for running.
continue;
}
if (!app_engine_->isFetched({app.first, app.second})) {
apps_to_be_fetched.insert(app);
}
Expand Down
8 changes: 6 additions & 2 deletions src/composeappmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <functional>
#include <memory>
#include <set>
#include <unordered_map>

#include "docker/composeappengine.h"
Expand Down Expand Up @@ -59,7 +60,8 @@ class ComposeAppManager : public RootfsTreeManager {
// Returns an intersection of Target's Apps and Apps listed in the config (sota.toml:compose_apps)
// If Apps are not specified in the config then all Target's Apps are returned
AppsContainer getApps(const Uptane::Target& t) const;
AppsContainer getAppsToUpdate(const Uptane::Target& t, AppsSyncReason& apps_and_reasons) const;
AppsContainer getAppsToUpdate(const Uptane::Target& t, AppsSyncReason& apps_and_reasons,
std::set<std::string>& fetched_apps) const;
AppsSyncReason checkForAppsToUpdate(const Uptane::Target& target);
void setAppsNotChecked() { are_apps_checked_ = false; }
void handleRemovedApps(const Uptane::Target& target) const;
Expand All @@ -72,7 +74,9 @@ class ComposeAppManager : public RootfsTreeManager {
Json::Value getRunningAppsInfo() const;
std::string getRunningAppsInfoForReport() const;

AppsContainer getAppsToFetch(const Uptane::Target& target, bool check_store = true) const;
AppsContainer getAppsToFetch(const Uptane::Target& target, bool check_store = true,
const AppsContainer* checked_apps = nullptr,
const std::set<std::string>* fetched_apps = nullptr) const;
void stopDisabledComposeApps(const Uptane::Target& target) const;
void removeDisabledComposeApps(const Uptane::Target& target) const;
void forEachRemovedApp(const Uptane::Target& target,
Expand Down

0 comments on commit f9170de

Please sign in to comment.