Title: [193643] trunk
Revision
193643
Author
beid...@apple.com
Date
2015-12-07 12:27:37 -0800 (Mon, 07 Dec 2015)

Log Message

Modern IDB: Fix "old versions" when upgrading databases.
https://bugs.webkit.org/show_bug.cgi?id=151948

Reviewed by Alex Christensen.

Source/WebCore:

No new tests (5 failing tests now pass, and updated results for a 6th test).

This includes the old version on the IDBVersionChangeEvent, as well as the version the
IDBDatabase is left with if the version change transaction is aborted.

Primary mechanism of the fix is to include the original IDBDatabaseInfo along with
IDBTransactionInfos that represent version change transactions.

* Modules/indexeddb/client/IDBDatabaseImpl.cpp:
(WebCore::IDBClient::IDBDatabase::willAbortTransaction):
(WebCore::IDBClient::IDBDatabase::didAbortTransaction):

* Modules/indexeddb/client/IDBOpenDBRequestImpl.cpp:
(WebCore::IDBClient::IDBOpenDBRequest::onUpgradeNeeded):

* Modules/indexeddb/client/IDBTransactionImpl.cpp:
(WebCore::IDBClient::IDBTransaction::IDBTransaction): Deleted.
(WebCore::IDBClient::IDBTransaction::finishAbortOrCommit): Deleted.
* Modules/indexeddb/client/IDBTransactionImpl.h:
(WebCore::IDBClient::IDBTransaction::info):
(WebCore::IDBClient::IDBTransaction::originalDatabaseInfo):

* Modules/indexeddb/server/UniqueIDBDatabase.cpp:
(WebCore::IDBServer::UniqueIDBDatabase::startVersionChangeTransaction):
(WebCore::IDBServer::UniqueIDBDatabase::commitTransaction):
* Modules/indexeddb/server/UniqueIDBDatabaseConnection.cpp:
(WebCore::IDBServer::UniqueIDBDatabaseConnection::createVersionChangeTransaction):

* Modules/indexeddb/shared/IDBTransactionInfo.cpp:
(WebCore::IDBTransactionInfo::versionChange):
(WebCore::IDBTransactionInfo::IDBTransactionInfo):
(WebCore::IDBTransactionInfo::isolatedCopy):
* Modules/indexeddb/shared/IDBTransactionInfo.h:
(WebCore::IDBTransactionInfo::originalDatabaseInfo):

LayoutTests:

* platform/mac-wk1/TestExpectations:
* storage/indexeddb/database-basics-expected.txt:
* storage/indexeddb/modern/deletedatabase-2-expected.txt:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (193642 => 193643)


--- trunk/LayoutTests/ChangeLog	2015-12-07 19:48:37 UTC (rev 193642)
+++ trunk/LayoutTests/ChangeLog	2015-12-07 20:27:37 UTC (rev 193643)
@@ -1,3 +1,14 @@
+2015-12-07  Brady Eidson  <beid...@apple.com>
+
+        Modern IDB: Fix "old versions" when upgrading databases.
+        https://bugs.webkit.org/show_bug.cgi?id=151948
+
+        Reviewed by Alex Christensen.
+
+        * platform/mac-wk1/TestExpectations:
+        * storage/indexeddb/database-basics-expected.txt:
+        * storage/indexeddb/modern/deletedatabase-2-expected.txt:
+
 2015-12-07  Xabier Rodriguez Calvar  <calva...@igalia.com>
 
         Unreviewed.

Modified: trunk/LayoutTests/platform/mac-wk1/TestExpectations (193642 => 193643)


--- trunk/LayoutTests/platform/mac-wk1/TestExpectations	2015-12-07 19:48:37 UTC (rev 193642)
+++ trunk/LayoutTests/platform/mac-wk1/TestExpectations	2015-12-07 20:27:37 UTC (rev 193643)
@@ -114,7 +114,6 @@
 storage/indexeddb/cursor-continueprimarykey.html [ Failure ]
 storage/indexeddb/cursor-leak.html [ Failure ]
 storage/indexeddb/cursor-request-cycle.html [ Failure ]
-storage/indexeddb/database-basics.html [ Failure ]
 storage/indexeddb/database-deletepending-flag.html [ Failure ]
 storage/indexeddb/database-wrapper.html [ Failure ]
 storage/indexeddb/delete-in-upgradeneeded-close-in-open-success.html [ Failure ]
@@ -133,11 +132,8 @@
 storage/indexeddb/intversion-close-between-events.html [ Failure ]
 storage/indexeddb/intversion-close-in-oncomplete.html [ Failure ]
 storage/indexeddb/intversion-close-in-upgradeneeded.html [ Failure ]
