Store PatchSetApprovals instead of labels in the index

The goal of storing SubmitRecord.Labels in the index was to render the
change table, but that requires both the results of the submit rule
evaluator and, in fact, all of the current PatchSetApprovals.

Instead, store PatchSetApprovals, which are trivial to find at
indexing time. Note that we do not just use the formatted label
representation stored in the index because it does not contain all the
necessary columns (e.g. timestamp). These may not be strictly speaking
required for rendering the change table, but having them set to null
in some cases might have caused errors down the line.

Delete the old label-based code entirely and change schema v2 rather
than revving to v3. This mistake was short-lived enough that we don't
expect people to have production data using it, and the old code was
sufficiently complex and incorrect that keeping it around isn't a good
idea.

Change-Id: I805a8fd6c60d4818910aed299260f56ef3006287
This commit is contained in:
Dave Borowitz
2013-09-12 13:25:58 -07:00
parent cce486f760
commit 24b14d5053
8 changed files with 75 additions and 264 deletions

View File

@@ -25,12 +25,12 @@ import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningScheduledExecutorService;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.SubmitRecord;
import com.google.gerrit.reviewdb.client.PatchSetApproval;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.config.SitePaths;
import com.google.gerrit.server.index.ChangeField;
import com.google.gerrit.server.index.ChangeField.ChangeProtoField;
import com.google.gerrit.server.index.ChangeField.SubmitLabelProtoField;
import com.google.gerrit.server.index.ChangeField.PatchSetApprovalProtoField;
import com.google.gerrit.server.index.ChangeIndex;
import com.google.gerrit.server.index.FieldDef;
import com.google.gerrit.server.index.FieldDef.FillArgs;
@@ -104,8 +104,7 @@ public class LuceneChangeIndex implements ChangeIndex {
public static final String CHANGES_CLOSED = "closed";
private static final String ID_FIELD = ChangeField.LEGACY_ID.getName();
private static final String CHANGE_FIELD = ChangeField.CHANGE.getName();
private static final String SUBMIT_LABEL_FIELD =
ChangeField.SUBMIT_RECORD_LABEL.getName();
private static final String APPROVAL_FIELD = ChangeField.APPROVAL.getName();
static interface Factory {
LuceneChangeIndex create(Schema<ChangeData> schema, String base);
@@ -265,7 +264,7 @@ public class LuceneChangeIndex implements ChangeIndex {
private static class QuerySource implements ChangeDataSource {
private static final ImmutableSet<String> FIELDS =
ImmutableSet.of(ID_FIELD, CHANGE_FIELD, SUBMIT_LABEL_FIELD);
ImmutableSet.of(ID_FIELD, CHANGE_FIELD, APPROVAL_FIELD);
private final List<SubIndex> indexes;
private final Query query;
@@ -359,15 +358,15 @@ public class LuceneChangeIndex implements ChangeIndex {
cb.bytes, cb.offset, cb.length);
ChangeData cd = new ChangeData(change);
BytesRef[] labelsBytes = doc.getBinaryValues(SUBMIT_LABEL_FIELD);
if (labelsBytes != null) {
List<SubmitRecord.Label> labels =
Lists.newArrayListWithCapacity(labelsBytes.length);
for (BytesRef lb : labelsBytes) {
labels.add(SubmitLabelProtoField.CODEC.decode(
lb.bytes, lb.offset, lb.length));
BytesRef[] approvalsBytes = doc.getBinaryValues(APPROVAL_FIELD);
if (approvalsBytes != null) {
List<PatchSetApproval> approvals =
Lists.newArrayListWithCapacity(approvalsBytes.length);
for (BytesRef ab : approvalsBytes) {
approvals.add(PatchSetApprovalProtoField.CODEC.decode(
ab.bytes, ab.offset, ab.length));
}
cd.setSubmitRecordLabels(labels);
cd.setCurrentApprovals(approvals);
}
return cd;
}