Skip to content

Commit

Permalink
Sketch out spec text for durability. Fixes #50
Browse files Browse the repository at this point in the history
  • Loading branch information
inexorabletash committed Sep 30, 2019
1 parent 29d45f4 commit b4422ef
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,21 @@ a [=/transaction=] with [=transaction/mode=] {{"readonly"}}.
A <dfn>read/write transaction</dfn>
is a [=/transaction=] with [=transaction/mode=] {{"readwrite"}}.

A [=/transaction=] has a <dfn>durability</dfn> hint. This is a hint to the user agent of whether to prioritize performance or durability when committing the transaction.

: {{"strict"}}
:: The user agent may consider that the [=/transaction=] has successfully [=transaction/committed=] only after verifying that all outstanding changes have been successfully written to a persistent storage medium.
: {{"relaxed"}}
:: The user agent may consider that the [=/transaction=] has successfully [=transaction/committed=] as soon as all outstanding changes have been written to the operating system, without subsequent verification.
: {{"default"}}
:: The user agent should use its default durability behavior for the storage [=/bucket=].

<aside class=note>
In a typical implementation, {{"strict"}} is a hint to the user agent to flush any operating system I/O buffers before a {{"complete"}} event is fired. While this provides greater confidence that the changes will be persisted in case of subsequent operating system crash or power loss, flushing buffers can take significant time and consume battery life on portable devices.

Web applications are encouraged to use {{"relaxed"}} for ephemeral data such as caches or quickly changing records, and {{"strict"}} in cases where reducing the risk of data loss outweighs the impact to performance and power. Implementations are encouraged to weigh the durability hint from applications against the impact to users and devices.
</aside>

<!-- ============================================================ -->
### Transaction Lifecycle ### {#transaction-lifecycle}
<!-- ============================================================ -->
Expand Down Expand Up @@ -2449,7 +2464,8 @@ interface IDBDatabase : EventTarget {
readonly attribute DOMStringList objectStoreNames;

[NewObject] IDBTransaction transaction((DOMString or sequence<DOMString>) storeNames,
optional IDBTransactionMode mode = "readonly");
optional IDBTransactionMode mode = "readonly",
optional IDBTransactionOptions options = {});
void close();

[NewObject] IDBObjectStore createObjectStore(
Expand All @@ -2464,6 +2480,12 @@ interface IDBDatabase : EventTarget {
attribute EventHandler onversionchange;
};

enum IDBTransactionDurability { "default", "strict", "relaxed" };

dictionary IDBTransactionOptions {
IDBTransactionDurability durability = "default";
};

dictionary IDBObjectStoreParameters {
(DOMString or sequence<DOMString>)? keyPath = null;
boolean autoIncrement = false;
Expand Down Expand Up @@ -2661,8 +2683,7 @@ instance on which it was called.

<div class=algorithm>

The <dfn method for=IDBDatabase>transaction(|storeNames|,
|mode|)</dfn> method, when invoked, must run these steps:
The <dfn method for=IDBDatabase>transaction(|storeNames|, |mode|, |options|)</dfn> method, when invoked, must run these steps:

1. If a running [=/upgrade transaction=] is associated with the [=/connection=],
[=throw=] an "{{InvalidStateError}}" {{DOMException}}.
Expand All @@ -2683,9 +2704,7 @@ The <dfn method for=IDBDatabase>transaction(|storeNames|,
1. If |mode| is not {{"readonly"}} or {{"readwrite"}},
[=throw=] a [=TypeError=].

1. Let |transaction| be a newly [=transaction/created=] [=/transaction=] with
|connection|, |mode| and the set of [=/object stores=] named in
|scope|.
1. Let |transaction| be a newly [=transaction/created=] [=/transaction=] with |connection|, |mode|, |options|' {{IDBTransactionOptions/durability}} member, and the set of [=/object stores=] named in |scope|.

1. Set |transaction|'s [=transaction/cleanup event loop=] to the
current [=event loop=].
Expand Down Expand Up @@ -4860,6 +4879,8 @@ attribute's getter must run these steps:
The <dfn attribute for=IDBTransaction>mode</dfn> attribute's getter
must return **this**'s [=transaction/mode=].

The <dfn attribute for=IDBTransaction>durability</dfn> attribute's getter must return the [=transaction/durability=] of the [=/transaction=].

The <dfn attribute for=IDBTransaction>db</dfn> attribute's getter must
return **this**'s [=transaction/connection=]'s associated [=/database=].

Expand Down Expand Up @@ -5198,7 +5219,7 @@ To <dfn>commit a transaction</dfn> with the |transaction| to commit, run these s
1. If |transaction|'s [=transaction/state=] is no longer [=transaction/committing=],
then terminate these steps.

1. Attempt to write any outstanding changes made by |transaction| to the [=database=].
1. Attempt to write any outstanding changes made by |transaction| to the [=database=], considering |transaction|'s [=transaction/durability=] hint.

1. If an error occurs while writing the changes to the [=database=],
then run [=abort a transaction=] with |transaction| and an
Expand Down Expand Up @@ -6814,6 +6835,7 @@ For the revision history of the second edition, see [that document's Revision Hi
* Added {{IDBCursor/request}} attribute. ([Issue #255](https://github.com/w3c/IndexedDB/issues/255))
* Removed handling for nonstandard `lastModifiedDate` property of {{File}} objects. ([Issue #215](https://github.com/w3c/IndexedDB/issues/215))
* Remove escaping {{IDBKeyRange/includes()}} method. ([Issue #294](https://github.com/w3c/IndexedDB/issues/294))
* Added {{IDBTransactionOptions/durability}} option and {{IDBTransaction/durability}} attribute. ([Issue #50](https://github.com/w3c/IndexedDB/issues/50))

<!-- ============================================================ -->
# Acknowledgements # {#acknowledgements}
Expand Down Expand Up @@ -6877,6 +6899,7 @@ Yaron Tausky,
Bevis Tseng,
Ben Turner,
Kyaw Tun,
Adrienne Walker,
Hans Wennborg,
Shawn Wilsher,
Brett Zamir,
Expand Down

0 comments on commit b4422ef

Please sign in to comment.