Bug 948205 - Rename seer.sqlite (and fixup schema in the process). r=mcmanus r=vladan
authorNicholas Hurley <hurley@todesschaf.org>
Mon, 13 Jan 2014 17:57:46 -0800
changeset 163242 044a089451c8a4392ca05a53b1058d061952031e
parent 163233 b114534a9386a426a8e95075c15690fc2fb06750
child 163243 8e8caac4dba483149e565442db2a307177acbb47
push id25989
push usercbook@mozilla.com
push dateTue, 14 Jan 2014 14:44:35 +0000
treeherdermozilla-central@be9f41887791 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcmanus, vladan
bugs948205
milestone29.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 948205 - Rename seer.sqlite (and fixup schema in the process). r=mcmanus r=vladan
netwerk/base/src/Seer.cpp
netwerk/base/src/Seer.h
netwerk/test/unit/test_seer.js
toolkit/components/telemetry/Telemetry.cpp
--- a/netwerk/base/src/Seer.cpp
+++ b/netwerk/base/src/Seer.cpp
@@ -404,39 +404,60 @@ Seer::Init()
   NS_ENSURE_SUCCESS(rv, rv);
 
   mStorageService = do_GetService("@mozilla.org/storage/service;1", &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR,
                               getter_AddRefs(mDBFile));
   NS_ENSURE_SUCCESS(rv, rv);
-  rv = mDBFile->AppendNative(NS_LITERAL_CSTRING("seer.sqlite"));
+  rv = mDBFile->AppendNative(NS_LITERAL_CSTRING("netpredictions.sqlite"));
   NS_ENSURE_SUCCESS(rv, rv);
 
   mInitialized = true;
 
   return rv;
 }
 
+void
+Seer::CheckForAndDeleteOldDBFile()
+{
+  nsCOMPtr<nsIFile> oldDBFile;
+  nsresult rv = mDBFile->GetParent(getter_AddRefs(oldDBFile));
+  RETURN_IF_FAILED(rv);
+
+  rv = oldDBFile->AppendNative(NS_LITERAL_CSTRING("seer.sqlite"));
+  RETURN_IF_FAILED(rv);
+
+  bool oldFileExists = false;
+  rv = oldDBFile->Exists(&oldFileExists);
+  if (NS_FAILED(rv) || !oldFileExists) {
+    return;
+  }
+
+  oldDBFile->Remove(false);
+}
+
 // Make sure that our sqlite storage is all set up with all the tables we need
 // to do the work. It isn't the end of the world if this fails, since this is
 // all an optimization, anyway.
 
 nsresult
 Seer::EnsureInitStorage()
 {
   MOZ_ASSERT(!NS_IsMainThread(), "Initializing seer storage on main thread");
 
   if (mDB) {
     return NS_OK;
   }
 
   nsresult rv;
 
+  CheckForAndDeleteOldDBFile();
+
   rv = mStorageService->OpenDatabase(mDBFile, getter_AddRefs(mDB));
   if (NS_FAILED(rv)) {
     // Retry once by trashing the file and trying to open again. If this fails,
     // we can just bail, and hope for better luck next time.
     rv = mDBFile->Remove(false);
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = mStorageService->OpenDatabase(mDBFile, getter_AddRefs(mDB));
@@ -663,17 +684,17 @@ Seer::EnsureInitStorage()
   rv = mDB->ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("CREATE TABLE IF NOT EXISTS moz_redirects (\n"
                          "  id integer PRIMARY KEY AUTOINCREMENT,\n"
                          "  pid integer NOT NULL,\n"
                          "  uri TEXT NOT NULL,\n"
                          "  origin TEXT NOT NULL,\n"
                          "  hits INTEGER DEFAULT 0,\n"
                          "  last_hit INTEGER DEFAULT 0,\n"
-                         "  FOREIGN KEY(pid) REFERENCES moz_pages(id)\n"
+                         "  FOREIGN KEY(pid) REFERENCES moz_pages(id) ON DELETE CASCADE\n"
                          ");\n"));
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = mDB->ExecuteSimpleSQL(
       NS_LITERAL_CSTRING("CREATE INDEX IF NOT EXISTS redirect_pid_uri_index "
                          "ON moz_redirects (pid, uri);"));
   NS_ENSURE_SUCCESS(rv, rv);
 
--- a/netwerk/base/src/Seer.h
+++ b/netwerk/base/src/Seer.h
@@ -57,16 +57,17 @@ public:
 
 private:
   friend class SeerPredictionEvent;
   friend class SeerLearnEvent;
   friend class SeerResetEvent;
   friend class SeerPredictionRunner;
   friend class SeerDBShutdownRunner;
 
+  void CheckForAndDeleteOldDBFile();
   nsresult EnsureInitStorage();
 
   // This is a proxy for the information we need from an nsIURI
   struct UriInfo {
     nsAutoCString spec;
     nsAutoCString origin;
   };
 
--- a/netwerk/test/unit/test_seer.js
+++ b/netwerk/test/unit/test_seer.js
@@ -211,17 +211,17 @@ DnsContinueVerifier.prototype = {
     // This means that the seer has learned and done our "checkpoint" prediction
     // Now we can get on with the prediction we actually want to test
 
     // tstamp is 10 days older than now - just over 1 week, which will ensure we
     // hit our cutoff for dns vs. preconnect. This is all in usec, hence the
     // x1000 on the Date object value.
     var tstamp = (new Date().valueOf() * 1000) - (10 * 86400 * 1000000);
 
-    var dbfile = FileUtils.getFile("ProfD", ["seer.sqlite"]);
+    var dbfile = FileUtils.getFile("ProfD", ["netpredictions.sqlite"]);
     var dbconn = Services.storage.openDatabase(dbfile);
     // We also need to update hits, since the toplevel has been "loaded" a
     // second time (from the prediction that kicked off this callback) to ensure
     // that the seer will try to do anything for this subresource.
     var stmt = "UPDATE moz_subresources SET last_hit = " + tstamp + ", hits = 2 WHERE uri = '" + this.subresource + "';";
     dbconn.executeSimpleSQL(stmt);
     dbconn.close();
 
--- a/toolkit/components/telemetry/Telemetry.cpp
+++ b/toolkit/components/telemetry/Telemetry.cpp
@@ -949,18 +949,18 @@ mThreadHangStatsMutex("Telemetry::mThrea
 mCachedTelemetryData(false),
 mLastShutdownTime(0),
 mFailedLockCount(0)
 {
   // A whitelist to prevent Telemetry reporting on Addon & Thunderbird DBs
   const char *trackedDBs[] = {
     "addons.sqlite", "content-prefs.sqlite", "cookies.sqlite",
     "downloads.sqlite", "extensions.sqlite", "formhistory.sqlite",
-    "index.sqlite", "healthreport.sqlite", "permissions.sqlite",
-    "places.sqlite", "search.sqlite", "seer.sqlite", "signons.sqlite",
+    "index.sqlite", "healthreport.sqlite", "netpredictions.sqlite",
+    "permissions.sqlite", "places.sqlite", "search.sqlite", "signons.sqlite",
     "urlclassifier3.sqlite", "webappsstore.sqlite"
   };
 
   for (size_t i = 0; i < ArrayLength(trackedDBs); i++)
     mTrackedDBs.PutEntry(nsDependentCString(trackedDBs[i]));
 
 #ifdef DEBUG
   // Mark immutable to prevent asserts on simultaneous access from multiple threads