Skip to content

Commit 43dfcf1

Browse files
Disambiguate "running" for transactions (#409)
The phrase "a transaction is running" was not normatively defined and confusing given the complex lifecycle of transactions. Introduce a new definition for "live" which covers from a transactions creation until it is finished. Also, rename "running an upgrade transaction" since steps are often invoked with "run" and that could get awkward. Simplify to "upgrade a database". No behavior changes, just normative terminology definitions. Resolves #408. Thanks to @evanstade the issue and suggestions. Co-authored-by: Austin Sullivan <[email protected]>
1 parent 9cd66f0 commit 43dfcf1

File tree

1 file changed

+31
-27
lines changed

1 file changed

+31
-27
lines changed

index.bs

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ A [=/connection=] has an <dfn>object store set</dfn>, which is
474474
initialized to the set of [=/object stores=] in the associated
475475
[=/database=] when the [=/connection=] is created. The contents of the
476476
set will remain constant except when an [=/upgrade transaction=] is
477-
running.
477+
[=transaction/live=].
478478

479479
A [=/connection=]'s [=get the parent=] algorithm returns
480480
null.
@@ -553,13 +553,13 @@ An [=/object store handle=] has an <dfn>index set</dfn>, which is
553553
initialized to the set of [=/indexes=] that reference the associated
554554
[=object-store-handle/object store=] when the [=/object store handle=]
555555
is created. The contents of the set will remain constant except when
556-
an [=/upgrade transaction=] is running.
556+
an [=/upgrade transaction=] is [=transaction/live=].
557557

558558
An [=/object store handle=] has a <dfn>name</dfn>, which is
559559
initialized to the [=object-store/name=] of the associated
560560
[=object-store-handle/object store=] when the [=/object store handle=]
561561
is created. The name will remain constant except when an [=/upgrade
562-
transaction=] is running.
562+
transaction=] is [=transaction/live=].
563563

564564
</div>
565565

@@ -866,7 +866,7 @@ particular [=/index=] within a [=/transaction=].
866866
An [=index handle=] has a <dfn>name</dfn>, which is initialized to the
867867
[=index/name=] of the associated [=index-handle/index=] when the
868868
[=index handle=] is created. The name will remain constant except when
869-
an [=/upgrade transaction=] is running.
869+
an [=/upgrade transaction=] is [=transaction/live=].
870870

871871
</div>
872872

@@ -905,7 +905,7 @@ following:
905905
::
906906
The transaction is only allowed to read data. No modifications can
907907
be done by this type of transaction. This has the advantage that
908-
several [=transaction/read-only transactions=] can run at the same time even
908+
several [=transaction/read-only transactions=] can be [=transaction/started=] at the same time even
909909
if their [=transaction/scopes=] are [=transaction/overlapping=], i.e. if they are using the
910910
same object stores. This type of transaction can be created any
911911
time once a database has been opened.
@@ -915,7 +915,7 @@ following:
915915
The transaction is allowed to read, modify and delete data from
916916
existing object stores. However object stores and indexes can't be
917917
added or removed. Multiple "{{IDBTransactionMode/readwrite}}" transactions
918-
can't run at the same time if their [=transaction/scopes=] are [=transaction/overlapping=]
918+
can't be [=transaction/started=] at the same time if their [=transaction/scopes=] are [=transaction/overlapping=]
919919
since that would mean that they can modify each other's data in
920920
the middle of the transaction. This type of transaction can be
921921
created any time once a database has been opened.
@@ -1001,7 +1001,7 @@ Transactions are expected to be short lived. This is encouraged by the
10011001
described below.
10021002

10031003
<aside class=note>
1004-
Authors can still cause transactions to run for a long time;
1004+
Authors can still cause transactions to stay [=transaction/live|alive=] for a long time;
10051005
however, this usage pattern is not advised as it can lead to a poor
10061006
user experience.
10071007
</aside>
@@ -1088,6 +1088,8 @@ the case even if the transaction has not yet been
10881088
requests; however, the implementation must keep track of the
10891089
[=/requests=] and their order.
10901090

1091+
A [=/transaction=] is said to be <dfn>live</dfn> from when it is [=transaction/created=] until its [=transaction/state=] is set to [=transaction/finished=].
1092+
10911093
<div algorithm>
10921094

