Skip to content

Commit

Permalink
IndexedDB 2.0: Queue up completed requests in the client, handle them…
Browse files Browse the repository at this point in the history
… one by one.

https://bugs.webkit.org/show_bug.cgi?id=165000

Reviewed by Alex Christensen.

Source/WebCore:

No new tests (Covered extensively by every existing test).

Currently when a TransactionOperation completes on the server, it immediately completes
itself on the client side, including scheduling an event dispatch if necessary.

This patch changes it so that "server completed operations" instead queue up in the
IDBTransaction and are "client-side completed" asynchronously, 1-by-1.

Currently this is a "no behavior change" because only one operation is ever sent to
the server at a time.

But that will change with https://webkit.org/b/164932
And this patch is a pre-requisite for that.

* Modules/indexeddb/IDBRequest.cpp:
(WebCore::IDBRequest::dispatchEvent):
(WebCore::IDBRequest::didOpenOrIterateCursor):
(WebCore::IDBRequest::completeRequestAndDispatchEvent):
(WebCore::IDBRequest::requestCompleted): Deleted.
* Modules/indexeddb/IDBRequest.h:

* Modules/indexeddb/IDBTransaction.cpp:
(WebCore::IDBTransaction::IDBTransaction):
(WebCore::IDBTransaction::internalAbort):
(WebCore::IDBTransaction::abortOnServerAndCancelRequests):
(WebCore::IDBTransaction::scheduleOperation):
(WebCore::IDBTransaction::schedulePendingOperationTimer):
(WebCore::IDBTransaction::pendingOperationTimerFired):
(WebCore::IDBTransaction::operationCompletedOnServer):
(WebCore::IDBTransaction::scheduleCompletedOperationTimer):
(WebCore::IDBTransaction::completedOperationTimerFired):
(WebCore::IDBTransaction::completeNoncursorRequest):
(WebCore::IDBTransaction::completeCursorRequest):
(WebCore::IDBTransaction::finishedDispatchEventForRequest):
(WebCore::IDBTransaction::didStart):
(WebCore::IDBTransaction::didOpenCursorOnServer):
(WebCore::IDBTransaction::didIterateCursorOnServer):
(WebCore::IDBTransaction::didGetAllRecordsOnServer):
(WebCore::IDBTransaction::didGetRecordOnServer):
(WebCore::IDBTransaction::didGetCountOnServer):
(WebCore::IDBTransaction::didDeleteRecordOnServer):
(WebCore::IDBTransaction::didClearObjectStoreOnServer):
(WebCore::IDBTransaction::putOrAddOnServer):
(WebCore::IDBTransaction::didPutOrAddOnServer):
(WebCore::IDBTransaction::operationCompletedOnClient):
(WebCore::IDBTransaction::deactivate):
(WebCore::IDBTransaction::connectionClosedFromServer):
(WebCore::IDBTransaction::scheduleOperationTimer): Deleted.
(WebCore::IDBTransaction::operationTimerFired): Deleted.
(WebCore::IDBTransaction::operationDidComplete): Deleted.
* Modules/indexeddb/IDBTransaction.h:

* Modules/indexeddb/client/IDBConnectionProxy.cpp:
(WebCore::IDBClient::IDBConnectionProxy::completeOperation):

* Modules/indexeddb/client/TransactionOperation.cpp:
(WebCore::IDBClient::TransactionOperation::TransactionOperation):
* Modules/indexeddb/client/TransactionOperation.h:
(WebCore::IDBClient::TransactionOperation::transitionToCompleteOnThisThread):
(WebCore::IDBClient::TransactionOperation::transitionToComplete):
(WebCore::IDBClient::TransactionOperation::doComplete):
(WebCore::IDBClient::TransactionOperation::idbRequest):
(WebCore::IDBClient::TransactionOperation::performCompleteOnOriginThread): Deleted.
(WebCore::IDBClient::TransactionOperation::completed): Deleted.

LayoutTests:

* storage/indexeddb/modern/resources/transaction-scheduler-6.js: This test had a bug which was masked by previously
  synchronous behavior. Fix that bug!


Canonical link: https://commits.webkit.org/182759@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@209069 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
beidson committed Nov 29, 2016
1 parent 159c6ff commit 4f9eaff
Show file tree
Hide file tree
Showing 11 changed files with 246 additions and 69 deletions.
10 changes: 10 additions & 0 deletions LayoutTests/ChangeLog
@@ -1,3 +1,13 @@
2016-11-29 Brady Eidson <beidson@apple.com>

