IndexConfig: Configure maxLimit from Config

An index implementation may not have an inherent upper bound to the
limit, but administrators may nonetheless want to restrict the maximum
query size at the server level for performance reasons.

Change-Id: Ic1f506e9857413ec860fe97785bff9e76b817db0
This commit is contained in:
Dave Borowitz 2015-04-22 16:43:54 -07:00
parent 8b6ec067e9
commit b82fbcb584
4 changed files with 35 additions and 4 deletions

View File

@ -2205,6 +2205,14 @@ advantage of new search features without restarting the server.
+
Defaults to true.
[[index.maxLimit]]index.maxLimit::
+
Maximum limit to allow for search queries. Requesting results above this
limit will truncate the list (but will still set `_more_changes` on
result lists). Set to 0 for no limit.
+
Defaults to no limit.
==== Lucene configuration
Open and closed changes are indexed in separate indexes named

View File

@ -16,6 +16,7 @@ package com.google.gerrit.lucene;
import com.google.gerrit.extensions.events.LifecycleListener;
import com.google.gerrit.lifecycle.LifecycleModule;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.index.ChangeSchemas;
import com.google.gerrit.server.index.IndexCollection;
import com.google.gerrit.server.index.IndexConfig;
@ -26,6 +27,8 @@ import com.google.inject.Inject;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import org.eclipse.jgit.lib.Config;
public class LuceneIndexModule extends LifecycleModule {
private final Integer singleVersion;
private final int threads;
@ -44,7 +47,6 @@ public class LuceneIndexModule extends LifecycleModule {
@Override
protected void configure() {
bind(IndexConfig.class).toInstance(IndexConfig.createDefault());
factory(LuceneChangeIndex.Factory.class);
install(new IndexModule(threads));
if (singleVersion == null && base == null) {
@ -54,6 +56,12 @@ public class LuceneIndexModule extends LifecycleModule {
}
}
@Provides
@Singleton
IndexConfig getIndexConfig(@GerritServerConfig Config cfg) {
return IndexConfig.fromConfig(cfg);
}
private static class MultiVersionModule extends LifecycleModule {
@Override
public void configure() {

View File

@ -18,6 +18,8 @@ import static com.google.common.base.Preconditions.checkArgument;
import com.google.auto.value.AutoValue;
import org.eclipse.jgit.lib.Config;
/**
* Implementation-specific configuration for secondary indexes.
* <p>
@ -28,11 +30,19 @@ import com.google.auto.value.AutoValue;
@AutoValue
public abstract class IndexConfig {
public static IndexConfig createDefault() {
return create(Integer.MAX_VALUE);
return create(0);
}
public static IndexConfig fromConfig(Config cfg) {
return create(cfg.getInt("index", null, "maxLimit", 0));
}
public static IndexConfig create(int maxLimit) {
checkArgument(maxLimit > 0, "maxLimit must be positive: %s", maxLimit);
if (maxLimit == 0) {
maxLimit = Integer.MAX_VALUE;
} else {
checkArgument(maxLimit > 0, "maxLimit must be positive: %s", maxLimit);
}
return new AutoValue_IndexConfig(maxLimit);
}

View File

@ -50,7 +50,6 @@ public class SolrIndexModule extends LifecycleModule {
@Override
protected void configure() {
bind(IndexConfig.class).toInstance(IndexConfig.createDefault());
install(new IndexModule(threads));
bind(ChangeIndex.class).to(SolrChangeIndex.class);
listener().to(SolrChangeIndex.class);
@ -59,6 +58,12 @@ public class SolrIndexModule extends LifecycleModule {
}
}
@Provides
@Singleton
IndexConfig getIndexConfig(@GerritServerConfig Config cfg) {
return IndexConfig.fromConfig(cfg);
}
@Provides
@Singleton
public SolrChangeIndex getChangeIndex(@GerritServerConfig Config cfg,