Bug 615926: attempt to avoid screwing up meta.
☠☠ backed out by 84fe21efcb57 ☠ ☠
authorRichard Newman <rnewman@mozilla.com>
Mon, 06 Dec 2010 14:22:09 -0800
changeset 58758 183be003b3126d6e355e4042178c0fb70e85d57d
parent 58757 faa6ce5a0a20cd74597e297220cff7654a65ebdb
child 58759 d2fd62ffd88e9c81bfe0271303a0e9f54cc51071
push id17416
push userpweitershausen@mozilla.com
push dateTue, 07 Dec 2010 07:05:47 +0000
treeherdermozilla-central@4d16d58becaf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs615926
Bug 615926: attempt to avoid screwing up meta.
services/sync/modules/service.js
--- a/services/sync/modules/service.js
+++ b/services/sync/modules/service.js
@@ -1057,27 +1057,50 @@ WeaveSvc.prototype = {
 
   // Stuff we need to do after login, before we can really do
   // anything (e.g. key setup).
   _remoteSetup: function WeaveSvc__remoteSetup(infoResponse) {
     let reset = false;
 
     this._log.debug("Fetching global metadata record");
     let meta = Records.get(this.metaURL);
+    
+    // Checking modified time of the meta record.
+    if (infoResponse &&
+        (infoResponse.obj.meta != this.metaModified) &&
+        !meta.isNew) {
+      
+      // Delete the cached meta record...
+      this._log.debug("Clearing cached meta record. metaModified is " +
+          JSON.stringify(this.metaModified) + ", setting to " +
+          JSON.stringify(info.obj.meta));
+      Records.del(this.metaURL);
+      
+      // ... fetch the current record from the server, and COPY THE FLAGS.
+      let newMeta       = Records.get(this.metaURL);
+      newMeta.isNew     = meta.isNew;
+      newMeta.changed   = meta.changed;
+      
+      // Switch in the new meta object and record the new time.
+      meta              = newMeta;
+      this.metaModified = info.obj.meta;
+    }
 
     let remoteVersion = (meta && meta.payload.storageVersion)?
       meta.payload.storageVersion : "";
 
     this._log.debug(["Weave Version:", WEAVE_VERSION, "Local Storage:",
       STORAGE_VERSION, "Remote Storage:", remoteVersion].join(" "));
 
     // Check for cases that require a fresh start. When comparing remoteVersion,
     // we need to convert it to a number as older clients used it as a string.
     if (!meta || !meta.payload.storageVersion || !meta.payload.syncID ||
         STORAGE_VERSION > parseFloat(remoteVersion)) {
+      
+      this._log.info("One of: no meta, no meta storageVersion, or no meta syncID. Fresh start needed.");
 
       // abort the server wipe if the GET status was anything other than 404 or 200
       let status = Records.response.status;
       if (status != 200 && status != 404) {
         this._checkServerError(Records.response);
         Status.sync = METARECORD_DOWNLOAD_FAIL;
         this._log.warn("Unknown error while downloading metadata record. " +
                        "Aborting sync.");
@@ -1103,16 +1126,18 @@ WeaveSvc.prototype = {
       return true;
     }
     else if (remoteVersion > STORAGE_VERSION) {
       Status.sync = VERSION_OUT_OF_DATE;
       this._log.warn("Upgrade required to access newer storage version.");
       return false;
     }
     else if (meta.payload.syncID != this.syncID) {
+      
+      this._log.info("Sync IDs differ. Local is " + this.syncID + ", remote is " + meta.payload.syncID);
       this.resetClient();
       this.syncID = meta.payload.syncID;
       this._log.debug("Clear cached values and take syncId: " + this.syncID);
 
       if (!this.upgradeSyncKey(meta.payload.syncID)) {
         this._log.warn("Failed to upgrade sync key. Failing remote setup.");
         return false;
       }
@@ -1403,26 +1428,16 @@ WeaveSvc.prototype = {
     // Figure out what the last modified time is for each collection
     let info = this._fetchInfo(infoURL, true);
     this.globalScore = 0;
 
     // Convert the response to an object and read out the modified times
     for each (let engine in [Clients].concat(Engines.getAll()))
       engine.lastModified = info.obj[engine.name] || 0;
 
-    // If the modified time of the meta record ever changes, clear the cache.
-    // ... unless meta is marked as new.
-    if ((info.obj.meta != this.metaModified) && !Records.get(this.metaURL).isNew) {
-      this._log.debug("Clearing cached meta record. metaModified is " +
-          JSON.stringify(this.metaModified) + ", setting to " +
-          JSON.stringify(info.obj.meta));
-      Records.del(this.metaURL);
-      this.metaModified = info.obj.meta;
-    }
-
     if (!(this._remoteSetup(info)))
       throw "aborting sync, remote setup failed";
 
     // Make sure we have an up-to-date list of clients before sending commands
     this._log.trace("Refreshing client list");
     this._syncEngine(Clients);
 
     // Wipe data in the desired direction if necessary