IndexedDB 2.0: Queue up completed requests in the client, handle them one by one.
https://bugs.webkit.org/show_bug.cgi?id=165000

Reviewed by Alex Christensen.

* storage/indexeddb/modern/resources/transaction-scheduler-6.js: This test had a bug which was masked by previously
synchronous behavior. Fix that bug!

2016-11-29 Zalan Bujtas <zalan@apple.com>

Safari (WebKit) doesn't wrap element within flex when width comes below min-width
Expand Down
Expand Up @@ -3,6 +3,10 @@ It verifies that the read-write doesn't start until both read-onlys have finishe

indexedDBTest(prepareDatabase);

function log(msg)
{
debug(msg);
}

function done()
{
Expand All @@ -13,30 +17,30 @@ var database;

function prepareDatabase(event)
{
debug("Upgrade needed: Old version - " + event.oldVersion + " New version - " + event.newVersion);
log("Upgrade needed: Old version - " + event.oldVersion + " New version - " + event.newVersion);

var versionTransaction = event.target.transaction;
database = event.target.result;
var objectStore = database.createObjectStore("TestObjectStore");
var request = objectStore.put("foo", "bar");

request.onerror = function(event) {
debug("put FAILED - " + event);
log("put FAILED - " + event);
done();
}

versionTransaction.onabort = function(event) {
debug("versionchange transaction aborted");
log("versionchange transaction aborted");
done();
}

versionTransaction.oncomplete = function(event) {
debug("versionchange transaction completed");
log("versionchange transaction completed");
continueTest();
}

versionTransaction.onerror = function(event) {
debug("versionchange transaction error'ed - " + event);
log("versionchange transaction error'ed - " + event);
done();
}
}
Expand All @@ -51,26 +55,26 @@ function continueTest()
var request = objectStore.put("baz", "foo");

request.onsuccess = function(event) {
debug("Write in readwrite transaction succeeded");
log("Write in readwrite transaction succeeded");
}

request.onerror = function(event) {
debug("Write in readwrite transaction unexpectedly failed");
log("Write in readwrite transaction unexpectedly failed");
done();
}

transaction.onabort = function(event) {
debug("readwrite transaction expectedly aborted");
log("readwrite transaction expectedly aborted");
done();
}

transaction.oncomplete = function(event) {
debug("readwrite transaction completed");
log("readwrite transaction completed");
done();
}

transaction.onerror = function(event) {
debug("readwrite transaction error'ed - " + event);
log("readwrite transaction error'ed - " + event);
done();
}
}
Expand All @@ -84,7 +88,7 @@ function startTransactionLoop(transaction, isFirstTime)

request.onsuccess = function(event) {
if (isFirstTime) {
debug("Starting a readonly transaction");
log("Starting a readonly transaction");
numberOfOpenTransactions++;
}

Expand All @@ -95,24 +99,22 @@ function startTransactionLoop(transaction, isFirstTime)
}

request.onerror = function(event) {
debug("Unexpected request error - " + event);
log("Unexpected request error - " + event);
done();
}

transaction.onerror = function(event) {
debug("Unexpected transaction error - " + event);
log("Unexpected transaction error - " + event);
done();
}

transaction.onabort = function(event) {
--numberOfOpenTransactions;
debug("Unexpected transaction abort - " + event);
log("Unexpected transaction abort - " + event);
done();
}

transaction.oncomplete = function(event) {
--numberOfOpenTransactions;
debug("readonly transaction completed");
log("readonly transaction completed");
}
}

Expand Down
72 changes: 72 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,75 @@
2016-11-29 Brady Eidson <beidson@apple.com>

IndexedDB 2.0: Queue up completed requests in the client, handle them one by one.
https://bugs.webkit.org/show_bug.cgi?id=165000

Reviewed by Alex Christensen.

No new tests (Covered extensively by every existing test).

Currently when a TransactionOperation completes on the server, it immediately completes
itself on the client side, including scheduling an event dispatch if necessary.

This patch changes it so that "server completed operations" instead queue up in the
IDBTransaction and are "client-side completed" asynchronously, 1-by-1.

Currently this is a "no behavior change" because only one operation is ever sent to
the server at a time.

But that will change with https://webkit.org/b/164932
And this patch is a pre-requisite for that.

* Modules/indexeddb/IDBRequest.cpp:
(WebCore::IDBRequest::dispatchEvent):
(WebCore::IDBRequest::didOpenOrIterateCursor):
(WebCore::IDBRequest::completeRequestAndDispatchEvent):
(WebCore::IDBRequest::requestCompleted): Deleted.
* Modules/indexeddb/IDBRequest.h:

