Title: [191354] trunk/Source/WebKit2
Revision
191354
Author
[email protected]
Date
2015-10-20 13:47:48 -0700 (Tue, 20 Oct 2015)

Log Message

Unreviewed, rolling out r191306.
https://bugs.webkit.org/show_bug.cgi?id=150371

"May have caused a significant warm PLT regression" (Requested
by cdumez_ on #webkit).

Reverted changeset:

"[WK2] Generalize NetworkCacheStorage API so it can store
different types of metadata"
https://bugs.webkit.org/show_bug.cgi?id=150221
http://trac.webkit.org/changeset/191306

Patch by Commit Queue <[email protected]> on 2015-10-20

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (191353 => 191354)


--- trunk/Source/WebKit2/ChangeLog	2015-10-20 20:42:01 UTC (rev 191353)
+++ trunk/Source/WebKit2/ChangeLog	2015-10-20 20:47:48 UTC (rev 191354)
@@ -1,3 +1,18 @@
+2015-10-20  Commit Queue  <[email protected]>
+
+        Unreviewed, rolling out r191306.
+        https://bugs.webkit.org/show_bug.cgi?id=150371
+
+        "May have caused a significant warm PLT regression" (Requested
+        by cdumez_ on #webkit).
+
+        Reverted changeset:
+
+        "[WK2] Generalize NetworkCacheStorage API so it can store
+        different types of metadata"
+        https://bugs.webkit.org/show_bug.cgi?id=150221
+        http://trac.webkit.org/changeset/191306
+
 2015-10-20  Tim Horton  <[email protected]>
 
         Try to fix the build by disabling MAC_GESTURE_EVENTS on 10.9 and 10.10

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp (191353 => 191354)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp	2015-10-20 20:42:01 UTC (rev 191353)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp	2015-10-20 20:47:48 UTC (rev 191354)
@@ -39,7 +39,6 @@
 #include <WebCore/ResourceRequest.h>
 #include <WebCore/ResourceResponse.h>
 #include <WebCore/SharedBuffer.h>
-#include <wtf/MainThread.h>
 #include <wtf/NeverDestroyed.h>
 #include <wtf/RunLoop.h>
 #include <wtf/text/StringBuilder.h>
@@ -51,13 +50,6 @@
 namespace WebKit {
 namespace NetworkCache {
 
-static const AtomicString& resourceType()
-{
-    ASSERT(WTF::isMainThread());
-    static NeverDestroyed<const AtomicString> resource("resource", AtomicString::ConstructFromLiteral);
-    return resource;
-}
-
 Cache& singleton()
 {
     static NeverDestroyed<Cache> instance;
@@ -121,7 +113,7 @@
     // FIXME: This implements minimal Range header disk cache support. We don't parse
     // ranges so only the same exact range request will be served from the cache.
     String range = request.httpHeaderField(WebCore::HTTPHeaderName::Range);
-    return { partition, resourceType(), range, request.url().string() };
+    return { partition, range, request.url().string() };
 }
 
 static String headerValueForVary(const WebCore::ResourceRequest& request, const String& headerName)
@@ -480,7 +472,7 @@
 {
     ASSERT(isEnabled());
 
-    m_storage->traverse(resourceType(), 0, [traverseHandler](const Storage::Record* record, const Storage::RecordInfo&) {
+    m_storage->traverse(0, [traverseHandler](const Storage::Record* record, const Storage::RecordInfo&) {
         if (!record) {
             traverseHandler(nullptr);
             return;
@@ -517,7 +509,7 @@
     Totals totals;
     auto flags = Storage::TraverseFlag::ComputeWorth | Storage::TraverseFlag::ShareCount;
     size_t capacity = m_storage->capacity();
-    m_storage->traverse(resourceType(), flags, [fd, totals, capacity](const Storage::Record* record, const Storage::RecordInfo& info) mutable {
+    m_storage->traverse(flags, [fd, totals, capacity](const Storage::Record* record, const Storage::RecordInfo& info) mutable {
         if (!record) {
             StringBuilder epilogue;
             epilogue.appendLiteral("{}\n],\n");
@@ -575,8 +567,7 @@
         RunLoop::main().dispatch(completionHandler);
         return;
     }
-    String anyType;
-    m_storage->clear(anyType, modifiedSince, WTF::move(completionHandler));
+    m_storage->clear(modifiedSince, WTF::move(completionHandler));
 
     deleteDumpFile();
 }

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheKey.cpp (191353 => 191354)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheKey.cpp	2015-10-20 20:42:01 UTC (rev 191353)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheKey.cpp	2015-10-20 20:47:48 UTC (rev 191354)
@@ -38,16 +38,14 @@
 
 Key::Key(const Key& o)
     : m_partition(o.m_partition.isolatedCopy())
-    , m_type(o.m_type.isolatedCopy())
     , m_identifier(o.m_identifier.isolatedCopy())
     , m_range(o.m_range.isolatedCopy())
     , m_hash(o.m_hash)
 {
 }
 
-Key::Key(const String& partition, const String& type, const String& range, const String& identifier)
+Key::Key(const String& partition, const String& range, const String& identifier)
     : m_partition(partition.isolatedCopy())
-    , m_type(type.isolatedCopy())
     , m_identifier(identifier.isolatedCopy())
     , m_range(range.isolatedCopy())
     , m_hash(computeHash())
@@ -57,7 +55,6 @@
 Key& Key::operator=(const Key& other)
 {
     m_partition = other.m_partition.isolatedCopy();
-    m_type = other.m_type.isolatedCopy();
     m_identifier = other.m_identifier.isolatedCopy();
     m_range = other.m_range.isolatedCopy();
     m_hash = other.m_hash;
@@ -86,7 +83,6 @@
     // SHA1 just happens to be suitably sized, fast and available.
     SHA1 sha1;
     hashString(sha1, m_partition);
-    hashString(sha1, m_type);
     hashString(sha1, m_identifier);
     hashString(sha1, m_range);
     SHA1::Digest hash;
@@ -128,13 +124,12 @@
 
 bool Key::operator==(const Key& other) const
 {
-    return m_hash == other.m_hash && m_partition == other.m_partition && m_type == other.m_type && m_identifier == other.m_identifier && m_range == other.m_range;
+    return m_hash == other.m_hash && m_partition == other.m_partition && m_identifier == other.m_identifier && m_range == other.m_range;
 }
 
 void Key::encode(Encoder& encoder) const
 {
     encoder << m_partition;
-    encoder << m_type;
     encoder << m_identifier;
     encoder << m_range;
     encoder << m_hash;
@@ -142,7 +137,7 @@
 
 bool Key::decode(Decoder& decoder, Key& key)
 {
-    return decoder.decode(key.m_partition) && decoder.decode(key.m_type) && decoder.decode(key.m_identifier) && decoder.decode(key.m_range) && decoder.decode(key.m_hash);
+    return decoder.decode(key.m_partition) && decoder.decode(key.m_identifier) && decoder.decode(key.m_range) && decoder.decode(key.m_hash);
 }
 
 }

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheKey.h (191353 => 191354)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheKey.h	2015-10-20 20:42:01 UTC (rev 191353)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheKey.h	2015-10-20 20:47:48 UTC (rev 191354)
@@ -44,7 +44,7 @@
     Key() { }
     Key(const Key&);
     Key(Key&&) = default;
-    Key(const String& partition, const String& type, const String& range, const String& identifier);
+    Key(const String& partition, const String& range, const String& identifier);
 
     Key& operator=(const Key&);
     Key& operator=(Key&&) = default;
@@ -53,7 +53,6 @@
 
     const String& partition() const { return m_partition; }
     const String& identifier() const { return m_identifier; }
-    const String& type() const { return m_type; }
 
     HashType hash() const { return m_hash; }
 
@@ -72,7 +71,6 @@
     HashType computeHash() const;
 
     String m_partition;
-    String m_type;
     String m_identifier;
     String m_range;
     HashType m_hash;

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStatistics.cpp (191353 => 191354)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStatistics.cpp	2015-10-20 20:42:01 UTC (rev 191353)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStatistics.cpp	2015-10-20 20:47:48 UTC (rev 191354)
@@ -144,10 +144,7 @@
     LOG(NetworkCache, "(NetworkProcess) Bootstrapping the network cache statistics database from the network cache...");
 
     Vector<StringCapture> hashes;
-    traverseRecordsFiles(networkCachePath, ASCIILiteral("resource"), [&hashes](const String& fileName, const String& hashString, const String& type, bool isBodyBlob, const String& recordDirectoryPath) {
-        if (isBodyBlob)
-            return;
-
+    traverseRecordsFiles(networkCachePath, [&hashes](const String& hashString, const String&) {
         Key::HashType hash;
         if (!Key::stringToHash(hashString, hash))
             return;

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp (191353 => 191354)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp	2015-10-20 20:42:01 UTC (rev 191353)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp	2015-10-20 20:47:48 UTC (rev 191354)
@@ -46,7 +46,7 @@
 static const char versionDirectoryPrefix[] = "Version ";
 static const char recordsDirectoryName[] = "Records";
 static const char blobsDirectoryName[] = "Blobs";
-static const char blobSuffix[] = "-blob";
+static const char bodyPostfix[] = "-body";
 
 static double computeRecordWorth(FileTimes);
 
@@ -113,13 +113,11 @@
 struct Storage::TraverseOperation {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    TraverseOperation(const String& type, TraverseFlags flags, const TraverseHandler& handler)
-        : type(type)
-        , flags(flags)
+    TraverseOperation(TraverseFlags flags, const TraverseHandler& handler)
+        : flags(flags)
         , handler(handler)
     { }
 
-    const String type;
     const TraverseFlags flags;
     const TraverseHandler handler;
 
@@ -153,49 +151,27 @@
     return WebCore::pathByAppendingComponent(makeVersionedDirectoryPath(baseDirectoryPath), blobsDirectoryName);
 }
 
-void traverseRecordsFiles(const String& recordsPath, const String& expectedType, const std::function<void (const String& fileName, const String& hashString, const String& type, bool isBodyBlob, const String& recordDirectoryPath)>& function)
+void traverseRecordsFiles(const String& recordsPath, const std::function<void (const String&, const String&)>& function)
 {
-    traverseDirectory(recordsPath, [&recordsPath, &function, &expectedType](const String& partitionName, DirectoryEntryType entryType) {
-        if (entryType != DirectoryEntryType::Directory)
+    traverseDirectory(recordsPath, [&recordsPath, &function](const String& subdirName, DirectoryEntryType type) {
+        if (type != DirectoryEntryType::Directory)
             return;
-        String partitionPath = WebCore::pathByAppendingComponent(recordsPath, partitionName);
-        traverseDirectory(partitionPath, [&function, &partitionPath, &expectedType](const String& actualType, DirectoryEntryType entryType) {
-            if (entryType != DirectoryEntryType::Directory)
+        String partitionPath = WebCore::pathByAppendingComponent(recordsPath, subdirName);
+        traverseDirectory(partitionPath, [&function, &partitionPath](const String& fileName, DirectoryEntryType type) {
+            if (type != DirectoryEntryType::File)
                 return;
-            if (!actualType.isEmpty() && expectedType != actualType)
-                return;
-            String recordDirectoryPath = WebCore::pathByAppendingComponent(partitionPath, actualType);
-            traverseDirectory(partitionPath, [&function, &recordDirectoryPath, &actualType](const String& fileName, DirectoryEntryType entryType) {
-                if (entryType != DirectoryEntryType::File || fileName.length() < Key::hashStringLength())
-                    return;
-
-                String hashString = fileName.substring(0, Key::hashStringLength());
-                auto isBodyBlob = fileName.length() > Key::hashStringLength() && fileName.endsWith(blobSuffix);
-                function(fileName, hashString, actualType, isBodyBlob, recordDirectoryPath);
-            });
+            function(fileName, partitionPath);
         });
     });
 }
 
 static void deleteEmptyRecordsDirectories(const String& recordsPath)
 {
-    traverseDirectory(recordsPath, [&recordsPath](const String& partitionName, DirectoryEntryType type) {
+    traverseDirectory(recordsPath, [&recordsPath](const String& subdirName, DirectoryEntryType type) {
         if (type != DirectoryEntryType::Directory)
             return;
-
-        // Delete [type] sub-folders.
-        String partitionPath = WebCore::pathByAppendingComponent(recordsPath, partitionName);
-        traverseDirectory(partitionPath, [&partitionPath](const String& subdirName, DirectoryEntryType entryType) {
-            if (entryType != DirectoryEntryType::Directory)
-                return;
-
-            // Let system figure out if it is really empty.
-            WebCore::deleteEmptyDirectory(WebCore::pathByAppendingComponent(partitionPath, subdirName));
-        });
-
-        // Delete [Partition] folders.
         // Let system figure out if it is really empty.
-        WebCore::deleteEmptyDirectory(WebCore::pathByAppendingComponent(recordsPath, partitionName));
+        WebCore::deleteEmptyDirectory(WebCore::pathByAppendingComponent(recordsPath, subdirName));
     });
 }
 
@@ -249,13 +225,14 @@
 
     backgroundIOQueue().dispatch([this] {
         auto recordFilter = std::make_unique<ContentsFilter>();
-        auto blobFilter = std::make_unique<ContentsFilter>();
+        auto bodyFilter = std::make_unique<ContentsFilter>();
         size_t recordsSize = 0;
         unsigned count = 0;
-        String anyType;
-        traverseRecordsFiles(recordsPath(), anyType, [&recordFilter, &blobFilter, &recordsSize, &count](const String& fileName, const String& hashString, const String& type, bool isBodyBlob, const String& recordDirectoryPath) {
-            auto filePath = WebCore::pathByAppendingComponent(recordDirectoryPath, fileName);
+        traverseRecordsFiles(recordsPath(), [&recordFilter, &bodyFilter, &recordsSize, &count](const String& fileName, const String& partitionPath) {
+            auto filePath = WebCore::pathByAppendingComponent(partitionPath, fileName);
 
+            bool isBody = fileName.endsWith(bodyPostfix);
+            String hashString = isBody ? fileName.substring(0, Key::hashStringLength()) : fileName;
             Key::HashType hash;
             if (!Key::stringToHash(hashString, hash)) {
                 WebCore::deleteFile(filePath);
@@ -267,33 +244,31 @@
                 WebCore::deleteFile(filePath);
                 return;
             }
-
-            if (isBodyBlob) {
-                blobFilter->add(hash);
+            if (isBody) {
+                bodyFilter->add(hash);
                 return;
             }
-
             recordFilter->add(hash);
             recordsSize += fileSize;
             ++count;
         });
 
         auto* recordFilterPtr = recordFilter.release();
-        auto* blobFilterPtr = blobFilter.release();
-        RunLoop::main().dispatch([this, recordFilterPtr, blobFilterPtr, recordsSize] {
+        auto* bodyFilterPtr = bodyFilter.release();
+        RunLoop::main().dispatch([this, recordFilterPtr, bodyFilterPtr, recordsSize] {
             auto recordFilter = std::unique_ptr<ContentsFilter>(recordFilterPtr);
-            auto blobFilter = std::unique_ptr<ContentsFilter>(blobFilterPtr);
+            auto bodyFilter = std::unique_ptr<ContentsFilter>(bodyFilterPtr);
 
-            for (auto& recordFilterKey : m_recordFilterHashesAddedDuringSynchronization)
-                recordFilter->add(recordFilterKey);
+            for (auto& hash : m_recordFilterHashesAddedDuringSynchronization)
+                recordFilter->add(hash);
             m_recordFilterHashesAddedDuringSynchronization.clear();
 
-            for (auto& hash : m_blobFilterHashesAddedDuringSynchronization)
-                blobFilter->add(hash);
-            m_blobFilterHashesAddedDuringSynchronization.clear();
+            for (auto& hash : m_bodyFilterHashesAddedDuringSynchronization)
+                bodyFilter->add(hash);
+            m_bodyFilterHashesAddedDuringSynchronization.clear();
 
             m_recordFilter = WTF::move(recordFilter);
-            m_blobFilter = WTF::move(blobFilter);
+            m_bodyFilter = WTF::move(bodyFilter);
             m_approximateRecordsSize = recordsSize;
             m_synchronizationInProgress = false;
         });
@@ -302,7 +277,7 @@
 
         deleteEmptyRecordsDirectories(recordsPath());
 
-        LOG(NetworkCacheStorage, "(NetworkProcess) cache synchronization completed size=%zu count=%u", recordsSize, count);
+        LOG(NetworkCacheStorage, "(NetworkProcess) cache synchronization completed size=%zu count=%d", recordsSize, count);
     });
 }
 
@@ -324,32 +299,30 @@
     return !m_recordFilter || m_recordFilter->mayContain(key.hash());
 }
 
-bool Storage::mayContainBlob(const Key& key) const
+String Storage::partitionPathForKey(const Key& key) const
 {
-    ASSERT(RunLoop::isMain());
-    return !m_blobFilter || m_blobFilter->mayContain(key.hash());
+    ASSERT(!key.partition().isEmpty());
+    return WebCore::pathByAppendingComponent(recordsPath(), key.partition());
 }
 
-String Storage::recordDirectoryPathForKey(const Key& key) const
+static String fileNameForKey(const Key& key)
 {
-    ASSERT(!key.partition().isEmpty());
-    ASSERT(!key.type().isEmpty());
-    return WebCore::pathByAppendingComponent(WebCore::pathByAppendingComponent(recordsPath(), key.partition()), key.type());
+    return key.hashAsString();
 }
 
 String Storage::recordPathForKey(const Key& key) const
 {
-    return WebCore::pathByAppendingComponent(recordDirectoryPathForKey(key), key.hashAsString());
+    return WebCore::pathByAppendingComponent(partitionPathForKey(key), fileNameForKey(key));
 }
 
-static String blobPathForRecordPath(const String& recordPath)
+static String bodyPathForRecordPath(const String& recordPath)
 {
-    return recordPath + blobSuffix;
+    return recordPath + bodyPostfix;
 }
 
-String Storage::blobPathForKey(const Key& key) const
+String Storage::bodyPathForKey(const Key& key) const
 {
-    return blobPathForRecordPath(recordPathForKey(key));
+    return bodyPathForRecordPath(recordPathForKey(key));
 }
 
 struct RecordMetaData {
@@ -479,20 +452,20 @@
 
 Optional<BlobStorage::Blob> Storage::storeBodyAsBlob(WriteOperation& writeOperation)
 {
-    auto blobPath = blobPathForKey(writeOperation.record.key);
+    auto bodyPath = bodyPathForKey(writeOperation.record.key);
 
     // Store the body.
-    auto blob = m_blobStorage.add(blobPath, writeOperation.record.body);
+    auto blob = m_blobStorage.add(bodyPath, writeOperation.record.body);
     if (blob.data.isNull())
         return { };
 
     ++writeOperation.activeCount;
 
     RunLoop::main().dispatch([this, blob, &writeOperation] {
-        if (m_blobFilter)
-            m_blobFilter->add(writeOperation.record.key.hash());
+        if (m_bodyFilter)
+            m_bodyFilter->add(writeOperation.record.key.hash());
         if (m_synchronizationInProgress)
-            m_blobFilterHashesAddedDuringSynchronization.append(writeOperation.record.key.hash());
+            m_bodyFilterHashesAddedDuringSynchronization.append(writeOperation.record.key.hash());
 
         if (writeOperation.mappedBodyHandler)
             writeOperation.mappedBodyHandler(blob.data);
@@ -550,7 +523,7 @@
 
     serialBackgroundIOQueue().dispatch([this, key] {
         WebCore::deleteFile(recordPathForKey(key));
-        m_blobStorage.remove(blobPathForKey(key));
+        m_blobStorage.remove(bodyPathForKey(key));
     });
 }
 
@@ -573,7 +546,7 @@
     const auto readTimeout = 1500_ms;
     m_readOperationTimeoutTimer.startOneShot(readTimeout);
 
-    bool shouldGetBodyBlob = mayContainBlob(readOperation.key);
+    bool shouldGetBodyBlob = !m_bodyFilter || m_bodyFilter->mayContain(readOperation.key.hash());
 
     ioQueue().dispatch([this, &readOperation, shouldGetBodyBlob] {
         auto recordPath = recordPathForKey(readOperation.key);
@@ -590,9 +563,9 @@
         });
 
         if (shouldGetBodyBlob) {
-            // Read the blob in parallel with the record read.
-            auto blobPath = blobPathForKey(readOperation.key);
-            readOperation.resultBodyBlob = m_blobStorage.get(blobPath);
+            // Read the body blob in parallel with the record read.
+            auto bodyPath = bodyPathForKey(readOperation.key);
+            readOperation.resultBodyBlob = m_blobStorage.get(bodyPath);
             finishReadOperation(readOperation);
         }
     });
@@ -601,7 +574,7 @@
 void Storage::finishReadOperation(ReadOperation& readOperation)
 {
     ASSERT(readOperation.activeCount);
-    // Record and blob reads must finish.
+    // Record and body blob reads must finish.
     if (--readOperation.activeCount)
         return;
 
@@ -708,17 +681,17 @@
     addToRecordFilter(writeOperation.record.key);
 
     backgroundIOQueue().dispatch([this, &writeOperation] {
-        auto recordDirectorPath = recordDirectoryPathForKey(writeOperation.record.key);
+        auto partitionPath = partitionPathForKey(writeOperation.record.key);
         auto recordPath = recordPathForKey(writeOperation.record.key);
 
-        WebCore::makeAllDirectories(recordDirectorPath);
+        WebCore::makeAllDirectories(partitionPath);
 
         ++writeOperation.activeCount;
 
         bool shouldStoreAsBlob = shouldStoreBodyAsBlob(writeOperation.record.body);
-        auto blob = shouldStoreAsBlob ? storeBodyAsBlob(writeOperation) : Nullopt;
+        auto bodyBlob = shouldStoreAsBlob ? storeBodyAsBlob(writeOperation) : Nullopt;
 
-        auto recordData = encodeRecord(writeOperation.record, blob);
+        auto recordData = encodeRecord(writeOperation.record, bodyBlob);
 
         auto channel = IOChannel::open(recordPath, IOChannel::Type::Create);
         size_t recordSize = recordData.size();
@@ -797,30 +770,28 @@
     m_writeOperationDispatchTimer.startOneShot(initialWriteDelay);
 }
 
-void Storage::traverse(const String& type, TraverseFlags flags, TraverseHandler&& traverseHandler)
+void Storage::traverse(TraverseFlags flags, TraverseHandler&& traverseHandler)
 {
     ASSERT(RunLoop::isMain());
     ASSERT(traverseHandler);
     // Avoid non-thread safe std::function copies.
 
-    auto traverseOperationPtr = std::make_unique<TraverseOperation>(type, flags, WTF::move(traverseHandler));
+    auto traverseOperationPtr = std::make_unique<TraverseOperation>(flags, WTF::move(traverseHandler));
     auto& traverseOperation = *traverseOperationPtr;
     m_activeTraverseOperations.add(WTF::move(traverseOperationPtr));
 
     ioQueue().dispatch([this, &traverseOperation] {
-        traverseRecordsFiles(recordsPath(), traverseOperation.type, [this, &traverseOperation](const String& fileName, const String& hashString, const String& type, bool isBodyBlob, const String& recordDirectoryPath) {
-            ASSERT(type == traverseOperation.type);
-            if (isBodyBlob)
+        traverseRecordsFiles(recordsPath(), [this, &traverseOperation](const String& fileName, const String& partitionPath) {
+            if (fileName.length() != Key::hashStringLength())
                 return;
+            auto recordPath = WebCore::pathByAppendingComponent(partitionPath, fileName);
 
-            auto recordPath = WebCore::pathByAppendingComponent(recordDirectoryPath, fileName);
-
             double worth = -1;
             if (traverseOperation.flags & TraverseFlag::ComputeWorth)
                 worth = computeRecordWorth(fileTimes(recordPath));
             unsigned bodyShareCount = 0;
             if (traverseOperation.flags & TraverseFlag::ShareCount)
-                bodyShareCount = m_blobStorage.shareCount(blobPathForRecordPath(recordPath));
+                bodyShareCount = m_blobStorage.shareCount(bodyPathForRecordPath(recordPath));
 
             std::unique_lock<Lock> lock(traverseOperation.activeMutex);
             ++traverseOperation.activeCount;
@@ -885,24 +856,24 @@
     shrinkIfNeeded();
 }
 
-void Storage::clear(const String& type, std::chrono::system_clock::time_point modifiedSinceTime, std::function<void ()>&& completionHandler)
+void Storage::clear(std::chrono::system_clock::time_point modifiedSinceTime, std::function<void ()>&& completionHandler)
 {
     ASSERT(RunLoop::isMain());
     LOG(NetworkCacheStorage, "(NetworkProcess) clearing cache");
 
     if (m_recordFilter)
         m_recordFilter->clear();
-    if (m_blobFilter)
-        m_blobFilter->clear();
+    if (m_bodyFilter)
+        m_bodyFilter->clear();
     m_approximateRecordsSize = 0;
 
     // Avoid non-thread safe std::function copies.
     auto* completionHandlerPtr = completionHandler ? new std::function<void ()>(WTF::move(completionHandler)) : nullptr;
-    StringCapture typeCapture(type);
-    ioQueue().dispatch([this, modifiedSinceTime, completionHandlerPtr, typeCapture] {
+
+    ioQueue().dispatch([this, modifiedSinceTime, completionHandlerPtr] {
         auto recordsPath = this->recordsPath();
-        traverseRecordsFiles(recordsPath, typeCapture.string(), [modifiedSinceTime](const String& fileName, const String& hashString, const String& type, bool isBodyBlob, const String& recordDirectoryPath) {
-            auto filePath = WebCore::pathByAppendingComponent(recordDirectoryPath, fileName);
+        traverseRecordsFiles(recordsPath, [modifiedSinceTime](const String& fileName, const String& partitionPath) {
+            auto filePath = WebCore::pathByAppendingComponent(partitionPath, fileName);
             if (modifiedSinceTime > std::chrono::system_clock::time_point::min()) {
                 auto times = fileTimes(filePath);
                 if (times.modification < modifiedSinceTime)
@@ -913,7 +884,7 @@
 
         deleteEmptyRecordsDirectories(recordsPath);
 
-        // This cleans unreferenced blobs.
+        // This cleans unreferences blobs.
         m_blobStorage.synchronize();
 
         if (completionHandlerPtr) {
@@ -979,16 +950,14 @@
 
     backgroundIOQueue().dispatch([this] {
         auto recordsPath = this->recordsPath();
-        String anyType;
-        traverseRecordsFiles(recordsPath, anyType, [this](const String& fileName, const String& hashString, const String& type, bool isBodyBlob, const String& recordDirectoryPath) {
-            if (isBodyBlob)
+        traverseRecordsFiles(recordsPath, [this](const String& fileName, const String& partitionPath) {
+            if (fileName.length() != Key::hashStringLength())
                 return;
+            auto recordPath = WebCore::pathByAppendingComponent(partitionPath, fileName);
+            auto bodyPath = bodyPathForRecordPath(recordPath);
 
-            auto recordPath = WebCore::pathByAppendingComponent(recordDirectoryPath, fileName);
-            auto blobPath = blobPathForRecordPath(recordPath);
-
             auto times = fileTimes(recordPath);
-            unsigned bodyShareCount = m_blobStorage.shareCount(blobPath);
+            unsigned bodyShareCount = m_blobStorage.shareCount(bodyPath);
             auto probability = deletionProbability(times, bodyShareCount);
 
             bool shouldDelete = randomNumber() < probability;
@@ -997,7 +966,7 @@
 
             if (shouldDelete) {
                 WebCore::deleteFile(recordPath);
-                m_blobStorage.remove(blobPath);
+                m_blobStorage.remove(bodyPath);
             }
         });
 

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h (191353 => 191354)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h	2015-10-20 20:42:01 UTC (rev 191353)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h	2015-10-20 20:47:48 UTC (rev 191354)
@@ -65,7 +65,7 @@
     void store(const Record&, MappedBodyHandler&&);
 
     void remove(const Key&);
-    void clear(const String& type, std::chrono::system_clock::time_point modifiedSinceTime, std::function<void ()>&& completionHandler);
+    void clear(std::chrono::system_clock::time_point modifiedSinceTime, std::function<void ()>&& completionHandler);
 
     struct RecordInfo {
         size_t bodySize;
@@ -80,13 +80,13 @@
     typedef unsigned TraverseFlags;
     typedef std::function<void (const Record*, const RecordInfo&)> TraverseHandler;
     // Null record signals end.
-    void traverse(const String& type, TraverseFlags, TraverseHandler&&);
+    void traverse(TraverseFlags, TraverseHandler&&);
 
     void setCapacity(size_t);
     size_t capacity() const { return m_capacity; }
     size_t approximateSize() const;
 
-    static const unsigned version = 5;
+    static const unsigned version = 4;
 
     String basePath() const;
     String versionPath() const;
@@ -97,9 +97,9 @@
 private:
     Storage(const String& directoryPath);
 
-    String recordDirectoryPathForKey(const Key&) const;
+    String partitionPathForKey(const Key&) const;
     String recordPathForKey(const Key&) const;
-    String blobPathForKey(const Key&) const;
+    String bodyPathForKey(const Key&) const;
 
     void synchronize();
     void deleteOldVersions();
@@ -129,7 +129,6 @@
     WorkQueue& serialBackgroundIOQueue() { return m_serialBackgroundIOQueue.get(); }
 
     bool mayContain(const Key&) const;
-    bool mayContainBlob(const Key&) const;
 
     void addToRecordFilter(const Key&);
 
@@ -142,13 +141,13 @@
     // 2^18 bit filter can support up to 26000 entries with false positive rate < 1%.
     using ContentsFilter = BloomFilter<18>;
     std::unique_ptr<ContentsFilter> m_recordFilter;
-    std::unique_ptr<ContentsFilter> m_blobFilter;
+    std::unique_ptr<ContentsFilter> m_bodyFilter;
 
     bool m_synchronizationInProgress { false };
     bool m_shrinkInProgress { false };
 
     Vector<Key::HashType> m_recordFilterHashesAddedDuringSynchronization;
-    Vector<Key::HashType> m_blobFilterHashesAddedDuringSynchronization;
+    Vector<Key::HashType> m_bodyFilterHashesAddedDuringSynchronization;
 
     static const int maximumRetrievePriority = 4;
     Deque<std::unique_ptr<ReadOperation>> m_pendingReadOperationsByPriority[maximumRetrievePriority + 1];
@@ -170,7 +169,7 @@
 };
 
 // FIXME: Remove, used by NetworkCacheStatistics only.
-void traverseRecordsFiles(const String& recordsPath, const String& type, const std::function<void (const String& fileName, const String& hashString, const String& type, bool isBodyBlob, const String& recordDirectoryPath)>&);
+void traverseRecordsFiles(const String& recordsPath, const std::function<void (const String&, const String&)>&);
 
 }
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to