Bug 228289

Summary: Implement IDBTransaction.durability
Product: WebKit Reporter: Sihui Liu <sihui_liu>
Component: WebCore Misc.Assignee: Sihui Liu <sihui_liu>
Status: RESOLVED FIXED    
Severity: Normal CC: achristensen, alecflett, annulen, beidson, cdumez, darin, esprehn+autocc, ews-watchlist, ggaren, gyuyoung.kim, jsbell, kondapallykalyan, nham, ryuan.choi, sergio, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
none
Patch for landing none

Description Sihui Liu 2021-07-26 11:38:48 PDT
...
Comment 1 Sihui Liu 2021-07-26 11:51:26 PDT
Created attachment 434221 [details]
Patch
Comment 2 Sihui Liu 2021-07-27 12:06:50 PDT
Created attachment 434306 [details]
Patch
Comment 3 Sihui Liu 2021-07-27 14:17:24 PDT
Created attachment 434312 [details]
Patch
Comment 4 Chris Dumez 2021-07-28 09:51:34 PDT
Comment on attachment 434312 [details]
Patch

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

> Source/WebCore/Modules/indexeddb/IDBDatabase.h:67
> +        TransactionOptions() : durability() { }

What does it mean to initialize `durability()` when it is an enum class? Shouldn't we use IDBTransactionDurability::Default?

> Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp:1155
> +            WTFLogAlways("sihuil: [%p]SQLiteIDBBackingStore::commitTransaction durability strict", this);

OOPS.
Comment 5 Alex Christensen 2021-07-28 09:53:20 PDT
Comment on attachment 434312 [details]
Patch

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

> Source/WebCore/Modules/indexeddb/IDBTransactionDurability.h:32
> +enum class IDBTransactionDurability {

: uint8_t
Comment 6 Darin Adler 2021-07-28 10:00:42 PDT
Comment on attachment 434312 [details]
Patch

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

>> Source/WebCore/Modules/indexeddb/IDBDatabase.h:67
>> +        TransactionOptions() : durability() { }
> 
> What does it mean to initialize `durability()` when it is an enum class? Shouldn't we use IDBTransactionDurability::Default?

It will give us the first value in the enumeration, so it will set it to IDBTransactionDurability::String; so I agree that we should either use IDBTransactionDurability::Default or reorder the enumeration values. But also, this can, and should, be done with member initialization syntax rather than a constructor.

    IDBTransactionDurability durability { IDBTransactionDurability::Default };

We should add test coverage, because the wrong default value should be observable.
Comment 7 Darin Adler 2021-07-28 10:16:02 PDT
Comment on attachment 434312 [details]
Patch

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

> Source/WebCore/platform/sql/SQLiteDatabase.h:100
> +    enum class CheckpointMode : uint8_t { Passive, Full, Restart, Truncate };

These constants need to match the values expected by sqlite3_wal_checkpoint_v2. So reordering them or adding a new value would create a big problem. I can see think of two ways to handle this:

1) Could add four static_assert checks to make sure these values match values like SQLITE_CHECKPOINT_PASSIVE. Those would go into the implementation file, so would not pollute the header.
2) Could convert from our CheckpointMode to SQLITE_CHECKPOINT_* constants with a switch statement instead of by casting to int.

Or maybe you can think of another solution.

> Source/WebCore/platform/sql/SQLiteDatabase.h:101
> +    int checkpoint(CheckpointMode);

This should return void. If we wanted it to return a result, we would need to define what the return value means. Just passing through the integer from the sqlite3_wal_checkpoint_v2 call doesn’t seem reasonable from an encapsulation point of view.