* Modules/indexeddb/IDBTransaction.cpp:
(WebCore::IDBTransaction::IDBTransaction):
(WebCore::IDBTransaction::internalAbort):
(WebCore::IDBTransaction::abortOnServerAndCancelRequests):
(WebCore::IDBTransaction::scheduleOperation):
(WebCore::IDBTransaction::schedulePendingOperationTimer):
(WebCore::IDBTransaction::pendingOperationTimerFired):
(WebCore::IDBTransaction::operationCompletedOnServer):
(WebCore::IDBTransaction::scheduleCompletedOperationTimer):
(WebCore::IDBTransaction::completedOperationTimerFired):
(WebCore::IDBTransaction::completeNoncursorRequest):
(WebCore::IDBTransaction::completeCursorRequest):
(WebCore::IDBTransaction::finishedDispatchEventForRequest):
(WebCore::IDBTransaction::didStart):
(WebCore::IDBTransaction::didOpenCursorOnServer):
(WebCore::IDBTransaction::didIterateCursorOnServer):
(WebCore::IDBTransaction::didGetAllRecordsOnServer):
(WebCore::IDBTransaction::didGetRecordOnServer):
(WebCore::IDBTransaction::didGetCountOnServer):
(WebCore::IDBTransaction::didDeleteRecordOnServer):
(WebCore::IDBTransaction::didClearObjectStoreOnServer):
(WebCore::IDBTransaction::putOrAddOnServer):
(WebCore::IDBTransaction::didPutOrAddOnServer):
(WebCore::IDBTransaction::operationCompletedOnClient):
(WebCore::IDBTransaction::deactivate):
(WebCore::IDBTransaction::connectionClosedFromServer):
(WebCore::IDBTransaction::scheduleOperationTimer): Deleted.
(WebCore::IDBTransaction::operationTimerFired): Deleted.
(WebCore::IDBTransaction::operationDidComplete): Deleted.
* Modules/indexeddb/IDBTransaction.h:

* Modules/indexeddb/client/IDBConnectionProxy.cpp:
(WebCore::IDBClient::IDBConnectionProxy::completeOperation):

* Modules/indexeddb/client/TransactionOperation.cpp:
(WebCore::IDBClient::TransactionOperation::TransactionOperation):
* Modules/indexeddb/client/TransactionOperation.h:
(WebCore::IDBClient::TransactionOperation::transitionToCompleteOnThisThread):
(WebCore::IDBClient::TransactionOperation::transitionToComplete):
(WebCore::IDBClient::TransactionOperation::doComplete):
(WebCore::IDBClient::TransactionOperation::idbRequest):
(WebCore::IDBClient::TransactionOperation::performCompleteOnOriginThread): Deleted.
(WebCore::IDBClient::TransactionOperation::completed): Deleted.

2016-11-29 Zalan Bujtas <zalan@apple.com>

Safari (WebKit) doesn't wrap element within flex when width comes below min-width
Expand Down
7 changes: 5 additions & 2 deletions Source/WebCore/Modules/indexeddb/IDBRequest.cpp
Expand Up @@ -304,6 +304,9 @@ bool IDBRequest::dispatchEvent(Event& event)
m_transaction->abortDueToFailedRequest(*m_domError);
}

if (m_transaction)
m_transaction->finishedDispatchEventForRequest(*this);

return dontPreventDefault;
}

Expand Down Expand Up @@ -465,10 +468,10 @@ void IDBRequest::didOpenOrIterateCursor(const IDBResultData& resultData)
m_cursorRequestNotifier = nullptr;
m_pendingCursor = nullptr;

requestCompleted(resultData);
completeRequestAndDispatchEvent(resultData);
}

void IDBRequest::requestCompleted(const IDBResultData& resultData)
void IDBRequest::completeRequestAndDispatchEvent(const IDBResultData& resultData)
{
ASSERT(currentThread() == originThreadID());

Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/indexeddb/IDBRequest.h
Expand Up @@ -87,7 +87,7 @@ class IDBRequest : public EventTargetWithInlineData, public IDBActiveDOMObject,
using RefCounted::ref;
using RefCounted::deref;

void requestCompleted(const IDBResultData&);
void completeRequestAndDispatchEvent(const IDBResultData&);

void setResult(const IDBKeyData&);
void setResult(const Vector<IDBKeyData>&);
Expand Down

0 comments on commit 4f9eaff

Please sign in to comment.