Bug 1546752 - Stop creating, writing, and reading the .metadata file in QuotaManager except the upgrades; r=janv
authorTom Tung <shes050117@gmail.com>
Mon, 20 May 2019 14:13:27 +0000
changeset 474523 29bdbbe89264b91d1bd4205c45536c9222a8d6ee
parent 474522 5f89081950bb50636258a00cfa0d8c4e18414d68
child 474524 c77c46ac90a55891e1f67ff18fb16029883cc0e6
child 474727 300a6bb3a0a6196ed15f95625ba5f94f2eff7d54
push id36041
push userccoroiu@mozilla.com
push dateMon, 20 May 2019 21:55:28 +0000
treeherdermozilla-central@29bdbbe89264 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjanv
bugs1546752
milestone69.0a1
first release with
nightly linux32
29bdbbe89264 / 69.0a1 / 20190520215528 / files
nightly linux64
29bdbbe89264 / 69.0a1 / 20190520215528 / files
nightly mac
29bdbbe89264 / 69.0a1 / 20190520215528 / files
nightly win32
29bdbbe89264 / 69.0a1 / 20190520215528 / files
nightly win64
29bdbbe89264 / 69.0a1 / 20190520215528 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1546752 - Stop creating, writing, and reading the .metadata file in QuotaManager except the upgrades; r=janv The main goal of this issue is to reduce IO during the storage initialization and stop creating .metadata file since we already have .metadata-v2 file to track the information for the origin directory. Therefore, this patch only stop create, write, and read the .metadata file. And, leaving the work for removing it to the next minor upgrade. Differential Revision: https://phabricator.services.mozilla.com/D28824
dom/quota/ActorsParent.cpp
dom/quota/test/unit/test_basics.js
--- a/dom/quota/ActorsParent.cpp
+++ b/dom/quota/ActorsParent.cpp
@@ -2248,38 +2248,16 @@ nsresult CreateDirectoryMetadata2(nsIFil
   rv = file->RenameTo(nullptr, NS_LITERAL_STRING(METADATA_V2_FILE_NAME));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   return NS_OK;
 }
 
-nsresult CreateDirectoryMetadataFiles(nsIFile* aDirectory, bool aPersisted,
-                                      const nsACString& aSuffix,
-                                      const nsACString& aGroup,
-                                      const nsACString& aOrigin,
-                                      int64_t aTimestamp) {
-  AssertIsOnIOThread();
-
-  nsresult rv =
-      CreateDirectoryMetadata(aDirectory, aTimestamp, aSuffix, aGroup, aOrigin);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  rv = CreateDirectoryMetadata2(aDirectory, aTimestamp, aPersisted, aSuffix,
-                                aGroup, aOrigin);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  return NS_OK;
-}
-
 nsresult GetBinaryInputStream(nsIFile* aDirectory, const nsAString& aFilename,
                               nsIBinaryInputStream** aStream) {
   MOZ_ASSERT(!NS_IsMainThread());
   MOZ_ASSERT(aDirectory);
   MOZ_ASSERT(aStream);
 
   nsCOMPtr<nsIFile> file;
   nsresult rv = aDirectory->Clone(getter_AddRefs(file));
@@ -3981,22 +3959,17 @@ nsresult QuotaManager::GetDirectoryMetad
       return rv;
     }
 
     nsCString upToDateGroup = baseDomain + suffix;
 
     if (group != upToDateGroup) {
       group = upToDateGroup;
 
-      rv =
-          CreateDirectoryMetadata(aDirectory, timestamp, suffix, group, origin);
-      if (NS_WARN_IF(NS_FAILED(rv))) {
-        return rv;
-      }
-
+      // Only creating .metadata-v2 to reduce IO.
       rv = CreateDirectoryMetadata2(aDirectory, timestamp, persisted, suffix,
                                     group, origin);
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
 
 #ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
       ContentPrincipalInfo contentPrincipalInfo;
@@ -5768,19 +5741,20 @@ nsresult QuotaManager::EnsureOriginIsIni
     return rv;
   }
 
   int64_t timestamp;
   if (aPersistenceType == PERSISTENCE_TYPE_PERSISTENT) {
     if (created) {
       timestamp = PR_Now();
 
-      rv = CreateDirectoryMetadataFiles(directory,
-                                        /* aPersisted */ true, aSuffix, aGroup,
-                                        aOrigin, timestamp);
+      // Only creating .metadata-v2 to reduce IO.
+      rv = CreateDirectoryMetadata2(directory, timestamp,
+                                    /* aPersisted */ true, aSuffix, aGroup,
+                                    aOrigin);
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
     } else {
       rv = GetDirectoryMetadata2WithRestore(directory,
                                             /* aPersistent */ true, &timestamp,
                                             /* aPersisted */ nullptr);
       if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -5794,19 +5768,20 @@ nsresult QuotaManager::EnsureOriginIsIni
                           /* aPersisted */ true, directory);
     NS_ENSURE_SUCCESS(rv, rv);
 
     mInitializedOrigins.AppendElement(aOrigin);
   } else if (created) {
     NoteOriginDirectoryCreated(aPersistenceType, aGroup, aOrigin,
                                /* aPersisted */ false, timestamp);
 
-    rv = CreateDirectoryMetadataFiles(directory,
-                                      /* aPersisted */ false, aSuffix, aGroup,
-                                      aOrigin, timestamp);
+    // Only creating .metadata-v2 to reduce IO.
+    rv = CreateDirectoryMetadata2(directory, timestamp,
+                                  /* aPersisted */ false, aSuffix, aGroup,
+                                  aOrigin);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   }
 
   directory.forget(aDirectory);
   *aCreated = created;
   return NS_OK;
