Diff
Modified: trunk/Source/WebCore/ChangeLog (249332 => 249333)
--- trunk/Source/WebCore/ChangeLog 2019-08-30 17:17:20 UTC (rev 249332)
+++ trunk/Source/WebCore/ChangeLog 2019-08-30 17:19:38 UTC (rev 249333)
@@ -1,3 +1,51 @@
+2019-08-30 Sihui Liu <sihui_...@apple.com>
+
+ IndexedDB: update size of database when database operation is completed
+ https://bugs.webkit.org/show_bug.cgi?id=201057
+
+ Reviewed by Youenn Fablet.
+
+ Currently when a database operation was completed, we re-computed the disk usage of the origin. This computation
+ listed all databases in the origin directory and read the size of each database file, which was very inefficient
+ because the completed operation should only affect one database.
+
+ This patch makes UniqueIDBDatabase keep track of database size and reports size change to QuotaUser.
+
+ Tested PerformanceTests/IndexedDB/basic/objectstore-add.html on release build minibrowser. This change makes
+ the test over 50% faster.
+
+ * Modules/indexeddb/server/IDBBackingStore.h:
+ * Modules/indexeddb/server/IDBServer.cpp:
+ (WebCore::IDBServer::IDBServer::QuotaUser::increaseSpaceUsed):
+ (WebCore::IDBServer::IDBServer::QuotaUser::decreaseSpaceUsed):
+ (WebCore::IDBServer::IDBServer::computeSpaceUsedForOrigin):
+ (WebCore::IDBServer::IDBServer::increaseSpaceUsed):
+ (WebCore::IDBServer::IDBServer::decreaseSpaceUsed):
+ (WebCore::IDBServer::IDBServer::setSpaceUsed): Deleted.
+ * Modules/indexeddb/server/IDBServer.h:
+ * Modules/indexeddb/server/MemoryIDBBackingStore.cpp:
+ (WebCore::IDBServer::MemoryIDBBackingStore::databaseSize const):
+ (WebCore::IDBServer::MemoryIDBBackingStore::close):
+ (WebCore::IDBServer::MemoryIDBBackingStore::databasesSizeForOrigin const): Deleted.
+ * Modules/indexeddb/server/MemoryIDBBackingStore.h:
+ * Modules/indexeddb/server/SQLiteIDBBackingStore.cpp:
+ (WebCore::IDBServer::SQLiteIDBBackingStore::databasesSizeForDirectory):
+ (WebCore::IDBServer::SQLiteIDBBackingStore::databaseSize const):
+ (WebCore::IDBServer::SQLiteIDBBackingStore::close):
+ (WebCore::IDBServer::SQLiteIDBBackingStore::databasesSizeForFolder): Deleted.
+ (WebCore::IDBServer::SQLiteIDBBackingStore::databasesSizeForOrigin const): Deleted.
+ * Modules/indexeddb/server/SQLiteIDBBackingStore.h:
+ * Modules/indexeddb/server/UniqueIDBDatabase.cpp:
+ (WebCore::IDBServer::UniqueIDBDatabase::deleteBackingStore):
+ (WebCore::IDBServer::UniqueIDBDatabase::shutdownForClose):
+ (WebCore::IDBServer::UniqueIDBDatabase::didShutdownForClose):
+ (WebCore::IDBServer::UniqueIDBDatabase::didDeleteBackingStore):
+ (WebCore::IDBServer::UniqueIDBDatabase::openBackingStore):
+ (WebCore::IDBServer::UniqueIDBDatabase::didOpenBackingStore):
+ (WebCore::IDBServer::UniqueIDBDatabase::postDatabaseTaskReply):
+ (WebCore::IDBServer::UniqueIDBDatabase::updateSpaceUsedIfNeeded):
+ * Modules/indexeddb/server/UniqueIDBDatabase.h:
+
2019-08-30 Alicia Boya GarcĂa <ab...@igalia.com>
[MSE][GStreamer] Replaying the video should update currentTime
Modified: trunk/Source/WebCore/Modules/indexeddb/server/IDBBackingStore.h (249332 => 249333)
--- trunk/Source/WebCore/Modules/indexeddb/server/IDBBackingStore.h 2019-08-30 17:17:20 UTC (rev 249332)
+++ trunk/Source/WebCore/Modules/indexeddb/server/IDBBackingStore.h 2019-08-30 17:19:38 UTC (rev 249333)
@@ -99,7 +99,8 @@
virtual bool supportsSimultaneousTransactions() = 0;
virtual bool isEphemeral() = 0;
- virtual uint64_t databasesSizeForOrigin() const = 0;
+ virtual void close() = 0;
+ virtual uint64_t databaseSize() const = 0;
virtual bool hasTransaction(const IDBResourceIdentifier&) const = 0;
protected:
Modified: trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp (249332 => 249333)
--- trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp 2019-08-30 17:17:20 UTC (rev 249332)
+++ trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp 2019-08-30 17:19:38 UTC (rev 249333)
@@ -732,6 +732,21 @@
m_manager->addUser(*this);
}
+void IDBServer::QuotaUser::increaseSpaceUsed(uint64_t size)
+{
+ if (!m_isInitialized)
+ return;
+ ASSERT(m_spaceUsed + size > m_spaceUsed);
+ m_spaceUsed += size;
+}
+void IDBServer::QuotaUser::decreaseSpaceUsed(uint64_t size)
+{
+ if (!m_isInitialized)
+ return;
+ ASSERT(m_spaceUsed >= size);
+ m_spaceUsed -= size;
+}
+
void IDBServer::QuotaUser::whenInitialized(CompletionHandler<void()>&& callback)
{
if (m_isInitialized) {
@@ -772,7 +787,7 @@
auto databaseDirectoryPath = this->databaseDirectoryPathIsolatedCopy();
auto oldVersionOriginDirectory = IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot(origin.topOrigin, origin.clientOrigin, databaseDirectoryPath, "v0");
auto newVersionOriginDirectory = IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot(origin.topOrigin, origin.clientOrigin, databaseDirectoryPath, "v1");
- auto size = SQLiteIDBBackingStore::databasesSizeForFolder(oldVersionOriginDirectory) + SQLiteIDBBackingStore::databasesSizeForFolder(newVersionOriginDirectory);
+ auto size = SQLiteIDBBackingStore::databasesSizeForDirectory(oldVersionOriginDirectory) + SQLiteIDBBackingStore::databasesSizeForDirectory(newVersionOriginDirectory);
postDatabaseTaskReply(createCrossThreadTask(*this, &IDBServer::finishComputingSpaceUsedForOrigin, origin, size));
}
@@ -799,11 +814,16 @@
user->resetSpaceUsed();
}
-void IDBServer::setSpaceUsed(const ClientOrigin& origin, uint64_t taskSize)
+void IDBServer::increaseSpaceUsed(const ClientOrigin& origin, uint64_t size)
{
- ensureQuotaUser(origin).setSpaceUsed(taskSize);
+ ensureQuotaUser(origin).increaseSpaceUsed(size);
}
+void IDBServer::decreaseSpaceUsed(const ClientOrigin& origin, uint64_t size)
+{
+ ensureQuotaUser(origin).decreaseSpaceUsed(size);
+}
+
void IDBServer::increasePotentialSpaceUsed(const ClientOrigin& origin, uint64_t taskSize)
{
ensureQuotaUser(origin).increasePotentialSpaceUsed(taskSize);
Modified: trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.h (249332 => 249333)
--- trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.h 2019-08-30 17:17:20 UTC (rev 249332)
+++ trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.h 2019-08-30 17:19:38 UTC (rev 249333)
@@ -116,7 +116,8 @@
void requestSpace(const ClientOrigin&, uint64_t taskSize, CompletionHandler<void(StorageQuotaManager::Decision)>&&);
void increasePotentialSpaceUsed(const ClientOrigin&, uint64_t taskSize);
void decreasePotentialSpaceUsed(const ClientOrigin&, uint64_t taskSize);
- void setSpaceUsed(const ClientOrigin&, uint64_t spaceUsed);
+ void increaseSpaceUsed(const ClientOrigin&, uint64_t size);
+ void decreaseSpaceUsed(const ClientOrigin&, uint64_t size);
void resetSpaceUsed(const ClientOrigin&);
void initializeQuotaUser(const ClientOrigin& origin) { ensureQuotaUser(origin); }
@@ -160,6 +161,8 @@
ASSERT(m_estimatedSpaceIncrease >= decrease);
m_estimatedSpaceIncrease -= decrease;
}
+ void increaseSpaceUsed(uint64_t size);
+ void decreaseSpaceUsed(uint64_t size);
void initializeSpaceUsed(uint64_t spaceUsed);
Modified: trunk/Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.cpp (249332 => 249333)
--- trunk/Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.cpp 2019-08-30 17:17:20 UTC (rev 249332)
+++ trunk/Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.cpp 2019-08-30 17:19:38 UTC (rev 249333)
@@ -595,12 +595,16 @@
// The in-memory IDB backing store doesn't need to do any cleanup when it is deleted.
}
-uint64_t MemoryIDBBackingStore::databasesSizeForOrigin() const
+uint64_t MemoryIDBBackingStore::databaseSize() const
{
// FIXME: Implement this.
return 0;
}
+void MemoryIDBBackingStore::close()
+{
+}
+
} // namespace IDBServer
} // namespace WebCore
Modified: trunk/Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.h (249332 => 249333)
--- trunk/Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.h 2019-08-30 17:17:20 UTC (rev 249332)
+++ trunk/Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.h 2019-08-30 17:19:38 UTC (rev 249333)
@@ -79,8 +79,6 @@
bool supportsSimultaneousTransactions() final { return true; }
bool isEphemeral() final { return true; }
- uint64_t databasesSizeForOrigin() const final;
-
void removeObjectStoreForVersionChangeAbort(MemoryObjectStore&);
void restoreObjectStoreForVersionChangeAbort(Ref<MemoryObjectStore>&&);
@@ -88,6 +86,9 @@
private:
RefPtr<MemoryObjectStore> takeObjectStoreByIdentifier(uint64_t identifier);
+
+ uint64_t databaseSize() const final;
+ void close() final;
IDBDatabaseIdentifier m_identifier;
PAL::SessionID m_sessionID;
Modified: trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp (249332 => 249333)
--- trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp 2019-08-30 17:17:20 UTC (rev 249332)
+++ trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp 2019-08-30 17:19:38 UTC (rev 249333)
@@ -845,22 +845,20 @@
return IDBError { };
}
-uint64_t SQLiteIDBBackingStore::databasesSizeForFolder(const String& folder)
+uint64_t SQLiteIDBBackingStore::databasesSizeForDirectory(const String& directory)
{
uint64_t diskUsage = 0;
- for (auto& directory : FileSystem::listDirectory(folder, "*")) {
- for (auto& file : FileSystem::listDirectory(directory, "*.sqlite3"_s))
+ for (auto& dbDirectory : FileSystem::listDirectory(directory, "*")) {
+ for (auto& file : FileSystem::listDirectory(dbDirectory, "*.sqlite3"_s))
diskUsage += SQLiteFileSystem::getDatabaseFileSize(file);
}
return diskUsage;
}
-uint64_t SQLiteIDBBackingStore::databasesSizeForOrigin() const
+uint64_t SQLiteIDBBackingStore::databaseSize() const
{
- auto databaseRootDirectory = this->databaseRootDirectoryIsolatedCopy();
- String oldVersionOriginDirectory = m_identifier.databaseDirectoryRelativeToRoot(databaseRootDirectory, "v0");
- String newVersionOriginDirectory = m_identifier.databaseDirectoryRelativeToRoot(databaseRootDirectory, "v1");
- return databasesSizeForFolder(oldVersionOriginDirectory) + databasesSizeForFolder(newVersionOriginDirectory);
+ ASSERT(!isMainThread());
+ return SQLiteFileSystem::getDatabaseFileSize(fullDatabasePath());
}
IDBError SQLiteIDBBackingStore::beginTransaction(const IDBTransactionInfo& info)
@@ -2593,6 +2591,11 @@
return m_cachedStatements[static_cast<size_t>(sql)].get();
}
+void SQLiteIDBBackingStore::close()
+{
+ closeSQLiteDB();
+}
+
void SQLiteIDBBackingStore::closeSQLiteDB()
{
for (size_t i = 0; i < static_cast<int>(SQL::Count); ++i)
Modified: trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.h (249332 => 249333)
--- trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.h 2019-08-30 17:17:20 UTC (rev 249332)
+++ trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.h 2019-08-30 17:19:38 UTC (rev 249333)
@@ -82,8 +82,6 @@
IDBObjectStoreInfo* infoForObjectStore(uint64_t objectStoreIdentifier) final;
void deleteBackingStore() final;
- uint64_t databasesSizeForOrigin() const final;
-
bool supportsSimultaneousTransactions() final { return false; }
bool isEphemeral() final { return false; }
@@ -94,7 +92,7 @@
IDBError getBlobRecordsForObjectStoreRecord(int64_t objectStoreRecord, Vector<String>& blobURLs, Vector<String>& blobFilePaths);
static String databaseNameFromEncodedFilename(const String&);
- static uint64_t databasesSizeForFolder(const String& folder);
+ static uint64_t databasesSizeForDirectory(const String& directory);
String databaseDirectory() const { return m_databaseDirectory; };
static String fullDatabasePathForDirectory(const String&);
@@ -135,6 +133,9 @@
IDBError getAllIndexRecords(const IDBResourceIdentifier& transactionIdentifier, const IDBGetAllRecordsData&, IDBGetAllResult& outValue);
void closeSQLiteDB();
+ void close() final;
+
+ uint64_t databaseSize() const final;
enum class SQL : size_t {
CreateObjectStoreInfo,
Modified: trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp (249332 => 249333)
--- trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp 2019-08-30 17:17:20 UTC (rev 249332)
+++ trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp 2019-08-30 17:19:38 UTC (rev 249333)
@@ -344,11 +344,14 @@
if (m_backingStore) {
m_backingStore->deleteBackingStore();
+ m_newDatabaseSize = m_backingStore->databaseSize();
+
m_backingStore = nullptr;
m_backingStoreSupportsSimultaneousTransactions = false;
m_backingStoreIsEphemeral = false;
} else {
auto backingStore = m_server->createBackingStore(identifier);
+ m_currentDatabaseSize = backingStore->databaseSize();
IDBDatabaseInfo databaseInfo;
auto error = backingStore->getOrEstablishDatabaseInfo(databaseInfo);
@@ -357,6 +360,7 @@
deletedVersion = databaseInfo.version();
backingStore->deleteBackingStore();
+ m_newDatabaseSize = backingStore->databaseSize();
}
postDatabaseTaskReply(createCrossThreadTask(*this, &UniqueIDBDatabase::didDeleteBackingStore, deletedVersion));
@@ -392,6 +396,11 @@
LOG(IndexedDB, "(db) UniqueIDBDatabase::shutdownForClose");
+ if (m_backingStore) {
+ m_backingStore->close();
+ m_newDatabaseSize = m_backingStore->databaseSize();
+ }
+
m_backingStore = nullptr;
m_backingStoreSupportsSimultaneousTransactions = false;
m_backingStoreIsEphemeral = false;
@@ -409,6 +418,8 @@
{
ASSERT(m_databaseReplyQueue.isEmpty());
m_databaseReplyQueue.kill();
+
+ updateSpaceUsedIfNeeded();
}
void UniqueIDBDatabase::didDeleteBackingStore(uint64_t deletedVersion)
@@ -440,6 +451,8 @@
m_currentOpenDBRequest = nullptr;
}
+ updateSpaceUsedIfNeeded();
+
m_deleteBackingStoreInProgress = false;
if (m_hardClosedForUserDelete)
@@ -773,6 +786,10 @@
m_backingStoreSupportsSimultaneousTransactions = m_backingStore->supportsSimultaneousTransactions();
m_backingStoreIsEphemeral = m_backingStore->isEphemeral();
+ // QuotaUser should have initiliazed storage usage, which contains the
+ // size of this database.
+ m_currentDatabaseSize = m_backingStore->databaseSize();
+
IDBDatabaseInfo databaseInfo;
auto error = m_backingStore->getOrEstablishDatabaseInfo(databaseInfo);
@@ -790,6 +807,8 @@
ASSERT(m_isOpeningBackingStore);
m_isOpeningBackingStore = false;
+ updateSpaceUsedIfNeeded();
+
if (m_hardClosedForUserDelete)
return;
@@ -2110,9 +2129,9 @@
void UniqueIDBDatabase::postDatabaseTaskReply(CrossThreadTask&& task)
{
- // FIXME: We might want to compute total size only for modification operations.
if (m_backingStore)
- m_databasesSizeForOrigin = m_backingStore->databasesSizeForOrigin();
+ m_newDatabaseSize = m_backingStore->databaseSize();
+
m_databaseReplyQueue.append(WTFMove(task));
m_server->postDatabaseTaskReply(createCrossThreadTask(*this, &UniqueIDBDatabase::executeNextDatabaseTaskReply));
}
@@ -2254,15 +2273,27 @@
postDatabaseTask(createCrossThreadTask(*this, &UniqueIDBDatabase::performUnconditionalDeleteBackingStore));
}
-void UniqueIDBDatabase::updateSpaceUsedIfNeeded(uint64_t callbackIdentifier)
+void UniqueIDBDatabase::updateSpaceUsedIfNeeded(Optional<uint64_t> optionalCallbackIdentifier)
{
- auto iterator = m_pendingSpaceIncreasingTasks.find(callbackIdentifier);
- if (iterator == m_pendingSpaceIncreasingTasks.end())
- return;
+ ASSERT(isMainThread());
- m_server->decreasePotentialSpaceUsed(m_identifier.origin(), iterator->value);
- m_server->setSpaceUsed(m_identifier.origin(), m_databasesSizeForOrigin);
- m_pendingSpaceIncreasingTasks.remove(iterator);
+ if (optionalCallbackIdentifier) {
+ uint64_t callbackIdentifier = optionalCallbackIdentifier.value();
+ auto iterator = m_pendingSpaceIncreasingTasks.find(callbackIdentifier);
+ if (iterator != m_pendingSpaceIncreasingTasks.end()) {
+ m_server->decreasePotentialSpaceUsed(m_identifier.origin(), iterator->value);
+ m_pendingSpaceIncreasingTasks.remove(iterator);
+ }
+ }
+
+ uint64_t databaseSize = m_newDatabaseSize;
+ if (databaseSize != m_currentDatabaseSize) {
+ if (databaseSize > m_currentDatabaseSize)
+ m_server->increaseSpaceUsed(m_identifier.origin(), databaseSize - m_currentDatabaseSize);
+ else
+ m_server->decreaseSpaceUsed(m_identifier.origin(), m_currentDatabaseSize - databaseSize);
+ m_currentDatabaseSize = databaseSize;
+ }
}
void UniqueIDBDatabase::performErrorCallback(uint64_t callbackIdentifier, const IDBError& error)
Modified: trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h (249332 => 249333)
--- trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h 2019-08-30 17:17:20 UTC (rev 249332)
+++ trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h 2019-08-30 17:19:38 UTC (rev 249333)
@@ -249,7 +249,7 @@
void requestSpace(uint64_t taskSize, const char* errorMessage, CompletionHandler<void(Optional<IDBError>&&)>&&);
void waitForRequestSpaceCompletion(CompletionHandler<void(Optional<IDBError>&&)>&&);
- void updateSpaceUsedIfNeeded(uint64_t callbackIdentifier);
+ void updateSpaceUsedIfNeeded(Optional<uint64_t> optionalCallbackIdentifier = WTF::nullopt);
Ref<IDBServer> m_server;
IDBDatabaseIdentifier m_identifier;
@@ -303,7 +303,8 @@
HashSet<IDBResourceIdentifier> m_cursorPrefetches;
HashMap<uint64_t, uint64_t> m_pendingSpaceIncreasingTasks;
- uint64_t m_databasesSizeForOrigin { 0 };
+ uint64_t m_currentDatabaseSize { 0 };
+ uint64_t m_newDatabaseSize { 0 };
};
} // namespace IDBServer