-storage/indexeddb/intversion-encoding.html [ Failure ]
 storage/indexeddb/intversion-gated-on-delete.html [ Failure ]
 storage/indexeddb/intversion-open-in-upgradeneeded.html [ Failure ]
-storage/indexeddb/intversion-open-with-version.html [ Failure ]
-storage/indexeddb/intversion-persistence.html [ Failure ]
 storage/indexeddb/intversion-upgrades.html [ Failure ]
 storage/indexeddb/key-type-array.html [ Failure ]
 storage/indexeddb/key-type-binary.html [ Failure ]
@@ -151,7 +147,6 @@
 storage/indexeddb/pending-version-change-on-exit.html [ Failure ]
 storage/indexeddb/pending-version-change-stuck-works-with-terminate.html [ Failure ]
 storage/indexeddb/pending-version-change-stuck.html [ Failure ]
-storage/indexeddb/persistence.html [ Failure ]
 storage/indexeddb/properties-disabled-at-runtime.html [ Failure ]
 storage/indexeddb/request-leak.html [ Failure ]
 storage/indexeddb/setversion-blocked-by-versionchange-close.html [ Failure ]

Modified: trunk/LayoutTests/storage/indexeddb/database-basics-expected.txt (193642 => 193643)


--- trunk/LayoutTests/storage/indexeddb/database-basics-expected.txt	2015-12-07 19:48:37 UTC (rev 193642)
+++ trunk/LayoutTests/storage/indexeddb/database-basics-expected.txt	2015-12-07 20:27:37 UTC (rev 193643)
@@ -13,7 +13,7 @@
 PASS Exception was thrown.
 PASS code is DOMException.INVALID_STATE_ERR
 PASS ename is 'InvalidStateError'
-Exception message: InvalidStateError: DOM IDBDatabase Exception 11
+Exception message: Failed to execute 'transaction' on 'IDBDatabase': A version change transaction is running.
 PASS db.version is 1
 PASS db.name is "database-basics.html"
 PASS db.objectStoreNames is []
@@ -53,7 +53,7 @@
 PASS Exception was thrown.
 PASS code is DOMException.INVALID_STATE_ERR
 PASS ename is 'InvalidStateError'
-Exception message: InvalidStateError: DOM IDBDatabase Exception 11
+Exception message: Failed to execute 'transaction' on 'IDBDatabase': The database connection is closing.
 Call twice, make sure it's harmless
 db.close()
 PASS successfullyParsed is true

Modified: trunk/LayoutTests/storage/indexeddb/modern/deletedatabase-2-expected.txt (193642 => 193643)


--- trunk/LayoutTests/storage/indexeddb/modern/deletedatabase-2-expected.txt	2015-12-07 19:48:37 UTC (rev 193642)
+++ trunk/LayoutTests/storage/indexeddb/modern/deletedatabase-2-expected.txt	2015-12-07 20:27:37 UTC (rev 193643)
@@ -2,7 +2,7 @@
 That open connection also has an in-progress transaction at the time it gets the versionChange event.
 Initial upgrade old version - 0 new version - 1
 Requesting deleteDatabase
-First connection received versionchange event: oldVersion 0, newVersion null
+First connection received versionchange event: oldVersion 1, newVersion null
 First version change complete
 open db success
 Delete database success: oldVersion 1, newVersion null

Modified: trunk/Source/WebCore/ChangeLog (193642 => 193643)


