summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJacek Centkowski <geminica.programs@gmail.com>2022-02-04 12:39:34 +0100
committerJacek Centkowski <geminica.programs@gmail.com>2022-03-09 17:11:31 +0100
commitfa06a731b989f5bd81edca5afb00e767cebad827 (patch)
tree28d65a89e8fc05ad64ded40f5ffdbecd8334ec30
parent349b5f07231f96bffe1acb6c24c1749d5442217c (diff)
Limit 'maxPages' to '100' by deafult
It seems that Lucene implementation has to scan through the large amount of data in order to reach distant page and results in substantial amount of memory being used (results in OOO exception). In order to mitigate it limit 'maxPages' to `100' if no value is set. Note that one can still set it to unlimited by changing the value to '0'. Release-Notes: Limit 'index.maxPages' to '100' by default Bug: Issue 15563 Change-Id: I5a9a50b755d9814fcdd47910702b8ec80b2a029f
-rw-r--r--Documentation/config-gerrit.txt2
-rw-r--r--java/com/google/gerrit/index/IndexConfig.java11
-rw-r--r--javatests/com/google/gerrit/index/IndexConfigTest.java58
3 files changed, 68 insertions, 3 deletions
diff --git a/Documentation/config-gerrit.txt b/Documentation/config-gerrit.txt
index 10baed2750..31bb6be480 100644
--- a/Documentation/config-gerrit.txt
+++ b/Documentation/config-gerrit.txt
@@ -3092,7 +3092,7 @@ results when searching with an offset. Requesting results starting past
this threshold times the requested limit will result in an error. Set to
0 for no limit.
+
-Defaults to no limit.
+Defaults to 100.
[[index.maxTerms]]index.maxTerms::
+
diff --git a/java/com/google/gerrit/index/IndexConfig.java b/java/com/google/gerrit/index/IndexConfig.java
index 29b8ea657e..c93c5393c2 100644
--- a/java/com/google/gerrit/index/IndexConfig.java
+++ b/java/com/google/gerrit/index/IndexConfig.java
@@ -17,6 +17,7 @@ package com.google.gerrit.index;
import static com.google.common.base.Preconditions.checkArgument;
import com.google.auto.value.AutoValue;
+import com.google.common.annotations.VisibleForTesting;
import java.util.function.Consumer;
import java.util.function.IntConsumer;
import org.eclipse.jgit.lib.Config;
@@ -31,6 +32,8 @@ import org.eclipse.jgit.lib.Config;
public abstract class IndexConfig {
private static final int DEFAULT_MAX_TERMS = 1024;
+ @VisibleForTesting static final int DEFAULT_MAX_PAGES = 100;
+
public static IndexConfig createDefault() {
return builder().build();
}
@@ -38,14 +41,18 @@ public abstract class IndexConfig {
public static Builder fromConfig(Config cfg) {
Builder b = builder();
setIfPresent(cfg, "maxLimit", b::maxLimit);
- setIfPresent(cfg, "maxPages", b::maxPages);
+ setIfPresent(cfg, "maxPages", DEFAULT_MAX_PAGES, b::maxPages);
setIfPresent(cfg, "maxTerms", b::maxTerms);
setTypeOrDefault(cfg, b::type);
return b;
}
private static void setIfPresent(Config cfg, String name, IntConsumer setter) {
- int n = cfg.getInt("index", null, name, 0);
+ setIfPresent(cfg, name, 0, setter);
+ }
+
+ private static void setIfPresent(Config cfg, String name, int def, IntConsumer setter) {
+ int n = cfg.getInt("index", null, name, def);
if (n != 0) {
setter.accept(n);
}
diff --git a/javatests/com/google/gerrit/index/IndexConfigTest.java b/javatests/com/google/gerrit/index/IndexConfigTest.java
new file mode 100644
index 0000000000..6d3fcb7024
--- /dev/null
+++ b/javatests/com/google/gerrit/index/IndexConfigTest.java
@@ -0,0 +1,58 @@
+// Copyright (C) 2022 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.index;
+
+import static com.google.common.truth.Truth.assertThat;
+import static com.google.gerrit.index.IndexConfig.DEFAULT_MAX_PAGES;
+
+import org.eclipse.jgit.lib.Config;
+import org.junit.Test;
+
+public class IndexConfigTest {
+ @Test
+ public void maxPagesIsLimitedByDefault() {
+ // when
+ IndexConfig config = IndexConfig.fromConfig(new Config()).build();
+
+ // then
+ assertThat(config.maxPages()).isEqualTo(DEFAULT_MAX_PAGES);
+ }
+
+ @Test
+ public void maxPagesCanBeConfigured() {
+ // given
+ Config cfg = new Config();
+ cfg.setInt("index", null, "maxPages", 10);
+
+ // when
+ IndexConfig config = IndexConfig.fromConfig(cfg).build();
+
+ // then
+ assertThat(config.maxPages()).isEqualTo(10);
+ }
+
+ @Test
+ public void maxPagesCanBeConfiguredToUnlimited() {
+ // given
+ Config cfg = new Config();
+ cfg.setInt("index", null, "maxPages", 0);
+
+ // when
+ IndexConfig config = IndexConfig.fromConfig(cfg).build();
+
+ // then
+ assertThat(config.maxPages()).isEqualTo(Integer.MAX_VALUE);
+ }
+}