Better, all of this should be private. I don’t see any clients outside SQLiteDatabase.cpp. Maybe not members at all. This entire thing could be kept inside the implementation file without touching the header.
Comment 8 Sihui Liu 2021-07-28 10:36:14 PDT
(In reply to Chris Dumez from comment #4)
> Comment on attachment 434312 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=434312&action=review
> 
> > Source/WebCore/Modules/indexeddb/IDBDatabase.h:67
> > +        TransactionOptions() : durability() { }
> 
> What does it mean to initialize `durability()` when it is an enum class?
> Shouldn't we use IDBTransactionDurability::Default?

Yes, it should be IDBTransactionDurability::Default.

> 
> > Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp:1155
> > +            WTFLogAlways("sihuil: [%p]SQLiteIDBBackingStore::commitTransaction durability strict", this);
> 
> OOPS.

OOPS, will remove.
Comment 9 Sihui Liu 2021-07-28 10:37:16 PDT
(In reply to Darin Adler from comment #6)
> Comment on attachment 434312 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=434312&action=review
> 
> >> Source/WebCore/Modules/indexeddb/IDBDatabase.h:67
> >> +        TransactionOptions() : durability() { }
> > 
> > What does it mean to initialize `durability()` when it is an enum class? Shouldn't we use IDBTransactionDurability::Default?
> 
> It will give us the first value in the enumeration, so it will set it to
> IDBTransactionDurability::String; so I agree that we should either use
> IDBTransactionDurability::Default or reorder the enumeration values. But
> also, this can, and should, be done with member initialization syntax rather
> than a constructor.
> 
>     IDBTransactionDurability durability { IDBTransactionDurability::Default
> };
> 
> We should add test coverage, because the wrong default value should be
> observable.

Will add.
Comment 10 Sihui Liu 2021-07-28 10:40:19 PDT
(In reply to Darin Adler from comment #7)
> Comment on attachment 434312 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=434312&action=review
> 
> > Source/WebCore/platform/sql/SQLiteDatabase.h:100
> > +    enum class CheckpointMode : uint8_t { Passive, Full, Restart, Truncate };
> 
> These constants need to match the values expected by
> sqlite3_wal_checkpoint_v2. So reordering them or adding a new value would
> create a big problem. I can see think of two ways to handle this:
> 
> 1) Could add four static_assert checks to make sure these values match
> values like SQLITE_CHECKPOINT_PASSIVE. Those would go into the
> implementation file, so would not pollute the header.
> 2) Could convert from our CheckpointMode to SQLITE_CHECKPOINT_* constants
> with a switch statement instead of by casting to int.
> 
> Or maybe you can think of another solution.

2) sounds good to me. Will change.

> 
> > Source/WebCore/platform/sql/SQLiteDatabase.h:101
> > +    int checkpoint(CheckpointMode);
> 
> This should return void. If we wanted it to return a result, we would need
> to define what the return value means. Just passing through the integer from
> the sqlite3_wal_checkpoint_v2 call doesn’t seem reasonable from an
> encapsulation point of view.

Okay, will change to void.

> 
> Better, all of this should be private. I don’t see any clients outside
> SQLiteDatabase.cpp. Maybe not members at all. This entire thing could be
> kept inside the implementation file without touching the header.

SQLiteIDBBackingStore uses this to force writing data back to file.
Comment 11 Sihui Liu 2021-07-28 13:26:54 PDT
Created attachment 434455 [details]
Patch
Comment 12 Darin Adler 2021-07-28 14:42:39 PDT
Comment on attachment 434455 [details]
Patch

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

> Source/WebCore/platform/sql/SQLiteDatabase.h:100
> +    enum class CheckpointMode : uint8_t { Passive, Full, Restart, Truncate };

Since WebKit is only using Full and Truncate, can we leave Passive and Restart out for now? We can add then if we find we need the modes.
Comment 13 Sihui Liu 2021-07-28 20:04:23 PDT
Created attachment 434492 [details]
Patch for landing
Comment 14 Sihui Liu 2021-07-28 20:05:04 PDT
(In reply to Darin Adler from comment #12)
> Comment on attachment 434455 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=434455&action=review
> 
> > Source/WebCore/platform/sql/SQLiteDatabase.h:100
> > +    enum class CheckpointMode : uint8_t { Passive, Full, Restart, Truncate };
> 
> Since WebKit is only using Full and Truncate, can we leave Passive and
> Restart out for now? We can add then if we find we need the modes.

Sure, removed.
Comment 15 EWS 2021-07-28 21:04:26 PDT
Committed r280415 (240055@main): <https://commits.webkit.org/240055@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 434492 [details].
Comment 16 Radar WebKit Bug Importer 2021-07-28 21:05:17 PDT
<rdar://problem/81251758>