Title: [191776] trunk
Revision
191776
Author
beid...@apple.com
Date
2015-10-29 21:55:12 -0700 (Thu, 29 Oct 2015)

Log Message

Modern IDB: autoIncrement support.
https://bugs.webkit.org/show_bug.cgi?id=150695

Reviewed by Alex Christensen.

Source/WebCore:

Test: storage/indexeddb/modern/autoincrement-abort.html

* Modules/indexeddb/server/IDBBackingStore.h:
* Modules/indexeddb/server/MemoryBackingStoreTransaction.cpp:
(WebCore::IDBServer::MemoryBackingStoreTransaction::addNewObjectStore):
(WebCore::IDBServer::MemoryBackingStoreTransaction::addExistingObjectStore):
(WebCore::IDBServer::MemoryBackingStoreTransaction::abort):
* Modules/indexeddb/server/MemoryBackingStoreTransaction.h:
* Modules/indexeddb/server/MemoryIDBBackingStore.cpp:
(WebCore::IDBServer::MemoryIDBBackingStore::putRecord):
(WebCore::IDBServer::MemoryIDBBackingStore::generateKeyNumber):
* Modules/indexeddb/server/MemoryIDBBackingStore.h:
* Modules/indexeddb/server/MemoryObjectStore.h:
(WebCore::IDBServer::MemoryObjectStore::currentKeyGeneratorValue):
(WebCore::IDBServer::MemoryObjectStore::setKeyGeneratorValue):
* Modules/indexeddb/server/UniqueIDBDatabase.cpp:
(WebCore::IDBServer::UniqueIDBDatabase::performPutOrAdd):

LayoutTests:

* storage/indexeddb/modern/autoincrement-abort-expected.txt: Added.
* storage/indexeddb/modern/autoincrement-abort.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (191775 => 191776)


--- trunk/LayoutTests/ChangeLog	2015-10-30 04:30:26 UTC (rev 191775)
+++ trunk/LayoutTests/ChangeLog	2015-10-30 04:55:12 UTC (rev 191776)
@@ -1,3 +1,13 @@
+2015-10-29  Brady Eidson  <beid...@apple.com>
+
+        Modern IDB: autoIncrement support.
+        https://bugs.webkit.org/show_bug.cgi?id=150695
+
+        Reviewed by Alex Christensen.
+
+        * storage/indexeddb/modern/autoincrement-abort-expected.txt: Added.
+        * storage/indexeddb/modern/autoincrement-abort.html: Added.
+
 2015-10-29  Michael Saboff  <msab...@apple.com>
 
         Crash making a tail call from a getter to a host function

Added: trunk/LayoutTests/storage/indexeddb/modern/autoincrement-abort-expected.txt (0 => 191776)


--- trunk/LayoutTests/storage/indexeddb/modern/autoincrement-abort-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/storage/indexeddb/modern/autoincrement-abort-expected.txt	2015-10-30 04:55:12 UTC (rev 191776)
@@ -0,0 +1,32 @@
+ALERT: Initial upgrade needed: Old version - 0 New version - 1
+ALERT: Initial upgrade versionchange transaction complete
+ALERT: Opening readwrite transaction to bump the key generator, but it will be aborted
+ALERT: Key used for put was 1
+ALERT: Key used for put was 2
+ALERT: Key used for put was 3
+ALERT: Key used for put was 4
+ALERT: Key used for put was 5
+ALERT: Key used for put was 6
+ALERT: readwrite transaction abort
+ALERT: Opening readwrite transaction to make sure the key generator had successfully reverted
+ALERT: Key used for put was 1
+ALERT: Key used for put was 2
+ALERT: Key used for put was 3
+ALERT: Key used for put was 4
+ALERT: Key used for put was 5
+ALERT: Key used for put was 6
+ALERT: readwrite transaction complete
+ALERT: Opening readwrite transaction to make sure the key generator picks up where it should've left off
+ALERT: Key used for put was 7
+ALERT: Key used for put was 8
+ALERT: Key used for put was 9
+ALERT: Key used for put was 10
+ALERT: Key used for put was 11
+ALERT: Key used for put was 12
+ALERT: readwrite transaction complete
+ALERT: Done
+This test creates a new database with an objectstore that autoincrements.
+It then puts some things in that object store, checking the keys that were used.
+But it then aborts that transaction.
+Then it opens a new one and puts something in it, double checking that the key generator was reverted when the above transaction was aborted.
+

