Bug 157843

Summary: Modern IDB: Add support for server side closing of open database connections
Product: WebKit Reporter: Brady Eidson <beidson>
Component: WebCore Misc.Assignee: Brady Eidson <beidson>
Status: RESOLVED FIXED    
Severity: Normal CC: achristensen, alecflett, commit-queue, jsbell
Priority: P2    
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 149117, 157626    
Attachments:
Description Flags
Patch v1
achristensen: review+
Patch for landing none

Description Brady Eidson 2016-05-18 09:25:32 PDT
Modern IDB: Add support for server side closing of open database connections

This is to support https://bugs.webkit.org/show_bug.cgi?id=157626
Comment 1 Brady Eidson 2016-05-18 09:28:32 PDT
When the IDBServer decides to close a database connection itself, a lot of cleanup has to take place.

The server has to:
- Error out all requests it knows about
- Abort all transactions it knows about
- Tell the connection that it is being closed
- Wait for the connection to acknowledge that it was closed on the server

The client has to:
- Error out all requests it hasn't sent to the server
- Abort all transactions that haven't already been aborted by the server
- Send acknowledgement to the server that it has been closed.

Additionally, because of the asynchronous nature of requests being "in flight" between the client and server, a few design assumptions change, requiring changing some asserts and null checks to be graceful failures, etc etc.
Comment 2 Brady Eidson 2016-05-18 11:49:11 PDT
Created attachment 279266 [details]
Patch v1
Comment 3 WebKit Commit Bot 2016-05-18 11:50:55 PDT
Attachment 279266 [details] did not pass style-queue:


ERROR: Source/WebCore/Modules/indexeddb/server/IDBServer.cpp:488:  Extra space before ( in function call  [whitespace/parens] [4]
ERROR: Source/WebCore/Modules/indexeddb/server/IDBServer.cpp:510:  Extra space before ( in function call  [whitespace/parens] [4]
ERROR: Source/WebCore/Modules/indexeddb/server/IDBServer.h:101:  Extra space before ( in function call  [whitespace/parens] [4]
ERROR: Source/WebCore/Modules/indexeddb/server/IDBServer.h:134:  Extra space before ( in function call  [whitespace/parens] [4]
Total errors found: 4 in 38 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 4 Alex Christensen 2016-05-18 12:06:28 PDT
Comment on attachment 279266 [details]
Patch v1

View in context: https://bugs.webkit.org/attachment.cgi?id=279266&action=review

> Source/WebCore/Modules/indexeddb/IDBTransaction.cpp:1087
> +    Vector<RefPtr<IDBClient::TransactionOperation>> operations;
> +    operations.reserveInitialCapacity(m_transactionOperationMap.size());
> +    for (auto& operation : m_transactionOperationMap.values())
> +        operations.uncheckedAppend(operation);

copyValuesToVector

> Source/WebCore/Modules/indexeddb/server/IDBServer.cpp:495
> +    // If the modification time is in the future, don't both doing anything.
> +    if (modificationTime > std::chrono::system_clock::now()) {

Is this really a common case worth optimizing for?

> Source/WebCore/Modules/indexeddb/server/IDBServer.cpp:519
> +    for (auto* connection : m_databaseConnections.values()) {
> +        const auto& identifier = connection->database().identifier();
> +        for (auto& origin : origins) {

This could get slow if there are a lot of origins and connections.  Is there any way to use a HashSet or something?
Comment 5 Brady Eidson 2016-05-18 12:24:46 PDT
(In reply to comment #4)
> Comment on attachment 279266 [details]
> Patch v1
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=279266&action=review
> 
> > Source/WebCore/Modules/indexeddb/IDBTransaction.cpp:1087
> > +    Vector<RefPtr<IDBClient::TransactionOperation>> operations;
> > +    operations.reserveInitialCapacity(m_transactionOperationMap.size());
> > +    for (auto& operation : m_transactionOperationMap.values())
> > +        operations.uncheckedAppend(operation);
> 
> copyValuesToVector

Yup.

> 
> > Source/WebCore/Modules/indexeddb/server/IDBServer.cpp:495
> > +    // If the modification time is in the future, don't both doing anything.
> > +    if (modificationTime > std::chrono::system_clock::now()) {
> 
> Is this really a common case worth optimizing for?

The commonality is indeterminate, since this is directly exposed as API.
The optimization definitely seems worthwhile because skipping it would involve performing a whole bunch of i/o just to do nothing.
 
> > Source/WebCore/Modules/indexeddb/server/IDBServer.cpp:519
> > +    for (auto* connection : m_databaseConnections.values()) {
> > +        const auto& identifier = connection->database().identifier();
> > +        for (auto& origin : origins) {
> 
> This could get slow if there are a lot of origins and connections.  Is there
> any way to use a HashSet or something?

The common case for known usage of this API is 1 origin.

For 1 origin, the Vector impl is faster and more space efficient than a HashSet, even before allowing for the construction of the HashSet itself.

I agree that if 1000's of origins came in the HashSet would be clearly superior, but in that case the entire operation will be very long running.

Especially since we have no reason to believe that happens, combined with the fact that this is already not blocking the main thread of either the Web or UI process, I think that is a premature optimization.
Comment 6 Brady Eidson 2016-05-18 12:26:57 PDT
The patch is obviously causing havoc with the imported w3c tests (which I hadn't run locally, as I always assume storage/indexeddb is a better suite anyways)

Checking that locally...
Comment 7 Brady Eidson 2016-05-18 12:45:46 PDT
(In reply to comment #6)
> The patch is obviously causing havoc with the imported w3c tests (which I
> hadn't run locally, as I always assume storage/indexeddb is a better suite
> anyways)
> 
> Checking that locally...

Never mind, nothing to see here.

Charge forward.
Comment 8 Brady Eidson 2016-05-18 13:12:25 PDT
Created attachment 279278 [details]
Patch for landing
Comment 9 WebKit Commit Bot 2016-05-18 13:15:03 PDT
Attachment 279278 [details] did not pass style-queue:


ERROR: Source/WebCore/Modules/indexeddb/server/IDBServer.cpp:488:  Extra space before ( in function call  [whitespace/parens] [4]
ERROR: Source/WebCore/Modules/indexeddb/server/IDBServer.cpp:510:  Extra space before ( in function call  [whitespace/parens] [4]
ERROR: Source/WebCore/Modules/indexeddb/server/IDBServer.h:101:  Extra space before ( in function call  [whitespace/parens] [4]
ERROR: Source/WebCore/Modules/indexeddb/server/IDBServer.h:134:  Extra space before ( in function call  [whitespace/parens] [4]
Total errors found: 4 in 38 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 10 WebKit Commit Bot 2016-05-18 13:41:25 PDT
Comment on attachment 279278 [details]
Patch for landing

Clearing flags on attachment: 279278

Committed r201098: <http://trac.webkit.org/changeset/201098>
Comment 11 WebKit Commit Bot 2016-05-18 13:41:32 PDT
All reviewed patches have been landed.  Closing bug.