Skip to content

Remove non-idempotent transactions #2771

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 7 additions & 19 deletions packages/firestore/src/local/indexeddb_persistence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ export class IndexedDbPersistence implements Persistence {
this.scheduleClientMetadataAndPrimaryLeaseRefreshes();

return this.simpleDb.runTransaction(
'readonly-idempotent',
'readonly',
[DbTargetGlobal.store],
txn => getHighestListenSequenceNumber(txn)
);
Expand Down Expand Up @@ -388,7 +388,7 @@ export class IndexedDbPersistence implements Persistence {
*/
private updateClientMetadataAndTryBecomePrimary(): Promise<void> {
return this.simpleDb
.runTransaction('readwrite-idempotent', ALL_STORES, txn => {
.runTransaction('readwrite', ALL_STORES, txn => {
const metadataStore = clientMetadataStore(txn);
return metadataStore
.put(
Expand Down Expand Up @@ -474,7 +474,7 @@ export class IndexedDbPersistence implements Persistence {

const inactiveClients = await this.runTransaction(
'maybeGarbageCollectMultiClientState',
'readwrite-primary-idempotent',
'readwrite-primary',
txn => {
const metadataStore = IndexedDbPersistence.getStore<
DbClientMetadataKey,
Expand Down Expand Up @@ -658,7 +658,7 @@ export class IndexedDbPersistence implements Persistence {
this.detachVisibilityHandler();
this.detachWindowUnloadHook();
await this.simpleDb.runTransaction(
'readwrite-idempotent',
'readwrite',
[DbPrimaryClient.store, DbClientMetadata.store],
txn => {
return this.releasePrimaryLeaseIfHeld(txn).next(() =>
Expand Down Expand Up @@ -690,7 +690,7 @@ export class IndexedDbPersistence implements Persistence {

getActiveClients(): Promise<ClientId[]> {
return this.simpleDb.runTransaction(
'readonly-idempotent',
'readonly',
[DbClientMetadata.store],
txn => {
return clientMetadataStore(txn)
Expand Down Expand Up @@ -762,16 +762,7 @@ export class IndexedDbPersistence implements Persistence {
): Promise<T> {
log.debug(LOG_TAG, 'Starting transaction:', action);

// TODO(schmidt-sebastian): Simplify once all transactions are idempotent.
const idempotent = mode.endsWith('idempotent');
const readonly = mode.startsWith('readonly');
const simpleDbMode = readonly
? idempotent
? 'readonly-idempotent'
: 'readonly'
: idempotent
? 'readwrite-idempotent'
: 'readwrite';
const simpleDbMode = mode === 'readonly' ? 'readonly' : 'readwrite';

let persistenceTransaction: PersistenceTransaction;

Expand All @@ -784,10 +775,7 @@ export class IndexedDbPersistence implements Persistence {
this.listenSequence.next()
);

if (
mode === 'readwrite-primary' ||
mode === 'readwrite-primary-idempotent'
) {
if (mode === 'readwrite-primary') {
// While we merely verify that we have (or can acquire) the lease
// immediately, we wait to extend the primary lease until after
// executing transactionOperation(). This ensures that even if the
Expand Down
Loading