-
Notifications
You must be signed in to change notification settings - Fork 625
Release Overlay #3112
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
Release Overlay #3112
Changes from all commits
39771c3
016221d
93ba4a7
f9d4208
b7d6597
4c53217
c145203
9f8c61e
3aa0f7f
1649407
4e76e7a
a8e393c
dff4bbd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,12 +49,10 @@ class SQLiteSchema { | |
* The version of the schema. Increase this by one for each migration added to runMigrations | ||
* below. | ||
*/ | ||
static final int VERSION = 13; | ||
|
||
static final int OVERLAY_SUPPORT_VERSION = VERSION + 1; | ||
static final int VERSION = 14; | ||
|
||
// TODO(indexing): Remove this constant and increment VERSION to enable indexing support | ||
static final int INDEXING_SUPPORT_VERSION = OVERLAY_SUPPORT_VERSION + 1; | ||
static final int INDEXING_SUPPORT_VERSION = VERSION + 1; | ||
|
||
/** | ||
* The batch size for data migrations. | ||
|
@@ -75,14 +73,11 @@ class SQLiteSchema { | |
} | ||
|
||
void runSchemaUpgrades() { | ||
runSchemaUpgrades(0, VERSION); | ||
runSchemaUpgrades(0); | ||
} | ||
|
||
void runSchemaUpgrades(int fromVersion) { | ||
int toVersion = VERSION; | ||
if (Persistence.OVERLAY_SUPPORT_ENABLED) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should remove the flag in its entirety to just set it to true but leave all conditional checks. This makes sure that we can turn it to false again. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one here has to be deleted, because if the version is increased again, doing this will override it. |
||
toVersion = OVERLAY_SUPPORT_VERSION; | ||
} | ||
if (Persistence.INDEXING_SUPPORT_ENABLED) { | ||
toVersion = INDEXING_SUPPORT_VERSION; | ||
} | ||
|
@@ -178,8 +173,16 @@ void runSchemaUpgrades(int fromVersion, int toVersion) { | |
ensurePathLength(); | ||
} | ||
|
||
if (fromVersion < 14 && toVersion >= 14) { | ||
Preconditions.checkState( | ||
Persistence.OVERLAY_SUPPORT_ENABLED || Persistence.INDEXING_SUPPORT_ENABLED); | ||
createOverlays(); | ||
createDataMigrationTable(); | ||
addPendingDataMigration(Persistence.DATA_MIGRATION_BUILD_OVERLAYS); | ||
} | ||
|
||
/* | ||
* Adding a new migration? READ THIS FIRST! | ||
* Adding a new schema upgrade? READ THIS FIRST! | ||
* | ||
* Be aware that the SDK version may be downgraded then re-upgraded. This means that running | ||
* your new migration must not prevent older versions of the SDK from functioning. Additionally, | ||
|
@@ -190,13 +193,6 @@ void runSchemaUpgrades(int fromVersion, int toVersion) { | |
* maintained invariants from later versions, so migrations that update values cannot assume | ||
* that existing values have been properly maintained. Calculate them again, if applicable. | ||
*/ | ||
if (fromVersion < OVERLAY_SUPPORT_VERSION && toVersion >= OVERLAY_SUPPORT_VERSION) { | ||
Preconditions.checkState( | ||
Persistence.OVERLAY_SUPPORT_ENABLED || Persistence.INDEXING_SUPPORT_ENABLED); | ||
createOverlays(); | ||
createDataMigrationTable(); | ||
addPendingDataMigration(Persistence.DATA_MIGRATION_BUILD_OVERLAYS); | ||
} | ||
|
||
if (fromVersion < INDEXING_SUPPORT_VERSION && toVersion >= INDEXING_SUPPORT_VERSION) { | ||
Preconditions.checkState(Persistence.INDEXING_SUPPORT_ENABLED); | ||
|
@@ -708,7 +704,9 @@ private void createDataMigrationTable() { | |
} | ||
|
||
private void addPendingDataMigration(String migration) { | ||
db.execSQL("INSERT INTO data_migrations (migration_name) VALUES (?)", new String[] {migration}); | ||
db.execSQL( | ||
"INSERT OR IGNORE INTO data_migrations (migration_name) VALUES (?)", | ||
new String[] {migration}); | ||
} | ||
|
||
private boolean tableExists(String table) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,6 @@ | |
import static com.google.firebase.firestore.testutil.TestUtil.viewChanges; | ||
import static java.util.Arrays.asList; | ||
import static java.util.Collections.emptyList; | ||
import static java.util.Collections.singletonList; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertNotNull; | ||
|
@@ -75,16 +74,17 @@ | |
import com.google.firebase.firestore.testutil.TestUtil; | ||
import com.google.firebase.firestore.util.AsyncQueue; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map.Entry; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import javax.annotation.Nullable; | ||
import org.junit.After; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
|
||
/** | ||
|
@@ -155,23 +155,27 @@ private void udpateViews(int targetId, boolean fromCache) { | |
notifyLocalViewChanges(viewChanges(targetId, fromCache, asList(), asList())); | ||
} | ||
|
||
private void acknowledgeMutation(long documentVersion, @Nullable Object transformResult) { | ||
private void acknowledgeMutationWithTransformResults( | ||
long documentVersion, Object... transformResult) { | ||
MutationBatch batch = batches.remove(0); | ||
SnapshotVersion version = version(documentVersion); | ||
MutationResult mutationResult = | ||
new MutationResult( | ||
version, | ||
transformResult != null | ||
? Collections.singletonList(TestUtil.wrap(transformResult)) | ||
: Collections.emptyList()); | ||
List<MutationResult> mutationResults = | ||
Collections.singletonList(new MutationResult(version, emptyList())); | ||
|
||
if (transformResult.length != 0) { | ||
mutationResults = | ||
Arrays.stream(transformResult) | ||
.map(r -> new MutationResult(version, Collections.singletonList(TestUtil.wrap(r)))) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
MutationBatchResult result = | ||
MutationBatchResult.create( | ||
batch, version, singletonList(mutationResult), WriteStream.EMPTY_STREAM_TOKEN); | ||
MutationBatchResult.create(batch, version, mutationResults, WriteStream.EMPTY_STREAM_TOKEN); | ||
lastChanges = localStore.acknowledgeBatch(result); | ||
} | ||
|
||
private void acknowledgeMutation(long documentVersion) { | ||
acknowledgeMutation(documentVersion, null); | ||
acknowledgeMutationWithTransformResults(documentVersion); | ||
} | ||
|
||
private void rejectMutation() { | ||
|
@@ -974,7 +978,10 @@ public void testReadsAllDocumentsForInitialCollectionQueries() { | |
localStore.executeQuery(query, /* usePreviousResults= */ true); | ||
|
||
assertRemoteDocumentsRead(/* byKey= */ 0, /* byQuery= */ 2); | ||
if (!Persistence.OVERLAY_SUPPORT_ENABLED) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a blocker, but we should ideally remove all statements like this (including the flag) or leave them all here. If we leave the flag, we should be able to turn it off during development and have the tests pass. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
if (Persistence.OVERLAY_SUPPORT_ENABLED) { | ||
// No mutations are read because only overlay is needed. | ||
assertMutationsRead(/* byKey= */ 0, /* byQuery= */ 0); | ||
} else { | ||
assertMutationsRead(/* byKey= */ 0, /* byQuery= */ 1); | ||
} | ||
} | ||
|
@@ -1070,7 +1077,7 @@ public void testHandlesSetMutationThenAckThenTransformThenAckThenTransform() { | |
assertContains(doc("foo/bar", 1, map("sum", 1)).setHasLocalMutations()); | ||
assertChanged(doc("foo/bar", 1, map("sum", 1)).setHasLocalMutations()); | ||
|
||
acknowledgeMutation(2, 1); | ||
acknowledgeMutationWithTransformResults(2, 1); | ||
assertChanged(doc("foo/bar", 2, map("sum", 1)).setHasCommittedMutations()); | ||
assertContains(doc("foo/bar", 2, map("sum", 1)).setHasCommittedMutations()); | ||
|
||
|
@@ -1284,19 +1291,17 @@ public void testHandlesSetMutationThenTransformThenRemoteEventThenTransform() { | |
assertChanged(doc("foo/bar", 2, map("sum", 3)).setHasLocalMutations()); | ||
assertContains(doc("foo/bar", 2, map("sum", 3)).setHasLocalMutations()); | ||
|
||
acknowledgeMutation(3, 1); | ||
acknowledgeMutationWithTransformResults(3, 1); | ||
assertChanged(doc("foo/bar", 3, map("sum", 3)).setHasLocalMutations()); | ||
assertContains(doc("foo/bar", 3, map("sum", 3)).setHasLocalMutations()); | ||
|
||
acknowledgeMutation(4, 1339); | ||
acknowledgeMutationWithTransformResults(4, 1339); | ||
assertChanged(doc("foo/bar", 4, map("sum", 1339)).setHasCommittedMutations()); | ||
assertContains(doc("foo/bar", 4, map("sum", 1339)).setHasCommittedMutations()); | ||
} | ||
|
||
@Test | ||
@Ignore("Test fails in CI") | ||
// TODO(Overlay): Fix me :) | ||
public void testHoldsBackOnlyNonIdempotentTransforms() { | ||
public void testHoldsBackTransforms() { | ||
Query query = Query.atPath(ResourcePath.fromString("foo")); | ||
allocateQuery(query); | ||
assertTargetId(2); | ||
|
@@ -1333,8 +1338,13 @@ public void testHoldsBackOnlyNonIdempotentTransforms() { | |
asList(2), | ||
emptyList())); | ||
assertChanged( | ||
doc("foo/bar", 2, map("sum", 1, "array_union", asList("bar", "foo"))) | ||
.setHasLocalMutations()); | ||
doc("foo/bar", 2, map("sum", 1, "array_union", asList("foo"))).setHasLocalMutations()); | ||
|
||
acknowledgeMutationWithTransformResults(3, 1338, asList("bar", "foo")); | ||
assertChanged( | ||
doc("foo/bar", 3, map("sum", 1338, "array_union", asList("bar", "foo"))) | ||
.withReadTime(new SnapshotVersion(new Timestamp(0, 3000))) | ||
.setHasCommittedMutations()); | ||
} | ||
|
||
@Test | ||
|
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.