summaryrefslogtreecommitdiffstats
path: root/services/sync/modules/stages
diff options
context:
space:
mode:
Diffstat (limited to 'services/sync/modules/stages')
-rw-r--r--services/sync/modules/stages/cluster.js6
-rw-r--r--services/sync/modules/stages/declined.js6
-rw-r--r--services/sync/modules/stages/enginesync.js147
3 files changed, 14 insertions, 145 deletions
diff --git a/services/sync/modules/stages/cluster.js b/services/sync/modules/stages/cluster.js
index 7665ce825..dd358bf98 100644
--- a/services/sync/modules/stages/cluster.js
+++ b/services/sync/modules/stages/cluster.js
@@ -4,7 +4,7 @@
this.EXPORTED_SYMBOLS = ["ClusterManager"];
-var {utils: Cu} = Components;
+const {utils: Cu} = Components;
Cu.import("resource://gre/modules/Log.jsm");
Cu.import("resource://services-sync/constants.js");
@@ -80,9 +80,6 @@ ClusterManager.prototype = {
return false;
}
- // Convert from the funky "String object with additional properties" that
- // resource.js returns to a plain-old string.
- cluster = cluster.toString();
// Don't update stuff if we already have the right cluster
if (cluster == this.service.clusterURL) {
return false;
@@ -90,6 +87,7 @@ ClusterManager.prototype = {
this._log.debug("Setting cluster to " + cluster);
this.service.clusterURL = cluster;
+ Svc.Prefs.set("lastClusterUpdate", Date.now().toString());
return true;
},
diff --git a/services/sync/modules/stages/declined.js b/services/sync/modules/stages/declined.js
index ff8a14181..b0877e929 100644
--- a/services/sync/modules/stages/declined.js
+++ b/services/sync/modules/stages/declined.js
@@ -11,7 +11,7 @@
this.EXPORTED_SYMBOLS = ["DeclinedEngines"];
-var {utils: Cu} = Components;
+const {utils: Cu} = Components;
Cu.import("resource://services-sync/constants.js");
Cu.import("resource://gre/modules/Log.jsm");
@@ -29,8 +29,8 @@ this.DeclinedEngines = function (service) {
}
this.DeclinedEngines.prototype = {
updateDeclined: function (meta, engineManager=this.service.engineManager) {
- let enabled = new Set(engineManager.getEnabled().map(e => e.name));
- let known = new Set(engineManager.getAll().map(e => e.name));
+ let enabled = new Set([e.name for each (e in engineManager.getEnabled())]);
+ let known = new Set([e.name for each (e in engineManager.getAll())]);
let remoteDeclined = new Set(meta.payload.declined || []);
let localDeclined = new Set(engineManager.getDeclined());
diff --git a/services/sync/modules/stages/enginesync.js b/services/sync/modules/stages/enginesync.js
index a00a2f48b..ed91adddb 100644
--- a/services/sync/modules/stages/enginesync.js
+++ b/services/sync/modules/stages/enginesync.js
@@ -8,16 +8,13 @@
this.EXPORTED_SYMBOLS = ["EngineSynchronizer"];
-var {utils: Cu} = Components;
+const {utils: Cu} = Components;
Cu.import("resource://gre/modules/Log.jsm");
Cu.import("resource://services-sync/constants.js");
Cu.import("resource://services-sync/engines.js");
Cu.import("resource://services-sync/policies.js");
Cu.import("resource://services-sync/util.js");
-Cu.import("resource://services-common/observers.js");
-Cu.import("resource://services-common/async.js");
-Cu.import("resource://gre/modules/Task.jsm");
/**
* Perform synchronization of engines.
@@ -34,7 +31,7 @@ this.EngineSynchronizer = function EngineSynchronizer(service) {
}
EngineSynchronizer.prototype = {
- sync: function sync(engineNamesToSync) {
+ sync: function sync() {
if (!this.onComplete) {
throw new Error("onComplete handler not installed.");
}
@@ -99,9 +96,6 @@ EngineSynchronizer.prototype = {
return;
}
- // We only honor the "hint" of what engines to Sync if this isn't
- // a first sync.
- let allowEnginesHint = false;
// Wipe data in the desired direction if necessary
switch (Svc.Prefs.get("firstSync")) {
case "resetClient":
@@ -113,9 +107,6 @@ EngineSynchronizer.prototype = {
case "wipeRemote":
this.service.wipeRemote(engineManager.enabledEngineNames);
break;
- default:
- allowEnginesHint = true;
- break;
}
if (this.service.clientsEngine.localCommands) {
@@ -145,31 +136,20 @@ EngineSynchronizer.prototype = {
try {
this._updateEnabledEngines();
} catch (ex) {
- this._log.debug("Updating enabled engines failed", ex);
+ this._log.debug("Updating enabled engines failed: " +
+ Utils.exceptionStr(ex));
this.service.errorHandler.checkServerError(ex);
this.onComplete(ex);
return;
}
- // If the engines to sync has been specified, we sync in the order specified.
- let enginesToSync;
- if (allowEnginesHint && engineNamesToSync) {
- this._log.info("Syncing specified engines", engineNamesToSync);
- enginesToSync = engineManager.get(engineNamesToSync).filter(e => e.enabled);
- } else {
- this._log.info("Syncing all enabled engines.");
- enginesToSync = engineManager.getEnabled();
- }
try {
- // We don't bother validating engines that failed to sync.
- let enginesToValidate = [];
- for (let engine of enginesToSync) {
+ for (let engine of engineManager.getEnabled()) {
// If there's any problems with syncing the engine, report the failure
if (!(this._syncEngine(engine)) || this.service.status.enforceBackoff) {
this._log.info("Aborting sync for failure in " + engine.name);
break;
}
- enginesToValidate.push(engine);
}
// If _syncEngine fails for a 401, we might not have a cluster URL here.
@@ -195,8 +175,6 @@ EngineSynchronizer.prototype = {
}
}
- Async.promiseSpinningly(this._tryValidateEngines(enginesToValidate));
-
// If there were no sync engine failures
if (this.service.status.service != SYNC_FAILED_PARTIAL) {
Svc.Prefs.set("lastSync", new Date().toString());
@@ -206,7 +184,7 @@ EngineSynchronizer.prototype = {
Svc.Prefs.reset("firstSync");
let syncTime = ((Date.now() - startTime) / 1000).toFixed(2);
- let dateStr = Utils.formatTimestamp(new Date());
+ let dateStr = new Date().toLocaleFormat(LOG_DATE_FORMAT);
this._log.info("Sync completed at " + dateStr
+ " after " + syncTime + " secs.");
}
@@ -214,106 +192,6 @@ EngineSynchronizer.prototype = {
this.onComplete(null);
},
- _tryValidateEngines: Task.async(function* (recentlySyncedEngines) {
- if (!Services.telemetry.canRecordBase || !Svc.Prefs.get("validation.enabled", false)) {
- this._log.info("Skipping validation: validation or telemetry reporting is disabled");
- return;
- }
-
- let lastValidation = Svc.Prefs.get("validation.lastTime", 0);
- let validationInterval = Svc.Prefs.get("validation.interval");
- let nowSeconds = Math.floor(Date.now() / 1000);
-
- if (nowSeconds - lastValidation < validationInterval) {
- this._log.info("Skipping validation: too recent since last validation attempt");
- return;
- }
- // Update the time now, even if we may return false still. We don't want to
- // check the rest of these more frequently than once a day.
- Svc.Prefs.set("validation.lastTime", nowSeconds);
-
- // Validation only occurs a certain percentage of the time.
- let validationProbability = Svc.Prefs.get("validation.percentageChance", 0) / 100.0;
- if (validationProbability < Math.random()) {
- this._log.info("Skipping validation: Probability threshold not met");
- return;
- }
- let maxRecords = Svc.Prefs.get("validation.maxRecords");
- if (!maxRecords) {
- // Don't bother asking the server for the counts if we know validation
- // won't happen anyway.
- return;
- }
-
- // maxRecords of -1 means "any number", so we can skip asking the server.
- // Used for tests.
- let info;
- if (maxRecords < 0) {
- info = {};
- for (let e of recentlySyncedEngines) {
- info[e.name] = 1; // needs to be < maxRecords
- }
- maxRecords = 2;
- } else {
-
- let collectionCountsURL = this.service.userBaseURL + "info/collection_counts";
- try {
- let infoResp = this.service._fetchInfo(collectionCountsURL);
- if (!infoResp.success) {
- this._log.error("Can't run validation: request to info/collection_counts responded with "
- + resp.status);
- return;
- }
- info = infoResp.obj; // might throw because obj is a getter which parses json.
- } catch (e) {
- // Not running validation is totally fine, so we just write an error log and return.
- this._log.error("Can't run validation: Caught error when fetching counts", e);
- return;
- }
- }
-
- if (!info) {
- return;
- }
-
- let engineLookup = new Map(recentlySyncedEngines.map(e => [e.name, e]));
- let toRun = [];
- for (let [engineName, recordCount] of Object.entries(info)) {
- let engine = engineLookup.get(engineName);
- if (recordCount > maxRecords || !engine) {
- this._log.debug(`Skipping validation for ${engineName} because it's not an engine or ` +
- `the number of records (${recordCount}) is greater than the maximum allowed (${maxRecords}).`);
- continue;
- }
- let validator = engine.getValidator();
- if (!validator) {
- continue;
- }
- // Put this in an array so that we know how many we're going to do, so we
- // don't tell users we're going to run some validators when we aren't.
- toRun.push({ engine, validator });
- }
-
- if (!toRun.length) {
- return;
- }
- Services.console.logStringMessage(
- "Sync is about to run a consistency check. This may be slow, and " +
- "can be controlled using the pref \"services.sync.validation.enabled\".\n" +
- "If you encounter any problems because of this, please file a bug.");
- for (let { validator, engine } of toRun) {
- try {
- let result = yield validator.validate(engine);
- Observers.notify("weave:engine:validate:finish", result, engine.name);
- } catch (e) {
- this._log.error(`Failed to run validation on ${engine.name}!`, e);
- Observers.notify("weave:engine:validate:error", e, engine.name)
- // Keep validating -- there's no reason to think that a failure for one
- // validator would mean the others will fail.
- }
- }
- }),
-
// Returns true if sync should proceed.
// false / no return value means sync should be aborted.
_syncEngine: function _syncEngine(engine) {
@@ -346,15 +224,8 @@ EngineSynchronizer.prototype = {
// If we're the only client, and no engines are marked as enabled,
// thumb our noses at the server data: it can't be right.
// Belt-and-suspenders approach to Bug 615926.
- let hasEnabledEngines = false;
- for (let e in meta.payload.engines) {
- if (e != "clients") {
- hasEnabledEngines = true;
- break;
- }
- }
-
- if ((numClients <= 1) && !hasEnabledEngines) {
+ if ((numClients <= 1) &&
+ ([e for (e in meta.payload.engines) if (e != "clients")].length == 0)) {
this._log.info("One client and no enabled engines: not touching local engine status.");
return;
}
@@ -418,7 +289,7 @@ EngineSynchronizer.prototype = {
}
// Any remaining engines were either enabled locally or disabled remotely.
- for (let engineName of enabled) {
+ for each (let engineName in enabled) {
let engine = engineManager.get(engineName);
if (Svc.Prefs.get("engineStatusChanged." + engine.prefName, false)) {
this._log.trace("The " + engineName + " engine was enabled locally.");