Added: trunk/LayoutTests/storage/indexeddb/modern/autoincrement-abort.html (0 => 191776)


--- trunk/LayoutTests/storage/indexeddb/modern/autoincrement-abort.html	                        (rev 0)
+++ trunk/LayoutTests/storage/indexeddb/modern/autoincrement-abort.html	2015-10-30 04:55:12 UTC (rev 191776)
@@ -0,0 +1,159 @@
+This test creates a new database with an objectstore that autoincrements.<br>
+It then puts some things in that object store, checking the keys that were used.<br>
+But it then aborts that transaction.<br>
+Then it opens a new one and puts something in it, double checking that the key generator was reverted when the above transaction was aborted.<br>
+<script>
+
+if (window.testRunner) {
+    testRunner.waitUntilDone();
+    testRunner.dumpAsText();
+}
+
+function done()
+{
+    alert("Done");
+    if (window.testRunner)
+        testRunner.notifyDone();
+}
+
+var createRequest = window.indexedDB.open("AutoincrementAbortDatabase", 1);
+var database;
+
+createRequest._onupgradeneeded_ = function(event) {
+    alert("Initial upgrade needed: Old version - " + event.oldVersion + " New version - " + event.newVersion);
+
+    var versionTransaction = createRequest.transaction;
+    database = event.target.result;
+    var objectStore = database.createObjectStore('TestObjectStore', { autoIncrement: true });
+    
+    versionTransaction._onabort_ = function(event) {
+        alert("Initial upgrade versionchange transaction unexpected abort");
+        done();
+    }
+
+    versionTransaction._oncomplete_ = function(event) {
+        alert("Initial upgrade versionchange transaction complete");
+        continueTest1();
+    }
+
+    versionTransaction._onerror_ = function(event) {
+        alert("Initial upgrade versionchange transaction unexpected error" + event);
+        done();
+    }
+}
+
+function putChecker(event) {
+    alert("Key used for put was " + event.target.result);
+}
+
+function continueTest1()
+{
+    alert("Opening readwrite transaction to bump the key generator, but it will be aborted");
+    var transaction = database.transaction('TestObjectStore', "readwrite");
+    var objectStore = transaction.objectStore('TestObjectStore');
+    
+    var request = objectStore.put("bar1");
+    request._onsuccess_ = putChecker;
+    var request = objectStore.put("bar2");
+    request._onsuccess_ = putChecker;
+    var request = objectStore.put("bar3");
+    request._onsuccess_ = putChecker;
+    var request = objectStore.put("bar4");
+    request._onsuccess_ = putChecker;
+    var request = objectStore.put("bar5");
+    request._onsuccess_ = putChecker;
+    var request = objectStore.put("bar6");
+    request._onsuccess_ = function(event) {
+        putChecker(event);
+        transaction.abort();
+    }
+    
+    transaction._onabort_ = function(event) {
+        alert("readwrite transaction abort");
+        continueTest2();
+    }
+
+    transaction._oncomplete_ = function(event) {
+        alert("readwrite transaction unexpected complete");
+        done();
+    }
+
+    transaction._onerror_ = function(event) {
+        alert("readwrite transaction unexpected error");
+        done();
+    }
+}
+
+function continueTest2()
+{
+    alert("Opening readwrite transaction to make sure the key generator had successfully reverted");
+    
+    var transaction = database.transaction('TestObjectStore', "readwrite");
+    var objectStore = transaction.objectStore('TestObjectStore');
+
+    var request = objectStore.put("bar1");
+    request._onsuccess_ = putChecker;
+    var request = objectStore.put("bar2");
+    request._onsuccess_ = putChecker;
+    var request = objectStore.put("bar3");
+    request._onsuccess_ = putChecker;
+    var request = objectStore.put("bar4");
+    request._onsuccess_ = putChecker;
+    var request = objectStore.put("bar5");
+    request._onsuccess_ = putChecker;
+    var request = objectStore.put("bar6");
+    request._onsuccess_ = putChecker;
+
+    transaction._onabort_ = function(event) {
+        alert("readwrite transaction unexpected abort");
+        done();
+    }
+
+    transaction._oncomplete_ = function(event) {
+        alert("readwrite transaction complete");
+        continueTest3();
+    }
+
+    transaction._onerror_ = function(event) {
+        alert("readwrite transaction unexpected error");
+        done();
+    }
+}
+
+function continueTest3()
+{
+    alert("Opening readwrite transaction to make sure the key generator picks up where it should've left off");
+    
+    var transaction = database.transaction('TestObjectStore', "readwrite");
+    var objectStore = transaction.objectStore('TestObjectStore');
+
+    var request = objectStore.put("bar1");
+    request._onsuccess_ = putChecker;
+    var request = objectStore.put("bar2");
+    request._onsuccess_ = putChecker;
+    var request = objectStore.put("bar3");
+    request._onsuccess_ = putChecker;
+    var request = objectStore.put("bar4");
+    request._onsuccess_ = putChecker;
+    var request = objectStore.put("bar5");
+    request._onsuccess_ = putChecker;
+    var request = objectStore.put("bar6");
+    request._onsuccess_ = putChecker;
+
+    transaction._onabort_ = function(event) {
+        alert("readwrite transaction unexpected abort");
+        done();
+    }
+
+    transaction._oncomplete_ = function(event) {
+        alert("readwrite transaction complete");
+        done();
+    }
+
+    transaction._onerror_ = function(event) {
+        alert("readwrite transaction unexpected error");
+        done();
+    }
+}
+
+</script>