@@ -8588,19 +8563,18 @@ nsresult PersistOp::DoDirectoryWork(Quot
     if (aQuotaManager->IsTemporaryStorageInitialized()) {
       aQuotaManager->NoteOriginDirectoryCreated(
           mPersistenceType.Value(), mGroup, mOriginScope.GetOrigin(),
           /* aPersisted */ true, timestamp);
     } else {
       timestamp = PR_Now();
     }
 
-    rv = CreateDirectoryMetadataFiles(directory,
-                                      /* aPersisted */ true, mSuffix, mGroup,
-                                      mOriginScope.GetOrigin(), timestamp);
+    rv = CreateDirectoryMetadata2(directory, timestamp, /* aPersisted */ true,
+                                  mSuffix, mGroup, mOriginScope.GetOrigin());
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   } else {
     // Get the persisted flag (restore the metadata file if necessary).
     bool persisted;
     rv = aQuotaManager->GetDirectoryMetadata2WithRestore(
         directory,
--- a/dom/quota/test/unit/test_basics.js
+++ b/dom/quota/test/unit/test_basics.js
@@ -7,32 +7,32 @@ var testGenerator = testSteps();
 
 function* testSteps()
 {
   const storageFile = "storage.sqlite";
 
   const metadataFiles = [
     {
       path: "storage/permanent/chrome/.metadata",
-      tmp: false
+      shouldExistAfterInit: false
     },
 
     {
       path: "storage/permanent/chrome/.metadata-tmp",
-      tmp: true
+      shouldExistAfterInit: false
     },
 
     {
       path: "storage/permanent/chrome/.metadata-v2",
-      tmp: false
+      shouldExistAfterInit: true
     },
 
     {
       path: "storage/permanent/chrome/.metadata-v2-tmp",
-      tmp: true
+      shouldExistAfterInit: false
     }
   ]
 
   info("Clearing");
 
   clear(continueToNextStepSync);
   yield undefined;
 
@@ -89,17 +89,17 @@ function* testSteps()
 
   ok(request.result, "Origin directory was created");
 
   for (let metadataFile of metadataFiles) {
     file = getRelativeFile(metadataFile.path);
 
     exists = file.exists();
 
-    if (metadataFile.tmp) {
+    if (metadataFile.shouldExistAfterInit) {
+      ok(exists, "Metadata file does exist");
+    } else {
       ok(!exists, "Metadata file doesn't exist");
-    } else {
-      ok(exists, "Metadata file does exist");
     }
   }
 
   finishTest();
 }