Delete a change from the index when it is not in the DB
If for some reason the secondary index is out of date, i.e. the change was deleted from the database but wasn't deleted from the secondary index, it was impossible to re-index (remove) that change. Add logic to automatically remove the change from the secondary index if this change is requested through the Change REST API endpoint and doesn't exist in the database. If a user click on search result from a stale change, he will a get a 404 page and the change will be removed from the index. To fix the problem without opening the change page, run a command like: curl --user <user name> -X POST http://<host>:<port>/a/changes/<change id>/index Issue: 2996 Change-Id: I1db5373e31585e99c5f45e05274d86d69b4f24e6
This commit is contained in:

committed by
Dave Borowitz

parent
04ef5f717d
commit
903be04b02
@@ -322,6 +322,19 @@ public class LuceneChangeIndex implements ChangeIndex {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void delete(int id) throws IOException {
|
||||
Term idTerm = QueryBuilder.idTerm(id);
|
||||
try {
|
||||
Futures.allAsList(
|
||||
openIndex.delete(idTerm),
|
||||
closedIndex.delete(idTerm)).get();
|
||||
} catch (ExecutionException | InterruptedException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAll() throws IOException {
|
||||
openIndex.deleteAll();
|
||||
|
@@ -55,6 +55,10 @@ public class QueryBuilder {
|
||||
return intTerm(ID_FIELD, cd.getId().get());
|
||||
}
|
||||
|
||||
public static Term idTerm(int id) {
|
||||
return intTerm(ID_FIELD, id);
|
||||
}
|
||||
|
||||
private final Schema<ChangeData> schema;
|
||||
private final org.apache.lucene.util.QueryBuilder queryBuilder;
|
||||
|
||||
|
Reference in New Issue
Block a user