Skip to content

Commit a2f0979

Browse files
author
Vladimir Kotal
authored
bump history cache chunk counts and make it tunable (#3647)
fixes #3585
1 parent e65fb53 commit a2f0979

File tree

6 files changed

+49
-3
lines changed

6 files changed

+49
-3
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/Configuration.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,8 @@ public final class Configuration {
308308
private String indexerAuthenticationToken;
309309
private boolean allowInsecureTokens;
310310

311+
private int historyChunkCount;
312+
311313
/*
312314
* types of handling history for remote SCM repositories:
313315
* ON - index history and display it in webapp
@@ -1375,6 +1377,14 @@ public void setAllowInsecureTokens(boolean value) {
13751377
this.allowInsecureTokens = value;
13761378
}
13771379

1380+
public int getHistoryChunkCount() {
1381+
return historyChunkCount;
1382+
}
1383+
1384+
public void setHistoryChunkCount(int historyChunkCount) {
1385+
this.historyChunkCount = historyChunkCount;
1386+
}
1387+
13781388
/**
13791389
* Write the current configuration to a file.
13801390
*

opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/RuntimeEnvironment.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,14 @@ public short getContextSurround() {
13601360
return syncReadConfiguration(Configuration::getContextSurround);
13611361
}
13621362

1363+
public int getHistoryChunkCount() {
1364+
return syncReadConfiguration(Configuration::getHistoryChunkCount);
1365+
}
1366+
1367+
public void setHistoryChunkCount(int chunkCount) {
1368+
syncWriteConfiguration(chunkCount, Configuration::setHistoryChunkCount);
1369+
}
1370+
13631371
public Set<String> getDisabledRepositories() {
13641372
return syncReadConfiguration(Configuration::getDisabledRepositories);
13651373
}

opengrok-indexer/src/main/java/org/opengrok/indexer/history/BoundaryChangesets.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
*/
2323
package org.opengrok.indexer.history;
2424

25+
import org.jetbrains.annotations.TestOnly;
26+
import org.opengrok.indexer.configuration.RuntimeEnvironment;
2527
import org.opengrok.indexer.logger.LoggerFactory;
2628
import org.opengrok.indexer.util.Statistics;
2729

@@ -47,18 +49,31 @@ public class BoundaryChangesets {
4749

4850
public BoundaryChangesets(RepositoryWithPerPartesHistory repository) {
4951
this.repository = repository;
50-
this.maxCount = repository.getPerPartesCount();
52+
53+
int globalPerPartesCount = RuntimeEnvironment.getInstance().getHistoryChunkCount();
54+
if (globalPerPartesCount > 0) {
55+
this.maxCount = globalPerPartesCount;
56+
} else {
57+
this.maxCount = repository.getPerPartesCount();
58+
}
5159
if (maxCount <= 1) {
5260
throw new RuntimeException(String.format("per partes count for repository ''%s'' " +
5361
"must be stricly greater than 1", repository.getDirectoryName()));
5462
}
63+
LOGGER.log(Level.FINER, "using history cache chunks with {0} entries for repository {1}",
64+
new Object[]{this.maxCount, repository});
5565
}
5666

5767
private void reset() {
5868
cnt = 0;
5969
result.clear();
6070
}
6171

72+
@TestOnly
73+
int getMaxCount() {
74+
return maxCount;
75+
}
76+
6277
/**
6378
* @param sinceRevision start revision ID
6479
* @return immutable list of revision IDs denoting the intervals

opengrok-indexer/src/main/java/org/opengrok/indexer/history/GitRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public class GitRepository extends RepositoryWithPerPartesHistory {
100100
private static final long serialVersionUID = -6126297612958508386L;
101101

102102
public static final int GIT_ABBREV_LEN = 8;
103-
public static final int MAX_CHANGESETS = 512;
103+
public static final int MAX_CHANGESETS = 65536;
104104

105105
public GitRepository() {
106106
type = "git";

opengrok-indexer/src/main/java/org/opengrok/indexer/history/MercurialRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class MercurialRepository extends RepositoryWithPerPartesHistory {
5858

5959
private static final long serialVersionUID = 1L;
6060

61-
public static final int MAX_CHANGESETS = 256;
61+
public static final int MAX_CHANGESETS = 131072;
6262

6363
/**
6464
* The property name used to obtain the client command for this repository.

opengrok-indexer/src/test/java/org/opengrok/indexer/history/BoundaryChangesetsTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
import org.apache.commons.lang3.tuple.ImmutableTriple;
2626
import org.junit.jupiter.api.AfterEach;
2727
import org.junit.jupiter.api.BeforeEach;
28+
import org.junit.jupiter.api.Test;
2829
import org.junit.jupiter.params.ParameterizedTest;
2930
import org.junit.jupiter.params.provider.MethodSource;
3031
import org.junit.jupiter.params.provider.ValueSource;
3132
import org.mockito.Mockito;
33+
import org.opengrok.indexer.configuration.RuntimeEnvironment;
3234
import org.opengrok.indexer.util.TestRepository;
3335

3436
import java.io.File;
@@ -37,6 +39,7 @@
3739
import java.util.stream.Stream;
3840

3941
import static org.junit.jupiter.api.Assertions.assertEquals;
42+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
4043
import static org.junit.jupiter.api.Assertions.assertNotNull;
4144
import static org.junit.jupiter.api.Assertions.assertThrows;
4245
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -74,6 +77,16 @@ void testInvalidMaxCount(int maxCount) {
7477
assertThrows(RuntimeException.class, () -> new BoundaryChangesets(gitSpyRepository));
7578
}
7679

80+
@Test
81+
void testMaxCountConfiguration() {
82+
int maxCount = (RuntimeEnvironment.getInstance().getHistoryChunkCount() + 1) * 2;
83+
assertNotEquals(0, maxCount);
84+
RuntimeEnvironment.getInstance().setHistoryChunkCount(maxCount);
85+
int actualCount = new BoundaryChangesets(gitRepository).getMaxCount();
86+
RuntimeEnvironment.getInstance().setHistoryChunkCount(0);
87+
assertEquals(maxCount, actualCount);
88+
}
89+
7790
/**
7891
* Used to supply test data for testing {@link BoundaryChangesets#getBoundaryChangesetIDs(String)}.
7992
* @return triplets of (maximum count, start revision, list of expected revisions)

0 commit comments

Comments
 (0)