--- trunk/Source/WebCore/ChangeLog	2015-12-07 19:48:37 UTC (rev 193642)
+++ trunk/Source/WebCore/ChangeLog	2015-12-07 20:27:37 UTC (rev 193643)
@@ -1,3 +1,45 @@
+2015-12-07  Brady Eidson  <beid...@apple.com>
+
+        Modern IDB: Fix "old versions" when upgrading databases.
+        https://bugs.webkit.org/show_bug.cgi?id=151948
+
+        Reviewed by Alex Christensen.
+
+        No new tests (5 failing tests now pass, and updated results for a 6th test).
+
+        This includes the old version on the IDBVersionChangeEvent, as well as the version the 
+        IDBDatabase is left with if the version change transaction is aborted.
+
+        Primary mechanism of the fix is to include the original IDBDatabaseInfo along with 
+        IDBTransactionInfos that represent version change transactions.
+
+        * Modules/indexeddb/client/IDBDatabaseImpl.cpp:
+        (WebCore::IDBClient::IDBDatabase::willAbortTransaction):
+        (WebCore::IDBClient::IDBDatabase::didAbortTransaction):
+
+        * Modules/indexeddb/client/IDBOpenDBRequestImpl.cpp:
+        (WebCore::IDBClient::IDBOpenDBRequest::onUpgradeNeeded):
+
+        * Modules/indexeddb/client/IDBTransactionImpl.cpp:
+        (WebCore::IDBClient::IDBTransaction::IDBTransaction): Deleted.
+        (WebCore::IDBClient::IDBTransaction::finishAbortOrCommit): Deleted.
+        * Modules/indexeddb/client/IDBTransactionImpl.h:
+        (WebCore::IDBClient::IDBTransaction::info):
+        (WebCore::IDBClient::IDBTransaction::originalDatabaseInfo):
+
+        * Modules/indexeddb/server/UniqueIDBDatabase.cpp:
+        (WebCore::IDBServer::UniqueIDBDatabase::startVersionChangeTransaction):
+        (WebCore::IDBServer::UniqueIDBDatabase::commitTransaction):
+        * Modules/indexeddb/server/UniqueIDBDatabaseConnection.cpp:
+        (WebCore::IDBServer::UniqueIDBDatabaseConnection::createVersionChangeTransaction):
+
+        * Modules/indexeddb/shared/IDBTransactionInfo.cpp:
+        (WebCore::IDBTransactionInfo::versionChange):
+        (WebCore::IDBTransactionInfo::IDBTransactionInfo):
+        (WebCore::IDBTransactionInfo::isolatedCopy):
+        * Modules/indexeddb/shared/IDBTransactionInfo.h:
+        (WebCore::IDBTransactionInfo::originalDatabaseInfo):
+
 2015-12-07  Nikos Andronikos  <nikos.andronikos-web...@cisra.canon.com.au>
 
         Update Objective-C code generator to pass a reference to calling object for partial interfaces

Modified: trunk/Source/WebCore/Modules/indexeddb/client/IDBDatabaseImpl.cpp (193642 => 193643)


--- trunk/Source/WebCore/Modules/indexeddb/client/IDBDatabaseImpl.cpp	2015-12-07 19:48:37 UTC (rev 193642)
+++ trunk/Source/WebCore/Modules/indexeddb/client/IDBDatabaseImpl.cpp	2015-12-07 20:27:37 UTC (rev 193643)
@@ -307,8 +307,11 @@
     ASSERT(refTransaction);
     m_abortingTransactions.set(transaction.info().identifier(), WTF::move(refTransaction));
 
-    if (transaction.isVersionChange())
+    if (transaction.isVersionChange()) {
+        ASSERT(transaction.originalDatabaseInfo());
+        m_info = *transaction.originalDatabaseInfo();
         m_closePending = true;
+    }
 }
 
 void IDBDatabase::didAbortTransaction(IDBTransaction& transaction)
