Skip to content

Commit f25efea

Browse files
Remove Indexing flag (#3226)
1 parent 9a66b0e commit f25efea

23 files changed

+318
-400
lines changed

firebase-firestore/firebase-firestore.gradle

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,6 @@ android.libraryVariants.all { variant ->
105105
file("local.properties").withInputStream { localProps.load(it) }
106106
} catch (FileNotFoundException e) {
107107
}
108-
109-
// TODO(Indexing): Delete below once indexing is shipped.
110-
if (localProps['firestoreEnableIndexing']) {
111-
variant.buildConfigField("boolean", "ENABLE_INDEXING", "true")
112-
} else {
113-
variant.buildConfigField("boolean", "ENABLE_INDEXING", "false")
114-
}
115108
}
116109

117110
configurations.all {

firebase-firestore/src/androidTest/java/com/google/firebase/firestore/IndexingTest.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,15 @@
1919
import androidx.test.ext.junit.runners.AndroidJUnit4;
2020
import com.google.android.gms.tasks.Task;
2121
import com.google.android.gms.tasks.Tasks;
22-
import com.google.firebase.firestore.local.Persistence;
2322
import com.google.firebase.firestore.testutil.Assert;
2423
import com.google.firebase.firestore.testutil.IntegrationTestUtil;
2524
import java.util.concurrent.ExecutionException;
2625
import org.junit.After;
27-
import org.junit.BeforeClass;
2826
import org.junit.Test;
2927
import org.junit.runner.RunWith;
3028

3129
@RunWith(AndroidJUnit4.class)
3230
public class IndexingTest {
33-
/** Current state of indexing support. Used for restoring after test run. */
34-
private static final boolean supportsIndexing = Persistence.INDEXING_SUPPORT_ENABLED;
35-
36-
@BeforeClass
37-
public static void beforeClass() {
38-
Persistence.INDEXING_SUPPORT_ENABLED = true;
39-
}
40-
41-
@BeforeClass
42-
public static void afterClass() {
43-
Persistence.INDEXING_SUPPORT_ENABLED = supportsIndexing;
44-
}
4531

4632
@After
4733
public void tearDown() {
@@ -115,6 +101,4 @@ public void testBadIndexDoesNotCrashClient() {
115101
+ " \"fieldOverrides\": []\n"
116102
+ "}"));
117103
}
118-
119-
// TODO(indexing): Add tests that validate that indices are active
120104
}

