Skip to content

Commit d300520

Browse files
Merging Master into Multi-Tab (#1038)
1 parent 56b15ff commit d300520

File tree

4 files changed

+107
-181
lines changed

4 files changed

+107
-181
lines changed

packages/firestore/src/core/sync_engine.ts

+1-11
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import { assert, fail } from '../util/assert';
3636
import { FirestoreError } from '../util/error';
3737
import * as log from '../util/log';
3838
import { AnyJs, primitiveComparator } from '../util/misc';
39-
import * as objUtils from '../util/obj';
4039
import { ObjectMap } from '../util/obj_map';
4140
import { Deferred } from '../util/promise';
4241
import { SortedMap } from '../util/sorted_map';
@@ -194,13 +193,7 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
194193
this.syncEngineListener === null,
195194
'SyncEngine already has a subscriber.'
196195
);
197-
<<<<<<< HEAD
198196
this.syncEngineListener = syncEngineListener;
199-
this.limboCollector.addGarbageSource(this.limboDocumentRefs);
200-
=======
201-
this.viewHandler = viewHandler;
202-
this.errorHandler = errorHandler;
203-
>>>>>>> master
204197
}
205198

206199
/**
@@ -501,16 +494,13 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
501494

502495
async rejectListen(targetId: TargetId, err: FirestoreError): Promise<void> {
503496
this.assertSubscribed('rejectListens()');
504-
<<<<<<< HEAD
505497

506498
// PORTING NOTE: Multi-tab only.
507499
this.sharedClientState.trackQueryUpdate(targetId, 'rejected', err);
508500

509-
const limboKey = this.limboKeysByTarget[targetId];
510-
=======
511501
const limboResolution = this.limboResolutionsByTarget[targetId];
512502
const limboKey = limboResolution && limboResolution.key;
513-
>>>>>>> master
503+
514504
if (limboKey) {
515505
// Since this query failed, we won't want to manually unlisten to it.
516506
// So go ahead and remove it from bookkeeping.

packages/firestore/src/local/indexeddb_schema.ts

+27-41
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,21 @@ import { SnapshotVersion } from '../core/snapshot_version';
2929
* Schema Version for the Web client:
3030
* 1. Initial version including Mutation Queue, Query Cache, and Remote Document
3131
* Cache
32-
<<<<<<< HEAD
33-
* 2. Added targetCount to targetGlobal row.
34-
* 3. Multi-Tab Support.
35-
=======
3632
* 2. Used to ensure a targetGlobal object exists and add targetCount to it. No
3733
* longer required because migration 3 unconditionally clears it.
3834
* 3. Dropped and re-created Query Cache to deal with cache corruption related
3935
* to limbo resolution. Addresses
4036
* https://github.com/firebase/firebase-ios-sdk/issues/1548
41-
>>>>>>> master
37+
* 4. Multi-Tab Support.
4238
*/
43-
export const SCHEMA_VERSION = 3;
39+
export const SCHEMA_VERSION = 4;
4440