10931095
To <dfn id=cleanup-indexed-database-transactions export>cleanup Indexed Database transactions</dfn>, run the following steps.
@@ -1135,14 +1137,14 @@ The following constraints define when a [=/transaction=] can be [=transaction/st
11351137
* have [=transaction/overlapping scopes=] with |tx|; and
11361138
* are not [=transaction/finished=].
11371139

1138-
Implementations may impose additional constraints. For example, implementations are not required to run non-[=transaction/overlapping=] <a for=transaction>read/write transactions</a> in parallel, or may impose limits on the number of running transactions.
1140+
Implementations may impose additional constraints. For example, implementations are not required to [=transaction/start=] non-[=transaction/overlapping=] <a for=transaction>read/write transactions</a> in parallel, or may impose limits on the number of [=transaction/started=] transactions.
11391141

11401142
<aside class=note>
11411143

11421144
These constraints imply the following:
11431145

1144-
* Any number of [=transaction/read-only transactions=] are allowed to run concurrently, even if they have [=transaction/overlapping scopes=].
1145-
* As long as a [=transaction/read-only transaction=] is running, the data that the implementation returns through [=/requests=] created with that transaction remains constant. That is, two requests to read the same piece of data yield the same result both for the case when data is found and the result is that data, and for the case when data is not found and a lack of data is indicated.
1146+
* Any number of [=transaction/read-only transactions=] are allowed to be [=transaction/started=] concurrently, even if they have [=transaction/overlapping scopes=].
1147+
* As long as a [=transaction/read-only transaction=] is [=transaction/live=], the data that the implementation returns through [=/requests=] created with that transaction remains constant. That is, two requests to read the same piece of data yield the same result both for the case when data is found and the result is that data, and for the case when data is not found and a lack of data is indicated.
11461148
* A <a for=transaction>read/write transaction</a> is only affected by changes to [=/object stores=] that are made using the transaction itself. The implementation ensures that another transaction does not modify the contents of [=/object stores=] in the <a for=transaction>read/write transaction</a>'s [=transaction/scope=]. The implementation also ensures that if the <a for=transaction>read/write transaction</a> completes successfully, the changes written to [=/object stores=] using the transaction can be committed to the [=/database=] without merge conflicts.
11471149
* If multiple <a for=transaction>read/write transactions</a> are attempting to access the same object store (i.e. if they have [=transaction/overlapping scopes=]), the transaction that was [=transaction/created=] first is the transaction which gets access to the object store first, and it is the only transaction which has access to the object store until the transaction is [=transaction/finished=].
11481150
* Any transaction [=transaction/created=] after a <a for=transaction>read/write transaction</a> sees the changes written by the <a for=transaction>read/write transaction</a>. For example, if a <a for=transaction>read/write transaction</a> A, is created, and later another transaction B, is created, and the two transactions have [=transaction/overlapping scopes=], then transaction B sees any changes made to any [=/object stores=] that are part of that [=transaction/overlapping scope=]. This also means that transaction B does not have access to any [=/object stores=] in that overlapping [=transaction/scope=] until transaction A is [=transaction/finished=].
@@ -1159,7 +1161,7 @@ An <dfn>upgrade transaction</dfn> is a [=/transaction=] with [=transaction/mode=
11591161
"{{IDBTransactionMode/versionchange}}".
11601162

11611163
An [=/upgrade transaction=] is automatically created when running the
1162-
steps to [=run an upgrade transaction=] after a [=/connection=]
1164+
steps to [=upgrade a database=] after a [=/connection=]
11631165
is opened to a [=/database=], if a [=database/version=] greater than
11641166
the current [=database/version=] is specified. This [=/transaction=]
11651167
will be active inside the {{IDBOpenDBRequest/upgradeneeded!!event}} event
@@ -1171,21 +1173,23 @@ handler.
11711173

11721174
An [=/upgrade transaction=] is exclusive. The steps to [=open a
11731175
database=] ensure that only one [=/connection=] to the database is
1174-
open when an [=/upgrade transaction=] is running.
1176+
open when an [=/upgrade transaction=] is [=transaction/live=].
11751177
The {{IDBOpenDBRequest/upgradeneeded!!event}} event isn't fired, and thus the
11761178
[=/upgrade transaction=] isn't started, until all other
11771179
[=/connections=] to the same [=/database=] are closed. This ensures
1178-
that all previous transactions are [=transaction/finished=]. As long
1179-
as an [=/upgrade transaction=] is running, attempts to open more
1180+
that all previous transactions are [=transaction/finished=].
1181+
1182+
As long
1183+
as an [=/upgrade transaction=] is [=transaction/live=], attempts to open more
11801184
[=/connections=] to the same [=/database=] are delayed, and any
11811185
attempts to use the same [=/connection=] to start additional
11821186
transactions by calling {{IDBDatabase/transaction()}} will throw an
1183-
exception. Thus [=/upgrade transactions=] not only ensure that no
1184-
other transactions are running concurrently, but also ensure that no
1187+
exception. This ensures that no
1188+
other transactions are [=transaction/live=] concurrently, and also ensures that no
11851189
new transactions are queued against the same [=/database=] as long
1186-
as the transaction is running.
1190+
as the [=/upgrade transaction=] is [=transaction/live=].
11871191

1188-
This ensures that once an [=/upgrade transaction=] is complete, the
1192+
This further ensures that once an [=/upgrade transaction=] is complete, the
11891193
set of [=/object stores=] and [=/indexes=] in a [=/database=] remain
11901194
constant for the lifetime of all subsequent [=/connections=] and
11911195
[=/transactions=].
@@ -1996,7 +2000,7 @@ enum IDBRequestReadyState {
19962000
::
19972001
Returns the {{IDBTransaction}} the request was made within.
19982002
If this as an [=request/open request=], then it returns an
1999-
[=/upgrade transaction=] while it is running, or null otherwise.
2003+
[=/upgrade transaction=] while it is [=transaction/live=], or null otherwise.
20002004

20012005
: |request| . {{IDBRequest/readyState}}
20022006
::
@@ -2083,7 +2087,7 @@ dictionary IDBVersionChangeEventInit : EventInit {
20832087
The <dfn attribute for=IDBVersionChangeEvent>oldVersion</dfn> getter steps are to return the value it was initialized to. It represents the previous version of the database.
20842088

20852089

2086-
The <dfn attribute for=IDBVersionChangeEvent>newVersion</dfn> getter steps are to return the value it was initialized to. It represents the new version of the database, or null if the database is being deleted. See the steps to [=run an upgrade transaction=].
2090+
The <dfn attribute for=IDBVersionChangeEvent>newVersion</dfn> getter steps are to return the value it was initialized to. It represents the new version of the database, or null if the database is being deleted. See the steps to [=upgrade a database=].
20872091

20882092
Events are constructed as defined in [[DOM#constructing-events]].
20892093

@@ -2636,7 +2640,7 @@ instance on which it was called.
26362640

26372641
The <dfn method for=IDBDatabase>transaction(|storeNames|, |mode|, |options|)</dfn> method steps are:
26382642

2639-
1. If a running [=/upgrade transaction=] is associated with the [=/connection=],
2643+
1. If a [=transaction/live=] [=/upgrade transaction=] is associated with the [=/connection=],
26402644
[=exception/throw=] an "{{InvalidStateError}}" {{DOMException}}.
26412645

26422646
1. If [=/this=]'s [=connection/close pending flag=] is true, then [=exception/throw=] an
@@ -4996,7 +5000,7 @@ To <dfn>open a database</dfn> with |storageKey| which requested the [=/database=
49965000
[=/connections=] in |openConnections| are
49975001
[=connection/closed=].
49985002

4999-
1. Run [=run an upgrade transaction=]
5003+
1. Run [=upgrade a database=]
50005004
using |connection|, |version| and |request|.
50015005

50025006
1. If |connection| was [=connection/closed=],
@@ -5052,7 +5056,7 @@ optional |forced flag|, run these steps:
50525056

50535057
<aside class=note>
50545058
Once the [=/connection=] is closed, this can unblock the steps to
5055-
[=run an upgrade transaction=], and the steps to [=delete a
5059+
[=upgrade a database=], and the steps to [=delete a
50565060
database=], which [both](#delete-close-block)
50575061
[wait](#version-change-close-block) for [=/connections=] to
50585062
a given [=/database=] to be closed before continuing.
@@ -5297,14 +5301,12 @@ created [=/request=] belongs to is [=transaction/aborted=] using the steps to
52975301

52985302

52995303
<!-- ============================================================ -->
5300-
## Running an upgrade transaction ## {#upgrade-transaction-steps}
5304+
## Upgrading a database ## {#upgrade-transaction-steps}
53015305
<!-- ============================================================ -->
53025306

53035307
<div algorithm>
53045308

5305-
To <dfn>run an upgrade transaction</dfn> with |connection| (a [=/connection=])
5306-
which is used to update the [=/database=], a new |version| to be set
5307-
for the [=/database=], and a |request|, run these steps:
5309+
To <dfn>upgrade a database</dfn> with |connection| (a [=/connection=]), a new |version|, and a |request|, run these steps:
53085310

53095311
1. Let |db| be |connection|'s [=/database=].
53105312

@@ -6781,6 +6783,7 @@ For the revision history of the second edition, see [that document's Revision Hi
67816783
* Specified [[#transaction-scheduling]] more precisely and disallow starting read/write transactions while read-only transactions with overlapping scope are running. ([Issue #253](https://github.com/w3c/IndexedDB/issues/253))
67826784
* Added <a href="#accessibility">Accessibility considerations</a> section. ([Issue #327](https://github.com/w3c/IndexedDB/issues/327))
67836785
* Used [[infra]]'s list sorting definition. ([Issue #346](https://github.com/w3c/IndexedDB/issues/346))
6786+
* Added a definition for [=transaction/live=] transactions, and renamed "run an upgrade transaction" to [=/upgrade a database=], to disambiguate "running". ([Issue #408](https://github.com/w3c/IndexedDB/issues/408))
67846787

67856788
<!-- ============================================================ -->
67866789
# Acknowledgements # {#acknowledgements}
@@ -6822,6 +6825,7 @@ Danillo Paiva,
68226825
David Grogan,
68236826
Domenic Denicola,
68246827
Dominique Hazael-Massieux,
6828+
Evan Stade,
68256829
Glenn Maynard,
68266830
Hans Wennborg,
68276831
Isiah Meadows,

0 commit comments

Comments
 (0)