Modified: trunk/Source/WebCore/ChangeLog (191775 => 191776)


--- trunk/Source/WebCore/ChangeLog	2015-10-30 04:30:26 UTC (rev 191775)
+++ trunk/Source/WebCore/ChangeLog	2015-10-30 04:55:12 UTC (rev 191776)
@@ -1,3 +1,28 @@
+2015-10-29  Brady Eidson  <beid...@apple.com>
+
+        Modern IDB: autoIncrement support.
+        https://bugs.webkit.org/show_bug.cgi?id=150695
+
+        Reviewed by Alex Christensen.
+
+        Test: storage/indexeddb/modern/autoincrement-abort.html
+
+        * Modules/indexeddb/server/IDBBackingStore.h:
+        * Modules/indexeddb/server/MemoryBackingStoreTransaction.cpp:
+        (WebCore::IDBServer::MemoryBackingStoreTransaction::addNewObjectStore):
+        (WebCore::IDBServer::MemoryBackingStoreTransaction::addExistingObjectStore):
+        (WebCore::IDBServer::MemoryBackingStoreTransaction::abort):
+        * Modules/indexeddb/server/MemoryBackingStoreTransaction.h:
+        * Modules/indexeddb/server/MemoryIDBBackingStore.cpp:
+        (WebCore::IDBServer::MemoryIDBBackingStore::putRecord):
+        (WebCore::IDBServer::MemoryIDBBackingStore::generateKeyNumber):
+        * Modules/indexeddb/server/MemoryIDBBackingStore.h:
+        * Modules/indexeddb/server/MemoryObjectStore.h:
+        (WebCore::IDBServer::MemoryObjectStore::currentKeyGeneratorValue):
+        (WebCore::IDBServer::MemoryObjectStore::setKeyGeneratorValue):
+        * Modules/indexeddb/server/UniqueIDBDatabase.cpp:
+        (WebCore::IDBServer::UniqueIDBDatabase::performPutOrAdd):
+
 2015-10-29  Alex Christensen  <achristen...@webkit.org>
 
         Make WebCore a framework in Mac CMake build

Modified: trunk/Source/WebCore/Modules/indexeddb/server/IDBBackingStore.h (191775 => 191776)


--- trunk/Source/WebCore/Modules/indexeddb/server/IDBBackingStore.h	2015-10-30 04:30:26 UTC (rev 191775)
+++ trunk/Source/WebCore/Modules/indexeddb/server/IDBBackingStore.h	2015-10-30 04:55:12 UTC (rev 191776)
@@ -57,6 +57,8 @@
     virtual IDBError deleteRecord(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyData&) = 0;
     virtual IDBError putRecord(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyData&, const ThreadSafeDataBuffer& value) = 0;
     virtual IDBError getRecord(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyData&, ThreadSafeDataBuffer& outValue) = 0;
+    virtual IDBError generateKeyNumber(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t& keyNumber) = 0;
+
 };
 
 } // namespace IDBServer

