From 9d6088ab808a4cf66babef9500da4331fc503574 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Wed, 29 May 2019 11:40:36 -0700 Subject: [PATCH] Added revalidate_policy config. This allows resources to be validated prior to every app launch instead of just after update. Also fixed some erroneous logging. --- CHANGELOG.md | 5 ++++ .../threerings/getdown/data/Application.java | 24 +++++++++---------- .../com/threerings/getdown/util/Config.java | 14 +++++++++++ .../threerings/getdown/launcher/Getdown.java | 16 +++++++------ 4 files changed, 40 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0b2310..9dc6b9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,11 @@ without a proxy, it does so for that session, but retains the proxy config for future sessions in which the proxy may again be needed. +* Added `revalidate_policy` config to control when Getdown revalidates resources (by hashing them + and comparing that hash to the values in `digest.txt`). The default, `after_update`, only + validates resources after the app is updated. A new mode, `always`, validates resources prior to + every application launch. + ## 1.8.4 - May 14, 2019 * Added `verify_timeout` config to allow customization of the default (60 second) timeout during diff --git a/core/src/main/java/com/threerings/getdown/data/Application.java b/core/src/main/java/com/threerings/getdown/data/Application.java index 80ea812..04bd3c3 100644 --- a/core/src/main/java/com/threerings/getdown/data/Application.java +++ b/core/src/main/java/com/threerings/getdown/data/Application.java @@ -636,21 +636,18 @@ public class Application } } - // determine whether we want strict comments + // read some miscellaneous configurations _strictComments = config.getBoolean("strict_comments"); - - // determine whether we want to allow offline operation (defaults to false) _allowOffline = config.getBoolean("allow_offline"); + _revalidatePolicy = config.getEnum( + "revalidate_policy", RevalidatePolicy.class, RevalidatePolicy.AFTER_UPDATE); + int tpSize = SysProps.threadPoolSize(); + _maxConcDownloads = Math.max(1, config.getInt("max_concurrent_downloads", tpSize)); + _verifyTimeout = config.getInt("verify_timeout", 60); // whether to cache code resources and launch from cache _useCodeCache = config.getBoolean("use_code_cache"); _codeCacheRetentionDays = config.getInt("code_cache_retention_days", 7); - - // maximum simultaneous downloads - _maxConcDownloads = Math.max(1, config.getInt("max_concurrent_downloads", - SysProps.threadPoolSize())); - - _verifyTimeout = config.getInt("verify_timeout", 60); } /** @@ -1361,14 +1358,14 @@ public class Application unpacked.addAll(unpackedAsync); long complete = System.currentTimeMillis(); - log.info("Verified resources", "count", rsrcs.size(), "size", (totalSize/1024) + "k", - "duration", (complete-start) + "ms"); + log.info("Verified resources", "count", rsrcs.size(), "alreadyValid", alreadyValid[0], + "size", (totalSize/1024) + "k", "duration", (complete-start) + "ms"); } private void verifyResource (Resource rsrc, ProgressObserver obs, int[] alreadyValid, Set unpacked, Set toInstall, Set toDownload) { - if (rsrc.isMarkedValid()) { + if (_revalidatePolicy != RevalidatePolicy.ALWAYS && rsrc.isMarkedValid()) { if (alreadyValid != null) { alreadyValid[0]++; } @@ -1765,6 +1762,7 @@ public class Application protected int _verifyTimeout = 60; + protected RevalidatePolicy _revalidatePolicy = RevalidatePolicy.AFTER_UPDATE; protected boolean _useCodeCache; protected int _codeCacheRetentionDays; @@ -1790,4 +1788,6 @@ public class Application protected static final String ENV_VAR_PREFIX = "%ENV."; protected static final Pattern ENV_VAR_PATTERN = Pattern.compile("%ENV\\.(.*?)%"); + + protected static enum RevalidatePolicy { ALWAYS, AFTER_UPDATE } } diff --git a/core/src/main/java/com/threerings/getdown/util/Config.java b/core/src/main/java/com/threerings/getdown/util/Config.java index 5c0b65e..2978fdf 100644 --- a/core/src/main/java/com/threerings/getdown/util/Config.java +++ b/core/src/main/java/com/threerings/getdown/util/Config.java @@ -247,6 +247,20 @@ public class Config return Boolean.parseBoolean(getString(name)); } + /** + * Returns the specified config value as an enum value. The string value of the config is + * converted to all upper case and then turned into an enum via {@link Enum#valueOf}. + */ + public > T getEnum (String name, Class eclass, T defval) { + String value = getString(name, defval.toString()); + try { + return Enum.valueOf(eclass, value.toUpperCase()); + } catch (Exception e) { + log.warning("Invalid value for '" + name + "' config: '" + value + "'."); + return defval; + } + } + /** * Massages a single string into an array and leaves existing array values as is. Simplifies * access to parameters that are expected to be arrays. diff --git a/launcher/src/main/java/com/threerings/getdown/launcher/Getdown.java b/launcher/src/main/java/com/threerings/getdown/launcher/Getdown.java index 794e3d6..d5abb09 100644 --- a/launcher/src/main/java/com/threerings/getdown/launcher/Getdown.java +++ b/launcher/src/main/java/com/threerings/getdown/launcher/Getdown.java @@ -129,7 +129,7 @@ public abstract class Getdown { if (SysProps.noInstall()) { log.info("Skipping install due to 'no_install' sysprop."); - } else if (_readyToInstall) { + } else if (isUpdateAvailable()) { log.info("Installing " + _toInstallResources.size() + " downloaded resources:"); for (Resource resource : _toInstallResources) { resource.install(true); @@ -260,13 +260,15 @@ public abstract class Getdown } } - try { - download(predownloads); - for (Resource rsrc : predownloads) { - rsrc.install(false); // install but don't validate yet + if (!predownloads.isEmpty()) { + try { + download(predownloads); + for (Resource rsrc : predownloads) { + rsrc.install(false); // install but don't validate yet + } + } catch (IOException ioe) { + log.warning("Failed to predownload resources. Continuing...", ioe); } - } catch (IOException ioe) { - log.warning("Failed to predownload resources. Continuing...", ioe); } }