@@ -317,7 +320,7 @@
 
     if (transaction.isVersionChange()) {
         ASSERT(transaction.originalDatabaseInfo());
-        m_info = *transaction.originalDatabaseInfo();
+        ASSERT(m_info.version() == transaction.originalDatabaseInfo()->version());
         m_closePending = true;
         m_closedInServer = true;
         m_serverConnection->databaseConnectionClosed(*this);

Modified: trunk/Source/WebCore/Modules/indexeddb/client/IDBOpenDBRequestImpl.cpp (193642 => 193643)


--- trunk/Source/WebCore/Modules/indexeddb/client/IDBOpenDBRequestImpl.cpp	2015-12-07 19:48:37 UTC (rev 193642)
+++ trunk/Source/WebCore/Modules/indexeddb/client/IDBOpenDBRequestImpl.cpp	2015-12-07 20:27:37 UTC (rev 193643)
@@ -119,8 +119,9 @@
     Ref<IDBTransaction> transaction = database->startVersionChangeTransaction(resultData.transactionInfo(), *this);
 
     ASSERT(transaction->info().mode() == IndexedDB::TransactionMode::VersionChange);
+    ASSERT(transaction->originalDatabaseInfo());
 
-    uint64_t oldVersion = database->info().version();
+    uint64_t oldVersion = transaction->originalDatabaseInfo()->version();
     uint64_t newVersion = transaction->info().newVersion();
 
     LOG(IndexedDB, "IDBOpenDBRequest::onUpgradeNeeded() - current version is %" PRIu64 ", new is %" PRIu64, oldVersion, newVersion);

Modified: trunk/Source/WebCore/Modules/indexeddb/client/IDBTransactionImpl.cpp (193642 => 193643)


--- trunk/Source/WebCore/Modules/indexeddb/client/IDBTransactionImpl.cpp	2015-12-07 19:48:37 UTC (rev 193642)
+++ trunk/Source/WebCore/Modules/indexeddb/client/IDBTransactionImpl.cpp	2015-12-07 20:27:37 UTC (rev 193643)
@@ -71,7 +71,6 @@
 
     if (m_info.mode() == IndexedDB::TransactionMode::VersionChange) {
         ASSERT(m_openDBRequest);
-        m_originalDatabaseInfo = std::make_unique<IDBDatabaseInfo>(m_database->info());
         m_startedOnServer = true;
     } else {
         activate();
@@ -326,8 +325,6 @@
 {
     ASSERT(m_state != IndexedDB::TransactionState::Finished);
     m_state = IndexedDB::TransactionState::Finished;
-
-    m_originalDatabaseInfo = nullptr;
 }
 
 void IDBTransaction::didStart(const IDBError& error)

Modified: trunk/Source/WebCore/Modules/indexeddb/client/IDBTransactionImpl.h (193642 => 193643)


--- trunk/Source/WebCore/Modules/indexeddb/client/IDBTransactionImpl.h	2015-12-07 19:48:37 UTC (rev 193642)
+++ trunk/Source/WebCore/Modules/indexeddb/client/IDBTransactionImpl.h	2015-12-07 20:27:37 UTC (rev 193643)
@@ -83,10 +83,10 @@
     virtual bool hasPendingActivity() const override final;
     virtual void stop() override final;
 
-    const IDBTransactionInfo info() const { return m_info; }
+    const IDBTransactionInfo& info() const { return m_info; }
     IDBDatabase& database() { return m_database.get(); }
     const IDBDatabase& database() const { return m_database.get(); }
-    IDBDatabaseInfo* originalDatabaseInfo() const { return m_originalDatabaseInfo.get(); }
+    IDBDatabaseInfo* originalDatabaseInfo() const { return m_info.originalDatabaseInfo(); }
 
     void didStart(const IDBError&);
     void didAbort(const IDBError&);
@@ -188,7 +188,6 @@
 
     Ref<IDBDatabase> m_database;
     IDBTransactionInfo m_info;
-    std::unique_ptr<IDBDatabaseInfo> m_originalDatabaseInfo;
 
     IndexedDB::TransactionState m_state { IndexedDB::TransactionState::Inactive };
     bool m_startedOnServer { false };

Modified: trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp (193642 => 193643)


--- trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp	2015-12-07 19:48:37 UTC (rev 193642)
+++ trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp	2015-12-07 20:27:37 UTC (rev 193643)
@@ -251,6 +251,8 @@
     addOpenDatabaseConnection(*m_versionChangeDatabaseConnection);
 
     m_versionChangeTransaction = &m_versionChangeDatabaseConnection->createVersionChangeTransaction(requestedVersion);
+    m_databaseInfo->setVersion(requestedVersion);
+
     m_inProgressTransactions.set(m_versionChangeTransaction->info().identifier(), m_versionChangeTransaction);
     m_server.postDatabaseTask(createCrossThreadTask(*this, &UniqueIDBDatabase::beginTransactionInBackingStore, m_versionChangeTransaction->info()));
 
@@ -771,7 +773,8 @@
 
     if (m_versionChangeTransaction == &transaction) {
         ASSERT(&m_versionChangeTransaction->databaseConnection() == m_versionChangeDatabaseConnection);
-        m_databaseInfo->setVersion(transaction.info().newVersion());
+        ASSERT(m_databaseInfo->version() == transaction.info().newVersion());
+
         m_versionChangeTransaction = nullptr;
         m_versionChangeDatabaseConnection = nullptr;
 

Modified: trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabaseConnection.cpp (193642 => 193643)


--- trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabaseConnection.cpp	2015-12-07 19:48:37 UTC (rev 193642)
+++ trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabaseConnection.cpp	2015-12-07 20:27:37 UTC (rev 193643)
@@ -85,7 +85,7 @@
     LOG(IndexedDB, "UniqueIDBDatabaseConnection::createVersionChangeTransaction");
     ASSERT(!m_closePending);
 
-    IDBTransactionInfo info = IDBTransactionInfo::versionChange(m_connectionToClient, newVersion);
+    IDBTransactionInfo info = IDBTransactionInfo::versionChange(m_connectionToClient, m_database.info(), newVersion);
 
     Ref<UniqueIDBDatabaseTransaction> transaction = UniqueIDBDatabaseTransaction::create(*this, info);
     m_transactionMap.set(transaction->info().identifier(), &transaction.get());

Modified: trunk/Source/WebCore/Modules/indexeddb/shared/IDBTransactionInfo.cpp (193642 => 193643)


--- trunk/Source/WebCore/Modules/indexeddb/shared/IDBTransactionInfo.cpp	2015-12-07 19:48:37 UTC (rev 193642)
+++ trunk/Source/WebCore/Modules/indexeddb/shared/IDBTransactionInfo.cpp	2015-12-07 20:27:37 UTC (rev 193643)
@@ -44,15 +44,26 @@
     return result;
 }
 
-IDBTransactionInfo IDBTransactionInfo::versionChange(const IDBServer::IDBConnectionToClient& connection, uint64_t newVersion)
+IDBTransactionInfo IDBTransactionInfo::versionChange(const IDBServer::IDBConnectionToClient& connection, const IDBDatabaseInfo& originalDatabaseInfo, uint64_t newVersion)
 {
     IDBTransactionInfo result((IDBResourceIdentifier(connection)));
     result.m_mode = IndexedDB::TransactionMode::VersionChange;
     result.m_newVersion = newVersion;
+    result.m_originalDatabaseInfo = std::make_unique<IDBDatabaseInfo>(originalDatabaseInfo);
 
     return WTF::move(result);
 }
 
+IDBTransactionInfo::IDBTransactionInfo(const IDBTransactionInfo& info)
+    : m_identifier(info.identifier())
+    , m_mode(info.m_mode)
+    , m_newVersion(info.m_newVersion)
+    , m_objectStores(info.m_objectStores)
+{
+    if (info.m_originalDatabaseInfo)
+        m_originalDatabaseInfo = std::make_unique<IDBDatabaseInfo>(*info.m_originalDatabaseInfo);
+}
+
 IDBTransactionInfo IDBTransactionInfo::isolatedCopy() const
 {
     IDBTransactionInfo result(m_identifier);
@@ -63,6 +74,9 @@
     for (auto& objectStore : m_objectStores)
         result.m_objectStores.uncheckedAppend(objectStore.isolatedCopy());
 
+    if (m_originalDatabaseInfo)
+        result.m_originalDatabaseInfo = std::make_unique<IDBDatabaseInfo>(*m_originalDatabaseInfo);
+
     return WTF::move(result);
 }
 

Modified: trunk/Source/WebCore/Modules/indexeddb/shared/IDBTransactionInfo.h (193642 => 193643)


--- trunk/Source/WebCore/Modules/indexeddb/shared/IDBTransactionInfo.h	2015-12-07 19:48:37 UTC (rev 193642)
+++ trunk/Source/WebCore/Modules/indexeddb/shared/IDBTransactionInfo.h	2015-12-07 20:27:37 UTC (rev 193643)
@@ -28,6 +28,7 @@
 
 #if ENABLE(INDEXED_DATABASE)
 
+#include "IDBDatabaseInfo.h"
 #include "IDBResourceIdentifier.h"
 #include "IndexedDB.h"
 #include <wtf/Vector.h>
@@ -45,8 +46,10 @@
 class IDBTransactionInfo {
 public:
     static IDBTransactionInfo clientTransaction(const IDBClient::IDBConnectionToServer&, const Vector<String>& objectStores, IndexedDB::TransactionMode);
-    static IDBTransactionInfo versionChange(const IDBServer::IDBConnectionToClient&, uint64_t newVersion);
+    static IDBTransactionInfo versionChange(const IDBServer::IDBConnectionToClient&, const IDBDatabaseInfo& originalDatabaseInfo, uint64_t newVersion);
 
+    IDBTransactionInfo(const IDBTransactionInfo&);
+
     IDBTransactionInfo isolatedCopy() const;
 
     IDBResourceIdentifier identifier() const { return m_identifier; }
@@ -56,6 +59,8 @@
 
     const Vector<String>& objectStores() const { return m_objectStores; }
 
+    IDBDatabaseInfo* originalDatabaseInfo() const { return m_originalDatabaseInfo.get(); }
+
 private:
     IDBTransactionInfo(const IDBResourceIdentifier&);
 
@@ -64,6 +69,7 @@
     IndexedDB::TransactionMode m_mode { IndexedDB::TransactionMode::ReadOnly };
     uint64_t m_newVersion { 0 };
     Vector<String> m_objectStores;
+    std::unique_ptr<IDBDatabaseInfo> m_originalDatabaseInfo;
 };
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to