Modified: trunk/Source/WebCore/Modules/indexeddb/server/MemoryBackingStoreTransaction.cpp (191775 => 191776)


--- trunk/Source/WebCore/Modules/indexeddb/server/MemoryBackingStoreTransaction.cpp	2015-10-30 04:30:26 UTC (rev 191775)
+++ trunk/Source/WebCore/Modules/indexeddb/server/MemoryBackingStoreTransaction.cpp	2015-10-30 04:55:12 UTC (rev 191776)
@@ -60,12 +60,9 @@
     LOG(IndexedDB, "MemoryBackingStoreTransaction::addNewObjectStore()");
 
     ASSERT(isVersionChange());
-
-    ASSERT(!m_objectStores.contains(&objectStore));
-    m_objectStores.add(&objectStore);
     m_versionChangeAddedObjectStores.add(&objectStore);
 
-    objectStore.writeTransactionStarted(*this);
+    addExistingObjectStore(objectStore);
 }
 
 void MemoryBackingStoreTransaction::addExistingObjectStore(MemoryObjectStore& objectStore)
@@ -78,6 +75,8 @@
     m_objectStores.add(&objectStore);
 
     objectStore.writeTransactionStarted(*this);
+
+    m_originalKeyGenerators.add(&objectStore, objectStore.currentKeyGeneratorValue());
 }
 
 void MemoryBackingStoreTransaction::objectStoreDeleted(std::unique_ptr<MemoryObjectStore> objectStore)
@@ -136,6 +135,9 @@
     }
 
     for (auto objectStore : m_objectStores) {
+        ASSERT(m_originalKeyGenerators.contains(objectStore));
+        objectStore->setKeyGeneratorValue(m_originalKeyGenerators.get(objectStore));
+
         auto keyValueMap = m_originalValues.get(objectStore);
         if (!keyValueMap)
             continue;
@@ -148,7 +150,6 @@
         m_originalValues.remove(objectStore);
     }
 
-
     finish();
 
     for (auto objectStore : m_versionChangeAddedObjectStores)

Modified: trunk/Source/WebCore/Modules/indexeddb/server/MemoryBackingStoreTransaction.h (191775 => 191776)


--- trunk/Source/WebCore/Modules/indexeddb/server/MemoryBackingStoreTransaction.h	2015-10-30 04:30:26 UTC (rev 191775)
+++ trunk/Source/WebCore/Modules/indexeddb/server/MemoryBackingStoreTransaction.h	2015-10-30 04:55:12 UTC (rev 191776)
@@ -79,6 +79,7 @@
     HashSet<MemoryObjectStore*> m_objectStores;
     HashSet<MemoryObjectStore*> m_versionChangeAddedObjectStores;
 
+    HashMap<MemoryObjectStore*, uint64_t> m_originalKeyGenerators;
     HashMap<String, std::unique_ptr<MemoryObjectStore>> m_deletedObjectStores;
     HashMap<MemoryObjectStore*, std::unique_ptr<KeyValueMap>> m_originalValues;
 

Modified: trunk/Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.cpp (191775 => 191776)


--- trunk/Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.cpp	2015-10-30 04:30:26 UTC (rev 191775)
+++ trunk/Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.cpp	2015-10-30 04:55:12 UTC (rev 191776)
@@ -211,7 +211,7 @@
 
     auto transaction = m_transactions.get(transactionIdentifier);
     if (!transaction)
-        return IDBError(IDBExceptionCode::Unknown, WTF::ASCIILiteral("No backing store transaction found to get record"));
+        return IDBError(IDBExceptionCode::Unknown, WTF::ASCIILiteral("No backing store transaction found to put record"));
 
     MemoryObjectStore* objectStore = m_objectStoresByIdentifier.get(objectStoreIdentifier);
     if (!objectStore)
@@ -238,6 +238,22 @@
     return IDBError();
 }
 
