Store project field in change index

Sometimes we need to lookup a change from the index in order to be
able to load it from the database or notedb. This is e.g. the case
when we only have a Change-Id. In this case we want to reload the
change after the index lookup because the index can be stale. This is
why we don't request any fields from the index when the change is
looked up, so that a rereading is enforced. So far the change ID was
sufficient for rereading because we always loaded the change from the
database, but for rereading the change from notedb, we need the
project name in addition. This is why the project field should be
stored in the index. In the case described above we explicitly don't
want to request the change field which contains the project, since the
index may be stale and requesting the change field wouldn't enforce
rereading the change. To have the project name available for
rereading the change the project field should be always included in
the set of requested fields, when the change field is not requested.

Because the project field was changed we need a new schema version
although it contains the same fields as the current schema version.

Change-Id: I14eefae0ef90accab6972d11babddf0402ce01b5
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2016-02-04 11:46:55 +01:00
parent 02417753a9
commit 25b6287364
4 changed files with 21 additions and 1 deletions

View File

@@ -18,6 +18,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.getOnlyElement;
import static com.google.gerrit.server.git.QueueProvider.QueueType.INTERACTIVE;
import static com.google.gerrit.server.index.ChangeField.LEGACY_ID;
import static com.google.gerrit.server.index.ChangeField.PROJECT;
import static com.google.gerrit.server.index.IndexRewriter.CLOSED_STATUSES;
import static com.google.gerrit.server.index.IndexRewriter.OPEN_STATUSES;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
@@ -34,6 +35,7 @@ import com.google.gerrit.common.Nullable;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.config.ConfigUtil;
import com.google.gerrit.server.config.GerritServerConfig;
@@ -454,6 +456,10 @@ public class LuceneChangeIndex implements ChangeIndex {
ChangeProtoField.CODEC.decode(cb.bytes, cb.offset, cb.length));
} else {
int id = doc.getField(idFieldName).numericValue().intValue();
// TODO(ekempin): Pass project to changeDataFactory
@SuppressWarnings("unused")
Project.NameKey project =
new Project.NameKey(doc.getField(PROJECT.getName()).stringValue());
cd = changeDataFactory.create(db.get(), new Change.Id(id));
}