Skip to content

Fix index deletion bug #3447

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
Feb 15, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public void addFieldIndex(FieldIndex index) {
public void deleteFieldIndex(FieldIndex index) {
db.execute("DELETE FROM index_configuration WHERE index_id = ?", index.getIndexId());
db.execute("DELETE FROM index_entries WHERE index_id = ?", index.getIndexId());
db.execute("DELETE FROM index_state WHERE index_id = ?", index.getIndexState());
db.execute("DELETE FROM index_state WHERE index_id = ?", index.getIndexId());

nextIndexToUpdate.remove(index);
Map<Integer, FieldIndex> collectionIndices = memoizedIndexes.get(index.getCollectionGroup());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,21 @@ public void testDeleteFieldIndexRemovesEntryFromCollectionGroup() {
assertEquals("coll2", collectionGroup);
}

@Test
public void testDeleteFieldIndexRemovesAllMetadata() {
indexManager.addFieldIndex(
fieldIndex("coll", 1, IndexState.create(1, IndexOffset.NONE), "value", Kind.ASCENDING));
addDoc("coll/doc", map("value", 1));
indexManager.updateCollectionGroup("coll", IndexOffset.NONE);

validateRowCount(1);

FieldIndex existingIndex = indexManager.getFieldIndexes("coll").iterator().next();
indexManager.deleteFieldIndex(existingIndex);

validateRowCount(0);
}

@Test
public void testChangeUser() {
IndexManager indexManager = persistence.getIndexManager(User.UNAUTHENTICATED);
Expand Down Expand Up @@ -714,4 +729,21 @@ private void verifyResults(Query query, String... documents) {
List<DocumentKey> keys = Arrays.stream(documents).map(s -> key(s)).collect(Collectors.toList());
assertWithMessage("Result for %s", query).that(results).containsExactlyElementsIn(keys);
}

/** Validates the row count in the SQLite tables that are used for indexing. */
private void validateRowCount(int expectedRows) {
SQLitePersistence persistence = (SQLitePersistence) this.persistence;
persistence
.query(
"SELECT "
+ "(SELECT COUNT(*) FROM index_state) AS index_state_count, "
+ "(SELECT COUNT(*) FROM index_entries) AS index_entries_count, "
+ "(SELECT COUNT(*) FROM index_configuration) AS index_configuration_count")
.first(
value -> {
assertEquals(value.getInt(0), expectedRows);
assertEquals(value.getInt(1), expectedRows);
assertEquals(value.getInt(2), expectedRows);
});
}
}