+IDBError MemoryIDBBackingStore::generateKeyNumber(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t& keyNumber)
+{
+    LOG(IndexedDB, "MemoryIDBBackingStore::generateKeyNumber");
+    ASSERT(objectStoreIdentifier);
+    ASSERT_UNUSED(transactionIdentifier, m_transactions.contains(transactionIdentifier));
+    ASSERT_UNUSED(transactionIdentifier, m_transactions.get(transactionIdentifier)->isWriting());
+
+    MemoryObjectStore* objectStore = m_objectStoresByIdentifier.get(objectStoreIdentifier);
+    RELEASE_ASSERT(objectStore);
+
+    keyNumber = objectStore->currentKeyGeneratorValue();
+    objectStore->setKeyGeneratorValue(keyNumber + 1);
+
+    return IDBError();
+}
+
 void MemoryIDBBackingStore::registerObjectStore(std::unique_ptr<MemoryObjectStore>&& objectStore)
 {
     ASSERT(objectStore);

Modified: trunk/Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.h (191775 => 191776)


--- trunk/Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.h	2015-10-30 04:30:26 UTC (rev 191775)
+++ trunk/Source/WebCore/Modules/indexeddb/server/MemoryIDBBackingStore.h	2015-10-30 04:55:12 UTC (rev 191776)
@@ -58,6 +58,7 @@
     virtual IDBError deleteRecord(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyData&) override final;
     virtual IDBError putRecord(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyData&, const ThreadSafeDataBuffer& value) override final;
     virtual IDBError getRecord(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, const IDBKeyData&, ThreadSafeDataBuffer& outValue) override final;
+    virtual IDBError generateKeyNumber(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t& keyNumber) override final;
 
     void removeObjectStoreForVersionChangeAbort(MemoryObjectStore&);
     void restoreObjectStoreForVersionChangeAbort(std::unique_ptr<MemoryObjectStore>&&);

Modified: trunk/Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.h (191775 => 191776)


--- trunk/Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.h	2015-10-30 04:30:26 UTC (rev 191775)
+++ trunk/Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.h	2015-10-30 04:55:12 UTC (rev 191776)
@@ -60,6 +60,9 @@
 
     void setKeyValue(const IDBKeyData&, const ThreadSafeDataBuffer& value);
 
+    uint64_t currentKeyGeneratorValue() const { return m_keyGeneratorValue; }
+    void setKeyGeneratorValue(uint64_t value) { m_keyGeneratorValue = value; }
+
     ThreadSafeDataBuffer valueForKey(const IDBKeyData&) const;
 
     const IDBObjectStoreInfo& info() const { return m_info; }
@@ -70,6 +73,7 @@
     IDBObjectStoreInfo m_info;
 
     MemoryBackingStoreTransaction* m_writeTransaction { nullptr };
+    uint64_t m_keyGeneratorValue { 1 };
 
     std::unique_ptr<KeyValueMap> m_keyValueStore;
     std::unique_ptr<std::set<IDBKeyData>> m_orderedKeys;

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


--- trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp	2015-10-30 04:30:26 UTC (rev 191775)
+++ trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp	2015-10-30 04:55:12 UTC (rev 191776)
@@ -313,6 +313,7 @@
     ASSERT(m_backingStore);
     ASSERT(objectStoreIdentifier);
 
+    bool keyWasGenerated = false;
     IDBKeyData usedKey;
     IDBError error;
 
@@ -324,14 +325,18 @@
     }
 
     if (objectStoreInfo->autoIncrement() && !keyData.isValid()) {
-        // FIXME: This is where generated key support goes
-        error = IDBError(IDBExceptionCode::Unknown, ASCIILiteral("Key generators not supported yet"));
-        m_server.postDatabaseTaskReply(createCrossThreadTask(*this, &UniqueIDBDatabase::didPerformPutOrAdd, callbackIdentifier, error, usedKey));
-        return;
-    }
+        uint64_t keyNumber;
+        error = m_backingStore->generateKeyNumber(transactionIdentifier, objectStoreIdentifier, keyNumber);
+        if (!error.isNull()) {
+            m_server.postDatabaseTaskReply(createCrossThreadTask(*this, &UniqueIDBDatabase::didPerformPutOrAdd, callbackIdentifier, error, usedKey));
+            return;
+        }
+        
+        usedKey.setNumberValue(keyNumber);
+        keyWasGenerated = true;
+    } else
+        usedKey = keyData;
 
-    usedKey = keyData;
-
     if (overwriteMode == IndexedDB::ObjectStoreOverwriteMode::NoOverwrite) {
         bool keyExists;
         error = m_backingStore->keyExistsInObjectStore(transactionIdentifier, objectStoreIdentifier, usedKey, keyExists);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to