firebase-firestore/src/androidTest/java/com/google/firebase/firestore/testutil/IntegrationTestUtil.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import com.google.firebase.firestore.QuerySnapshot;
3939
import com.google.firebase.firestore.auth.User;
4040
import com.google.firebase.firestore.core.DatabaseInfo;
41-
import com.google.firebase.firestore.local.Persistence;
4241
import com.google.firebase.firestore.model.DatabaseId;
4342
import com.google.firebase.firestore.testutil.provider.FirestoreProvider;
4443
import com.google.firebase.firestore.util.AsyncQueue;
@@ -255,8 +254,6 @@ public static FirebaseFirestore testFirestore(
255254
// This unfortunately is a global setting that affects existing Firestore clients.
256255
Logger.setLogLevel(logLevel);
257256

258-
Persistence.INDEXING_SUPPORT_ENABLED = true;
259-
260257
Context context = ApplicationProvider.getApplicationContext();
261258
DatabaseId databaseId = DatabaseId.forDatabase(projectId, DatabaseId.DEFAULT_DATABASE_ID);
262259

firebase-firestore/src/main/java/com/google/firebase/firestore/FirebaseFirestore.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import com.google.firebase.firestore.util.Function;
5353
import com.google.firebase.firestore.util.Logger;
5454
import com.google.firebase.firestore.util.Logger.Level;
55+
import com.google.firebase.firestore.util.Preconditions;
5556
import com.google.firebase.inject.Deferred;
5657
import java.io.ByteArrayInputStream;
5758
import java.io.InputStream;
@@ -306,13 +307,8 @@ public FirebaseApp getApp() {
306307
@VisibleForTesting
307308
Task<Void> setIndexConfiguration(String json) {
308309
ensureClientConfigured();
309-
310-
if (!settings.isPersistenceEnabled()) {
311-
throw new IllegalStateException("Cannot enable indexes when persistence is disabled");
312-
}
313-
314-
// Preconditions.checkState(BuildConfig.ENABLE_INDEXING, "Indexing support is not yet
315-
// available.");
310+
Preconditions.checkState(
311+
settings.isPersistenceEnabled(), "Cannot enable indexes when persistence is disabled");
316312

317313
List<FieldIndex> parsedIndexes = new ArrayList<>();
318314

firebase-firestore/src/main/java/com/google/firebase/firestore/core/ComponentProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public abstract class ComponentProvider {
4040
private RemoteStore remoteStore;
4141
private EventManager eventManager;
4242
private ConnectivityMonitor connectivityMonitor;
43-
private IndexBackfiller indexBackfiller;
43+
@Nullable private IndexBackfiller indexBackfiller;
4444
@Nullable private Scheduler garbageCollectionScheduler;
4545

4646
/** Configuration options for the component provider. */
@@ -109,6 +109,7 @@ public Scheduler getGarbageCollectionScheduler() {
109109
return garbageCollectionScheduler;
110110
}
111111

112+
@Nullable
112113
public IndexBackfiller getIndexBackfiller() {
113114
return indexBackfiller;
114115
}

firebase-firestore/src/main/java/com/google/firebase/firestore/core/FirestoreClient.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ public final class FirestoreClient {
7474
private RemoteStore remoteStore;
7575
private SyncEngine syncEngine;
7676
private EventManager eventManager;
77-
private IndexBackfiller indexBackfiller;
7877

7978
// LRU-related
79+
@Nullable private Scheduler indexBackfillScheduler;
8080
@Nullable private Scheduler gcScheduler;
8181

8282
public FirestoreClient(
@@ -160,9 +160,8 @@ public Task<Void> terminate() {
160160
if (gcScheduler != null) {
161161
gcScheduler.stop();
162162
}
163-
164-
if (Persistence.INDEXING_SUPPORT_ENABLED) {
165-
indexBackfiller.getScheduler().stop();
163+
if (indexBackfillScheduler != null) {
164+
indexBackfillScheduler.stop();
166165
}
167166
});
168167
}
@@ -282,14 +281,15 @@ private void initialize(Context context, User user, FirebaseFirestoreSettings se
282281
remoteStore = provider.getRemoteStore();
283282
syncEngine = provider.getSyncEngine();
284283
eventManager = provider.getEventManager();
285-
indexBackfiller = provider.getIndexBackfiller();
284+
IndexBackfiller indexBackfiller = provider.getIndexBackfiller();
286285

287286
if (gcScheduler != null) {
288287
gcScheduler.start();
289288
}
290289

291-
if (Persistence.INDEXING_SUPPORT_ENABLED && settings.isPersistenceEnabled()) {
292-
indexBackfiller.getScheduler().start();
290+
if (indexBackfiller != null) {
291+
indexBackfillScheduler = indexBackfiller.getScheduler();
292+
indexBackfillScheduler.start();
293293
}
294294
}
295295

firebase-firestore/src/main/java/com/google/firebase/firestore/core/MemoryComponentProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ protected Scheduler createGarbageCollectionScheduler(Configuration configuration
4242
}
4343

4444
@Override
45+
@Nullable
4546
protected IndexBackfiller createIndexBackfiller(Configuration configuration) {
46-
return new IndexBackfiller(getPersistence(), configuration.getAsyncQueue());
47+
return null;
4748
}
4849

4950
@Override

firebase-firestore/src/main/java/com/google/firebase/firestore/core/SQLiteComponentProvider.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
package com.google.firebase.firestore.core;
1616

17+
import com.google.firebase.firestore.local.IndexBackfiller;
1718
import com.google.firebase.firestore.local.LocalSerializer;
1819
import com.google.firebase.firestore.local.LruDelegate;
1920
import com.google.firebase.firestore.local.LruGarbageCollector;
@@ -32,6 +33,11 @@ protected Scheduler createGarbageCollectionScheduler(Configuration configuration
3233
return gc.newScheduler(configuration.getAsyncQueue(), getLocalStore());
3334
}
3435

36+
@Override
37+
protected IndexBackfiller createIndexBackfiller(Configuration configuration) {
38+
return new IndexBackfiller(getPersistence(), configuration.getAsyncQueue());
39+
}
40+
3541
@Override
3642
protected Persistence createPersistence(Configuration configuration) {
3743
LocalSerializer serializer =

firebase-firestore/src/main/java/com/google/firebase/firestore/index/OrderedCodeWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import java.util.Arrays;
2323

2424
/**
25-
* OrderedCodeWriter is a minimal-allocation implmentation of the writing behavior defined by the
25+
* OrderedCodeWriter is a minimal-allocation implementation of the writing behavior defined by the
2626
* backend.
2727
*/
2828
public class OrderedCodeWriter {

firebase-firestore/src/main/java/com/google/firebase/firestore/local/IndexBackfiller.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,11 @@ public Scheduler(AsyncQueue asyncQueue) {
7272

7373
@Override
7474
public void start() {
75-
hardAssert(Persistence.INDEXING_SUPPORT_ENABLED, "Indexing support not enabled");
7675
scheduleBackfill();
7776
}
7877

7978
@Override
8079
public void stop() {
81-
hardAssert(Persistence.INDEXING_SUPPORT_ENABLED, "Indexing support not enabled");
8280
if (backfillTask != null) {
8381
backfillTask.cancel();
8482
}

firebase-firestore/src/main/java/com/google/firebase/firestore/local/LocalStore.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public final class LocalStore implements BundleCallback {
115115
private IndexManager indexManager;
116116

117117
/** Manages field index backfill. */
118-
private final IndexBackfiller indexBackfiller;
118+
private final @Nullable IndexBackfiller indexBackfiller;
119119

120120
/** The set of all mutations that have been sent but not yet been applied to the backend. */
121121
private MutationQueue mutationQueue;
@@ -152,7 +152,7 @@ public final class LocalStore implements BundleCallback {
152152

153153
public LocalStore(
154154
Persistence persistence,
155-
IndexBackfiller indexBackfiller,
155+
@Nullable IndexBackfiller indexBackfiller,
156156
QueryEngine queryEngine,
157157
User initialUser) {
158158
hardAssert(
@@ -168,15 +168,18 @@ public LocalStore(
168168
localDocuments =
169169
new LocalDocumentsView(remoteDocuments, mutationQueue, documentOverlayCache, indexManager);
170170
this.queryEngine = queryEngine;
171-
this.indexBackfiller = indexBackfiller;
172171
queryEngine.initialize(localDocuments, indexManager);
173172

174173
localViewReferences = new ReferenceSet();
175174
persistence.getReferenceDelegate().setInMemoryPins(localViewReferences);
176175

177176
remoteDocuments.setIndexManager(indexManager);
178-
indexBackfiller.setIndexManager(indexManager);
179-
indexBackfiller.setLocalDocumentsView(localDocuments);
177+
178+
this.indexBackfiller = indexBackfiller;
179+
if (indexBackfiller != null) {
180+
indexBackfiller.setIndexManager(indexManager);
181+
indexBackfiller.setLocalDocumentsView(localDocuments);
182+
}
180183

181184
queryDataByTarget = new SparseArray<>();
182185
targetIdByTarget = new HashMap<>();
@@ -218,8 +221,10 @@ public ImmutableSortedMap<DocumentKey, Document> handleUserChange(User user) {
218221

219222
// TODO(indexing): Add spec tests that test these components change after a user change
220223
remoteDocuments.setIndexManager(indexManager);
221-
indexBackfiller.setIndexManager(indexManager);
222-
indexBackfiller.setLocalDocumentsView(localDocuments);
224+
if (indexBackfiller != null) {
225+
indexBackfiller.setIndexManager(indexManager);
226+
indexBackfiller.setLocalDocumentsView(localDocuments);
227+
}
223228

224229
// Union the old/new changed keys.
225230
ImmutableSortedSet<DocumentKey> changedKeys = DocumentKey.emptyKeySet();

firebase-firestore/src/main/java/com/google/firebase/firestore/local/Persistence.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
package com.google.firebase.firestore.local;
1616

17-
import com.google.firebase.firestore.BuildConfig;
1817
import com.google.firebase.firestore.auth.User;
1918
import com.google.firebase.firestore.util.Supplier;
2019

@@ -53,10 +52,6 @@ public abstract class Persistence {
5352
/** Constant string to indicate a data migration is required to support overlays. */
5453
public static String DATA_MIGRATION_BUILD_OVERLAYS = "BUILD_OVERLAYS";
5554

56-
/** Temporary setting for enabling indexing-specific code paths while in development. */
57-
// TODO(Indexing): Remove this.
58-
public static boolean INDEXING_SUPPORT_ENABLED = BuildConfig.ENABLE_INDEXING;
59-
6055
// Local subclasses only, please.
6156
Persistence() {}
6257

firebase-firestore/src/main/java/com/google/firebase/firestore/local/SQLiteIndexManager.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,6 @@ final class SQLiteIndexManager implements IndexManager {
9696

9797
@Override
9898
public void start() {
99-
if (!Persistence.INDEXING_SUPPORT_ENABLED) {
100-
started = true;
101-
return;
102-
}
103-
10499
Map<Integer, FieldIndex.IndexState> indexStates = new HashMap<>();
105100

106101
// Fetch all index states if persisted for the user. These states contain per user information
@@ -228,7 +223,6 @@ public void deleteFieldIndex(FieldIndex index) {
228223
@Override
229224
public void updateIndexEntries(ImmutableSortedMap<DocumentKey, Document> documents) {
230225
hardAssert(started, "IndexManager not started");
231-
if (!Persistence.INDEXING_SUPPORT_ENABLED) return;
232226

233227
for (Map.Entry<DocumentKey, Document> entry : documents) {
234228
Collection<FieldIndex> fieldIndexes = getFieldIndexes(entry.getKey().getCollectionGroup());
@@ -509,10 +503,6 @@ private Object[] fillBounds(
509503
public FieldIndex getFieldIndex(Target target) {
510504
hardAssert(started, "IndexManager not started");
511505

512-
if (!Persistence.INDEXING_SUPPORT_ENABLED) {
513-
return null;
514-
}
515-
516506
TargetIndexMatcher targetIndexMatcher = new TargetIndexMatcher(target);
517507
String collectionGroup =
518508
target.getCollectionGroup() != null

firebase-firestore/src/main/java/com/google/firebase/firestore/local/SQLiteSchema.java

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import com.google.firebase.firestore.proto.Target;
2929
import com.google.firebase.firestore.util.Consumer;
3030
import com.google.firebase.firestore.util.Logger;
31-
import com.google.firebase.firestore.util.Preconditions;
3231
import com.google.protobuf.InvalidProtocolBufferException;
3332
import java.util.ArrayList;
3433
import java.util.List;
@@ -49,10 +48,7 @@ class SQLiteSchema {
4948
* The version of the schema. Increase this by one for each migration added to runMigrations
5049
* below.
5150
*/
52-
static final int VERSION = 15;
53-
54-
// TODO(indexing): Remove this constant and increment VERSION to enable indexing support
55-
static final int INDEXING_SUPPORT_VERSION = VERSION + 1;
51+
static final int VERSION = 16;
5652

5753
/**
5854
* The batch size for data migrations.
@@ -77,11 +73,7 @@ void runSchemaUpgrades() {
7773
}
7874

7975
void runSchemaUpgrades(int fromVersion) {
80-
int toVersion = VERSION;
81-
if (Persistence.INDEXING_SUPPORT_ENABLED) {
82-
toVersion = INDEXING_SUPPORT_VERSION;
83-
}
84-
runSchemaUpgrades(fromVersion, toVersion);
76+
runSchemaUpgrades(fromVersion, VERSION);
8577
}
8678

8779
/**
@@ -183,6 +175,10 @@ void runSchemaUpgrades(int fromVersion, int toVersion) {
183175
ensureReadTime();
184176
}
185177

178+
if (fromVersion < 16 && toVersion >= 16) {
179+
createFieldIndex();
180+
}
181+
186182
/*
187183
* Adding a new schema upgrade? READ THIS FIRST!
188184
*
@@ -196,11 +192,6 @@ void runSchemaUpgrades(int fromVersion, int toVersion) {
196192
* that existing values have been properly maintained. Calculate them again, if applicable.
197193
*/
198194

199-
if (fromVersion < INDEXING_SUPPORT_VERSION && toVersion >= INDEXING_SUPPORT_VERSION) {
200-
Preconditions.checkState(Persistence.INDEXING_SUPPORT_ENABLED);
201-
createFieldIndex();
202-
}
203-
204195
Logger.debug(
205196
"SQLiteSchema",
206197
"Migration from version %s to %s took %s milliseconds",

firebase-firestore/src/test/java/com/google/firebase/firestore/local/IndexBackfillerTest.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@
4747
import java.util.Map;
4848
import java.util.Set;
4949
import org.junit.After;
50-
import org.junit.AfterClass;
5150
import org.junit.Before;
52-
import org.junit.BeforeClass;
5351
import org.junit.Rule;
5452
import org.junit.Test;
5553
import org.junit.rules.TestName;
@@ -60,18 +58,6 @@
6058
@RunWith(RobolectricTestRunner.class)
6159
@Config(manifest = Config.NONE)
6260
public class IndexBackfillerTest {
63-
/** Current state of indexing support. Used for restoring after test run. */
64-
private static final boolean supportsIndexing = Persistence.INDEXING_SUPPORT_ENABLED;
65-
66-
@BeforeClass
67-
public static void beforeClass() {
68-
Persistence.INDEXING_SUPPORT_ENABLED = true;
69-
}
70-
71-
@AfterClass
72-
public static void afterClass() {
73-
Persistence.INDEXING_SUPPORT_ENABLED = supportsIndexing;
74-
}
7561

7662
@Rule public TestName name = new TestName();
7763

0 commit comments

Comments
 (0)