Add AccountIndexRewriter
The AccountIndexRewriter only translates Predicate<AccountState> to IndexedAccountQuery. It is much simpler than the ChangeIndexRewriter because for the account index there are no subindices and all predicates are served by the index. If a predicates requires a field that is not contained in the current index schema we would just fail those queries at the QueryBuilder. Change-Id: Ib0e8bcba9b475d861b102a8a7c51fcf13a3418ae Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -21,8 +21,8 @@ import static com.google.gerrit.server.git.QueueProvider.QueueType.INTERACTIVE;
|
||||
import static com.google.gerrit.server.index.change.ChangeField.CHANGE;
|
||||
import static com.google.gerrit.server.index.change.ChangeField.LEGACY_ID;
|
||||
import static com.google.gerrit.server.index.change.ChangeField.PROJECT;
|
||||
import static com.google.gerrit.server.index.change.IndexRewriter.CLOSED_STATUSES;
|
||||
import static com.google.gerrit.server.index.change.IndexRewriter.OPEN_STATUSES;
|
||||
import static com.google.gerrit.server.index.change.ChangeIndexRewriter.CLOSED_STATUSES;
|
||||
import static com.google.gerrit.server.index.change.ChangeIndexRewriter.OPEN_STATUSES;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
@@ -51,7 +51,7 @@ import com.google.gerrit.server.index.change.ChangeField.ChangeProtoField;
|
||||
import com.google.gerrit.server.index.change.ChangeField.PatchSetApprovalProtoField;
|
||||
import com.google.gerrit.server.index.change.ChangeField.PatchSetProtoField;
|
||||
import com.google.gerrit.server.index.change.ChangeIndex;
|
||||
import com.google.gerrit.server.index.change.IndexRewriter;
|
||||
import com.google.gerrit.server.index.change.ChangeIndexRewriter;
|
||||
import com.google.gerrit.server.query.Predicate;
|
||||
import com.google.gerrit.server.query.QueryParseException;
|
||||
import com.google.gerrit.server.query.change.ChangeData;
|
||||
@@ -239,7 +239,7 @@ public class LuceneChangeIndex implements ChangeIndex {
|
||||
@Override
|
||||
public ChangeDataSource getSource(Predicate<ChangeData> p, QueryOptions opts)
|
||||
throws QueryParseException {
|
||||
Set<Change.Status> statuses = IndexRewriter.getPossibleStatus(p);
|
||||
Set<Change.Status> statuses = ChangeIndexRewriter.getPossibleStatus(p);
|
||||
List<ChangeSubIndex> indexes = Lists.newArrayListWithCapacity(2);
|
||||
if (!Sets.intersection(statuses, OPEN_STATUSES).isEmpty()) {
|
||||
indexes.add(openIndex);
|
||||
|
||||
@@ -28,12 +28,13 @@ import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.gerrit.server.git.WorkQueue;
|
||||
import com.google.gerrit.server.index.account.AccountIndexCollection;
|
||||
import com.google.gerrit.server.index.account.AccountIndexDefinition;
|
||||
import com.google.gerrit.server.index.account.AccountIndexRewriter;
|
||||
import com.google.gerrit.server.index.account.AccountSchemaDefinitions;
|
||||
import com.google.gerrit.server.index.change.ChangeIndexCollection;
|
||||
import com.google.gerrit.server.index.change.ChangeIndexDefinition;
|
||||
import com.google.gerrit.server.index.change.ChangeIndexRewriter;
|
||||
import com.google.gerrit.server.index.change.ChangeIndexer;
|
||||
import com.google.gerrit.server.index.change.ChangeSchemaDefinitions;
|
||||
import com.google.gerrit.server.index.change.IndexRewriter;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.Provides;
|
||||
@@ -87,11 +88,11 @@ public class IndexModule extends LifecycleModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(IndexRewriter.class);
|
||||
|
||||
bind(AccountIndexRewriter.class);
|
||||
bind(AccountIndexCollection.class);
|
||||
listener().to(AccountIndexCollection.class);
|
||||
|
||||
bind(ChangeIndexRewriter.class);
|
||||
bind(ChangeIndexCollection.class);
|
||||
listener().to(ChangeIndexCollection.class);
|
||||
factory(ChangeIndexer.Factory.class);
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
// Copyright (C) 2016 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.index;
|
||||
|
||||
import com.google.gerrit.server.query.Predicate;
|
||||
import com.google.gerrit.server.query.QueryParseException;
|
||||
|
||||
public interface IndexRewriter<T> {
|
||||
|
||||
Predicate<T> rewrite(Predicate<T> in, QueryOptions opts)
|
||||
throws QueryParseException;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// Copyright (C) 2016 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.index.account;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.google.gerrit.server.account.AccountState;
|
||||
import com.google.gerrit.server.index.IndexRewriter;
|
||||
import com.google.gerrit.server.index.QueryOptions;
|
||||
import com.google.gerrit.server.query.Predicate;
|
||||
import com.google.gerrit.server.query.QueryParseException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
public class AccountIndexRewriter implements IndexRewriter<AccountState> {
|
||||
|
||||
private final AccountIndexCollection indexes;
|
||||
|
||||
@Inject
|
||||
AccountIndexRewriter(AccountIndexCollection indexes) {
|
||||
this.indexes = indexes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Predicate<AccountState> rewrite(Predicate<AccountState> in,
|
||||
QueryOptions opts) throws QueryParseException {
|
||||
AccountIndex index = indexes.getSearchIndex();
|
||||
checkNotNull(index, "no active search index configured for accounts");
|
||||
return new IndexedAccountQuery(index, in, opts);
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.Change.Status;
|
||||
import com.google.gerrit.server.index.IndexConfig;
|
||||
import com.google.gerrit.server.index.IndexPredicate;
|
||||
import com.google.gerrit.server.index.IndexRewriter;
|
||||
import com.google.gerrit.server.index.QueryOptions;
|
||||
import com.google.gerrit.server.query.AndPredicate;
|
||||
import com.google.gerrit.server.query.NotPredicate;
|
||||
@@ -43,7 +44,7 @@ import java.util.Set;
|
||||
|
||||
/** Rewriter that pushes boolean logic into the secondary index. */
|
||||
@Singleton
|
||||
public class IndexRewriter {
|
||||
public class ChangeIndexRewriter implements IndexRewriter<ChangeData> {
|
||||
/** Set of all open change statuses. */
|
||||
public static final Set<Change.Status> OPEN_STATUSES;
|
||||
|
||||
@@ -124,12 +125,13 @@ public class IndexRewriter {
|
||||
private final IndexConfig config;
|
||||
|
||||
@Inject
|
||||
IndexRewriter(ChangeIndexCollection indexes,
|
||||
ChangeIndexRewriter(ChangeIndexCollection indexes,
|
||||
IndexConfig config) {
|
||||
this.indexes = indexes;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Predicate<ChangeData> rewrite(Predicate<ChangeData> in,
|
||||
QueryOptions opts) throws QueryParseException {
|
||||
ChangeIndex index = indexes.getSearchIndex();
|
||||
@@ -57,7 +57,7 @@ import com.google.gerrit.server.index.Schema;
|
||||
import com.google.gerrit.server.index.change.ChangeField;
|
||||
import com.google.gerrit.server.index.change.ChangeIndex;
|
||||
import com.google.gerrit.server.index.change.ChangeIndexCollection;
|
||||
import com.google.gerrit.server.index.change.IndexRewriter;
|
||||
import com.google.gerrit.server.index.change.ChangeIndexRewriter;
|
||||
import com.google.gerrit.server.notedb.ChangeNotes;
|
||||
import com.google.gerrit.server.patch.PatchListCache;
|
||||
import com.google.gerrit.server.project.ChangeControl;
|
||||
@@ -158,7 +158,7 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
|
||||
public static class Arguments {
|
||||
final Provider<ReviewDb> db;
|
||||
final Provider<InternalChangeQuery> queryProvider;
|
||||
final IndexRewriter rewriter;
|
||||
final ChangeIndexRewriter rewriter;
|
||||
final DynamicMap<ChangeOperatorFactory> opFactories;
|
||||
final IdentifiedUser.GenericFactory userFactory;
|
||||
final CapabilityControl.Factory capabilityControlFactory;
|
||||
@@ -190,7 +190,7 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
|
||||
@VisibleForTesting
|
||||
public Arguments(Provider<ReviewDb> db,
|
||||
Provider<InternalChangeQuery> queryProvider,
|
||||
IndexRewriter rewriter,
|
||||
ChangeIndexRewriter rewriter,
|
||||
DynamicMap<ChangeOperatorFactory> opFactories,
|
||||
IdentifiedUser.GenericFactory userFactory,
|
||||
Provider<CurrentUser> self,
|
||||
@@ -229,7 +229,7 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
|
||||
private Arguments(
|
||||
Provider<ReviewDb> db,
|
||||
Provider<InternalChangeQuery> queryProvider,
|
||||
IndexRewriter rewriter,
|
||||
ChangeIndexRewriter rewriter,
|
||||
DynamicMap<ChangeOperatorFactory> opFactories,
|
||||
IdentifiedUser.GenericFactory userFactory,
|
||||
Provider<CurrentUser> self,
|
||||
|
||||
@@ -32,7 +32,7 @@ import com.google.gerrit.server.index.IndexPredicate;
|
||||
import com.google.gerrit.server.index.QueryOptions;
|
||||
import com.google.gerrit.server.index.change.ChangeIndex;
|
||||
import com.google.gerrit.server.index.change.ChangeIndexCollection;
|
||||
import com.google.gerrit.server.index.change.IndexRewriter;
|
||||
import com.google.gerrit.server.index.change.ChangeIndexRewriter;
|
||||
import com.google.gerrit.server.index.change.IndexedChangeQuery;
|
||||
import com.google.gerrit.server.notedb.ChangeNotes;
|
||||
import com.google.gerrit.server.project.ChangeControl;
|
||||
@@ -54,7 +54,7 @@ public class QueryProcessor {
|
||||
private final ChangeControl.GenericFactory changeControlFactory;
|
||||
private final ChangeNotes.Factory notesFactory;
|
||||
private final ChangeIndexCollection indexes;
|
||||
private final IndexRewriter rewriter;
|
||||
private final ChangeIndexRewriter rewriter;
|
||||
private final IndexConfig indexConfig;
|
||||
private final Metrics metrics;
|
||||
|
||||
@@ -69,7 +69,7 @@ public class QueryProcessor {
|
||||
ChangeControl.GenericFactory changeControlFactory,
|
||||
ChangeNotes.Factory notesFactory,
|
||||
ChangeIndexCollection indexes,
|
||||
IndexRewriter rewriter,
|
||||
ChangeIndexRewriter rewriter,
|
||||
IndexConfig indexConfig,
|
||||
Metrics metrics) {
|
||||
this.db = db;
|
||||
|
||||
@@ -45,13 +45,13 @@ import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class IndexRewriterTest extends GerritBaseTests {
|
||||
public class ChangeIndexRewriterTest extends GerritBaseTests {
|
||||
private static final IndexConfig CONFIG = IndexConfig.createDefault();
|
||||
|
||||
private FakeChangeIndex index;
|
||||
private ChangeIndexCollection indexes;
|
||||
private ChangeQueryBuilder queryBuilder;
|
||||
private IndexRewriter rewrite;
|
||||
private ChangeIndexRewriter rewrite;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@@ -59,7 +59,7 @@ public class IndexRewriterTest extends GerritBaseTests {
|
||||
indexes = new ChangeIndexCollection();
|
||||
indexes.setSearchIndex(index);
|
||||
queryBuilder = new FakeQueryBuilder(indexes);
|
||||
rewrite = new IndexRewriter(indexes,
|
||||
rewrite = new ChangeIndexRewriter(indexes,
|
||||
IndexConfig.create(0, 0, 3));
|
||||
}
|
||||
|
||||
@@ -292,6 +292,6 @@ public class IndexRewriterTest extends GerritBaseTests {
|
||||
}
|
||||
|
||||
private Set<Change.Status> status(String query) throws QueryParseException {
|
||||
return IndexRewriter.getPossibleStatus(parse(query));
|
||||
return ChangeIndexRewriter.getPossibleStatus(parse(query));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user