4541
/**
4642
* Performs database creation and schema upgrades.
4743
*
4844
* Note that in production, this method is only ever used to upgrade the schema
49-
* to SCHEMA_VERSION. Different versions are only used for testing and
50-
* local feature development.
45+
* to SCHEMA_VERSION. Different values of toVersion are only used for testing
46+
* and local feature development.
5147
*/
5248
export function createOrUpgradeDb(
5349
db: IDBDatabase,
@@ -56,14 +52,9 @@ export function createOrUpgradeDb(
5652
toVersion: number
5753
): PersistencePromise<void> {
5854
assert(
59-
<<<<<<< HEAD
60-
fromVersion < toVersion && fromVersion >= 0 && toVersion <= 3,
61-
=======
6255
fromVersion < toVersion && fromVersion >= 0 && toVersion <= SCHEMA_VERSION,
63-
>>>>>>> master
6456
'Unexpected schema upgrade from v${fromVersion} to v{toVersion}.'
6557
);
66-
let p = PersistencePromise.resolve();
6758

6859
if (fromVersion < 1 && toVersion >= 1) {
6960
createOwnerStore(db);
@@ -72,29 +63,6 @@ export function createOrUpgradeDb(
7263
createRemoteDocumentCache(db);
7364
}
7465

75-
<<<<<<< HEAD
76-
if (fromVersion < 2 && toVersion >= 2) {
77-
p = p
78-
.next(() => ensureTargetGlobalExists(txn))
79-
.next(targetGlobal => saveTargetCount(txn, targetGlobal));
80-
}
81-
82-
if (fromVersion > 0 && fromVersion < 3 && toVersion >= 3) {
83-
// Schema version 3 uses auto-generated keys to generate globally unique
84-
// mutation batch IDs (this was previously ensured internally by the
85-
// client). To migrate to the new schema, we have to read all mutations
86-
// and write them back out. We preserve the existing batch IDs to guarantee
87-
// consistency with other object stores. Any further mutation batch IDs will
88-
// be auto-generated.
89-
p = p.next(() => upgradeMutationBatchSchemaAndMigrateData(db, txn));
90-
}
91-
92-
if (fromVersion < 3 && toVersion >= 3) {
93-
p = p.next(() => {
94-
createClientMetadataStore(db);
95-
createRemoteDocumentChangesStore(db);
96-
});
97-
=======
9866
// Migration 2 to populate the targetGlobal object no longer needed since
9967
// migration 3 unconditionally clears it.
10068

@@ -107,7 +75,23 @@ export function createOrUpgradeDb(
10775
createQueryCache(db);
10876
}
10977
p = p.next(() => writeEmptyTargetGlobalEntry(txn));
110-
>>>>>>> master
78+
}
79+
80+
if (fromVersion < 4 && toVersion >= 4) {
81+
if (fromVersion !== 0) {
82+
// Schema version 3 uses auto-generated keys to generate globally unique
83+
// mutation batch IDs (this was previously ensured internally by the
84+
// client). To migrate to the new schema, we have to read all mutations
85+
// and write them back out. We preserve the existing batch IDs to guarantee
86+
// consistency with other object stores. Any further mutation batch IDs will
87+
// be auto-generated.
88+
p = p.next(() => upgradeMutationBatchSchemaAndMigrateData(db, txn));
89+
}
90+
91+
p = p.next(() => {
92+
createClientMetadataStore(db);
93+
createRemoteDocumentChangesStore(db);
94+
});
11195
}
11296

11397
return p;
@@ -711,12 +695,14 @@ export const V1_STORES = [
711695
DbTargetDocument.store
712696
];
713697

698+
// V2 is no longer usable (see comment at top of file)
699+
714700
// Visible for testing
715-
export const V2_STORES = V1_STORES;
701+
export const V3_STORES = V1_STORES;
716702

717703
// Visible for testing
718-
export const V3_STORES = [
719-
...V2_STORES,
704+
export const V4_STORES = [
705+
...V3_STORES,
720706
DbClientMetadata.store,
721707
DbRemoteDocumentChanges.store
722708
];
@@ -726,4 +712,4 @@ export const V3_STORES = [
726712
* used when creating transactions so that access across all stores is done
727713
* atomically.
728714
*/
729-
export const ALL_STORES = V3_STORES;
715+
export const ALL_STORES = V4_STORES;

packages/firestore/test/unit/local/indexeddb_schema.test.ts

+11-59
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,17 @@ import {
2222
createOrUpgradeDb,
2323
DbMutationBatch,
2424
DbMutationBatchKey,
25-
<<<<<<< HEAD
2625
DbOwner,
2726
DbOwnerKey,
2827
DbTarget,
2928
DbTargetGlobal,
3029
DbTargetGlobalKey,
30+
DbTargetKey,
31+
DbTimestamp,
3132
SCHEMA_VERSION,
3233
V1_STORES,
33-
V2_STORES,
34-
V3_STORES
34+
V3_STORES,
35+
V4_STORES
3536
} from '../../../src/local/indexeddb_schema';
3637
import { SimpleDb, SimpleDbTransaction } from '../../../src/local/simple_db';
3738
import { PersistencePromise } from '../../../src/local/persistence_promise';
@@ -41,16 +42,7 @@ import { JsonProtoSerializer } from '../../../src/remote/serializer';
4142
import { PlatformSupport } from '../../../src/platform/platform';
4243
import { AsyncQueue } from '../../../src/util/async_queue';
4344
import { SharedFakeWebStorage, TestPlatform } from '../../util/test_platform';
44-
=======
45-
DbTarget,
46-
DbTargetGlobal,
47-
DbTargetGlobalKey,
48-
DbTargetKey,
49-
DbTimestamp
50-
} from '../../../src/local/indexeddb_schema';
51-
import { SimpleDb, SimpleDbTransaction } from '../../../src/local/simple_db';
5245
import { SnapshotVersion } from '../../../src/core/snapshot_version';
53-
>>>>>>> master
5446

5547
const INDEXEDDB_TEST_DATABASE_PREFIX = 'schemaTest/';
5648
const INDEXEDDB_TEST_DATABASE =
@@ -144,31 +136,6 @@ describe('IndexedDbSchema: createOrUpgradeDb', () => {
144136
});
145137
});
146138

147-
<<<<<<< HEAD
148-
it('can install schema version 2', () => {
149-
return withDb(2, db => {
150-
expect(db.version).to.equal(2);
151-
// We should have all of the stores, we should have the target global row
152-
// and we should not have any targets counted, because there are none.
153-
expect(getAllObjectStores(db)).to.have.members(V2_STORES);
154-
// Check the target count. We haven't added any targets, so we expect 0.
155-
return getTargetCount(db).then(targetCount => {
156-
expect(targetCount).to.equal(0);
157-
});
158-
});
159-
});
160-
161-
it('can install schema version 3', () => {
162-
return withDb(3, async db => {
163-
expect(db.version).to.be.equal(3);
164-
expect(getAllObjectStores(db)).to.have.members(V3_STORES);
165-
});
166-
});
167-
168-
it('can upgrade from schema version 1 to 2', () => {
169-
const expectedTargetCount = 5;
170-
return withDb(1, db => {
171-
=======
172139
it('drops the query cache from 2 to 3', () => {
173140
const userId = 'user';
174141
const batchId = 1;
@@ -189,7 +156,6 @@ describe('IndexedDbSchema: createOrUpgradeDb', () => {
189156
);
190157

191158
return withDb(2, db => {
192-
>>>>>>> master
193159
const sdb = new SimpleDb(db);
194160
return sdb.runTransaction(
195161
'readwrite',
@@ -213,24 +179,11 @@ describe('IndexedDbSchema: createOrUpgradeDb', () => {
213179
.next(() => mutations.put(expectedMutation))
214180
);
215181
}
216-
<<<<<<< HEAD
217-
return p;
218-
});
219-
}).then(() =>
220-
withDb(2, db => {
221-
expect(db.version).to.equal(2);
222-
expect(getAllObjectStores(db)).to.have.members(V2_STORES);
223-
return getTargetCount(db).then(targetCount => {
224-
expect(targetCount).to.equal(expectedTargetCount);
225-
});
226-
})
227-
);
228-
=======
229182
);
230183
}).then(() => {
231184
return withDb(3, db => {
232185
expect(db.version).to.equal(3);
233-
expect(getAllObjectStores(db)).to.have.members(ALL_STORES);
186+
expect(getAllObjectStores(db)).to.have.members(V3_STORES);
234187

235188
const sdb = new SimpleDb(db);
236189
return sdb.runTransaction(
@@ -259,7 +212,7 @@ describe('IndexedDbSchema: createOrUpgradeDb', () => {
259212
const expected = JSON.parse(JSON.stringify(resetTargetGlobal));
260213
expect(targetGlobalEntry).to.deep.equal(expected);
261214
})
262-
.next(() => mutations.get([userId, batchId]))
215+
.next(() => mutations.get(batchId))
263216
.next(mutation => {
264217
// Mutations should be unaffected.
265218
expect(mutation.userId).to.equal(userId);
@@ -269,10 +222,9 @@ describe('IndexedDbSchema: createOrUpgradeDb', () => {
269222
);
270223
});
271224
});
272-
>>>>>>> master
273225
});
274226

275-
it('can upgrade from schema version 2 to 3', () => {
227+
it('can upgrade from schema version 3 to 4', () => {
276228
const testWrite = { delete: 'foo' };
277229
const testMutations = [
278230
{
@@ -295,7 +247,7 @@ describe('IndexedDbSchema: createOrUpgradeDb', () => {
295247
}
296248
];
297249

298-
return withDb(2, db => {
250+
return withDb(3, db => {
299251
const sdb = new SimpleDb(db);
300252
return sdb.runTransaction('readwrite', [DbMutationBatch.store], txn => {
301253
const store = txn.store(DbMutationBatch.store);
@@ -306,9 +258,9 @@ describe('IndexedDbSchema: createOrUpgradeDb', () => {
306258
return p;
307259
});
308260
}).then(() =>
309-
withDb(3, db => {
310-
expect(db.version).to.be.equal(3);
311-
expect(getAllObjectStores(db)).to.have.members(V3_STORES);
261+
withDb(4, db => {
262+
expect(db.version).to.be.equal(4);
263+
expect(getAllObjectStores(db)).to.have.members(V4_STORES);
312264

313265
const sdb = new SimpleDb(db);
314266
return sdb.runTransaction('readwrite', [DbMutationBatch.store], txn => {

0 commit comments

Comments
 (0)