Modern IDB: Using existing database info from SQLite backing store is busted.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 26 Feb 2016 19:49:35 +0000 (19:49 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 26 Feb 2016 19:49:35 +0000 (19:49 +0000)
<rdar://problem/24848143> and https://bugs.webkit.org/show_bug.cgi?id=154735

Reviewed by Alex Christensen.

No new tests.

Reproducing the bug requires having a known database on disk *before* launching the DatabaseProcess to
read in the existing IDBDatabaseInfo.

Our automated infrastructure currently has no way of testing this.

* Modules/indexeddb/client/IDBConnectionToServer.cpp:
(WebCore::IDBClient::IDBConnectionToServer::openDatabase):
* Modules/indexeddb/server/SQLiteIDBBackingStore.cpp:
(WebCore::IDBServer::SQLiteIDBBackingStore::getOrEstablishDatabaseInfo): Do the optional migrate on
  the IndexRecords table here; *every* time we open a SQLite backing store.
(WebCore::IDBServer::SQLiteIDBBackingStore::createAndPopulateInitialDatabaseInfo): Deleted.
* Modules/indexeddb/shared/IDBDatabaseInfo.cpp:
(WebCore::IDBDatabaseInfo::isolatedCopy): Copy the entire object, not just name/version.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@197190 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/client/IDBConnectionToServer.cpp
Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp
Source/WebCore/Modules/indexeddb/shared/IDBDatabaseInfo.cpp

index 81abf55..91148e6 100644 (file)
@@ -1,3 +1,26 @@
+2016-02-26  Brady Eidson  <beidson@apple.com>
+
+        Modern IDB: Using existing database info from SQLite backing store is busted.
+        <rdar://problem/24848143> and https://bugs.webkit.org/show_bug.cgi?id=154735
+
+        Reviewed by Alex Christensen.
+
+        No new tests.
+        
+        Reproducing the bug requires having a known database on disk *before* launching the DatabaseProcess to
+        read in the existing IDBDatabaseInfo.
+        
+        Our automated infrastructure currently has no way of testing this.
+
+        * Modules/indexeddb/client/IDBConnectionToServer.cpp:
+        (WebCore::IDBClient::IDBConnectionToServer::openDatabase):
+        * Modules/indexeddb/server/SQLiteIDBBackingStore.cpp:
+        (WebCore::IDBServer::SQLiteIDBBackingStore::getOrEstablishDatabaseInfo): Do the optional migrate on
+          the IndexRecords table here; *every* time we open a SQLite backing store.
+        (WebCore::IDBServer::SQLiteIDBBackingStore::createAndPopulateInitialDatabaseInfo): Deleted.
+        * Modules/indexeddb/shared/IDBDatabaseInfo.cpp:
+        (WebCore::IDBDatabaseInfo::isolatedCopy): Copy the entire object, not just name/version.
+
 2016-02-25  Gavin Barraclough  <barraclough@apple.com>
 
         RefCounter value changed callback should be called on all changes (not just zero edge).
index b20b9c6..dd5859d 100644 (file)
@@ -76,7 +76,7 @@ void IDBConnectionToServer::didDeleteDatabase(const IDBResultData& resultData)
 
 void IDBConnectionToServer::openDatabase(IDBOpenDBRequest& request)
 {
-    LOG(IndexedDB, "IDBConnectionToServer::openDatabase - %s", request.databaseIdentifier().debugString().utf8().data());
+    LOG(IndexedDB, "IDBConnectionToServer::openDatabase - %s (%" PRIu64 ")", request.databaseIdentifier().debugString().utf8().data(), request.version());
 
     ASSERT(!m_openDBRequestMap.contains(request.resourceIdentifier()));
     m_openDBRequestMap.set(request.resourceIdentifier(), &request);
index b5d5256..c1e8163 100644 (file)
@@ -372,12 +372,6 @@ std::unique_ptr<IDBDatabaseInfo> SQLiteIDBBackingStore::createAndPopulateInitial
         return nullptr;
     }
 
-    if (!ensureValidIndexRecordsTable()) {
-        LOG_ERROR("Could not create IndexRecords table in database (%i) - %s", m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg());
-        m_sqliteDB = nullptr;
-        return nullptr;
-    }
-
     if (!m_sqliteDB->executeCommand("CREATE TABLE KeyGenerators (objectStoreID INTEGER NOT NULL ON CONFLICT FAIL UNIQUE ON CONFLICT REPLACE, currentKey INTEGER NOT NULL ON CONFLICT FAIL);")) {
         LOG_ERROR("Could not create KeyGenerators table in database (%i) - %s", m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg());
         m_sqliteDB = nullptr;
@@ -594,6 +588,12 @@ const IDBDatabaseInfo& SQLiteIDBBackingStore::getOrEstablishDatabaseInfo()
         return *m_databaseInfo;
     }
 
+    if (!ensureValidIndexRecordsTable()) {
+        LOG_ERROR("Error creating or migrating Index Records table in database");
+        m_sqliteDB = nullptr;
+        return *m_databaseInfo;
+    }
+
     auto databaseInfo = extractExistingDatabaseInfo();
     if (!databaseInfo)
         databaseInfo = createAndPopulateInitialDatabaseInfo();
index 9de5f42..7cdb91e 100644 (file)
@@ -46,6 +46,10 @@ IDBDatabaseInfo IDBDatabaseInfo::isolatedCopy() const
 
     info.m_name = m_name.isolatedCopy();
     info.m_version = m_version;
+    info.m_maxObjectStoreID = m_maxObjectStoreID;
+
+    for (auto entry : m_objectStoreMap)
+        info.m_objectStoreMap.set(entry.key, entry.value.isolatedCopy());
 
     return info;
 }