Bug 1546752 - Stop creating, writing, and reading the .metadata file in QuotaManager except the upgrades; r=janv, a=jcristau
authorTom Tung <shes050117@gmail.com>
Mon, 20 May 2019 14:13:27 +0000
changeset 533813 55da5150365dc92235e56b3c9717f432abc68270
parent 533812 985afd2f291041c4e794f300ab3a22ed641166e9
child 533814 3af73765ec38e4b930a2868fbb765186fe3d359c
push id11435
push userjcristau@mozilla.com
push dateWed, 12 Jun 2019 14:26:08 +0000
treeherdermozilla-beta@06b935ea69b8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjanv, jcristau
bugs1546752
milestone68.0
Bug 1546752 - Stop creating, writing, and reading the .metadata file in QuotaManager except the upgrades; r=janv, a=jcristau 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));
@@ -3972,22 +3950,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;
@@ -5767,19 +5740,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))) {
@@ -5793,19 +5767,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;
@@ -8595,19 +8570,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();
 }