Skip to content

Commit 5a635a8

Browse files
Vladimir Kotalahornace
authored andcommitted
add option to turn off per partes history cache
fixes #3660
1 parent 2ebeb8f commit 5a635a8

File tree

7 files changed

+56
-1
lines changed

7 files changed

+56
-1
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ public final class Configuration {
309309
private boolean allowInsecureTokens;
310310

311311
private int historyChunkCount;
312+
private boolean historyCachePerPartesEnabled = true;
312313

313314
/*
314315
* types of handling history for remote SCM repositories:
@@ -1385,6 +1386,14 @@ public void setHistoryChunkCount(int historyChunkCount) {
13851386
this.historyChunkCount = historyChunkCount;
13861387
}
13871388

1389+
public boolean isHistoryCachePerPartesEnabled() {
1390+
return historyCachePerPartesEnabled;
1391+
}
1392+
1393+
public void setHistoryCachePerPartesEnabled(boolean historyCachePerPartesEnabled) {
1394+
this.historyCachePerPartesEnabled = historyCachePerPartesEnabled;
1395+
}
1396+
13881397
/**
13891398
* Write the current configuration to a file.
13901399
*

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
@@ -1368,6 +1368,14 @@ public void setHistoryChunkCount(int chunkCount) {
13681368
syncWriteConfiguration(chunkCount, Configuration::setHistoryChunkCount);
13691369
}
13701370

1371+
public boolean isHistoryCachePerPartesEnabled() {
1372+
return syncReadConfiguration(Configuration::isHistoryCachePerPartesEnabled);
1373+
}
1374+
1375+
public void setHistoryCachePerPartesEnabled(boolean enabled) {
1376+
syncWriteConfiguration(enabled, Configuration::setHistoryCachePerPartesEnabled);
1377+
}
1378+
13711379
public Set<String> getDisabledRepositories() {
13721380
return syncReadConfiguration(Configuration::getDisabledRepositories);
13731381
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ public void store(History history, Repository repository) throws HistoryExceptio
397397
* corresponding source file.
398398
*
399399
* @param history history object to process into per-file histories
400+
* @param tillRevision end revision
400401
* @param repository repository object
401402
*/
402403
@Override

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2006, 2020, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2006, 2021, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package org.opengrok.indexer.history;
2424

@@ -73,6 +73,14 @@ History get(File file, Repository repository, boolean withFiles)
7373
*/
7474
void store(History history, Repository repository) throws HistoryException;
7575

76+
/**
77+
* Store potentially partial history for a repository.
78+
*
79+
* @param history The history to store
80+
* @param repository The repository whose history to store
81+
* @param tillRevision end revision (can be null)
82+
* @throws HistoryException if the history cannot be stored
83+
*/
7684
void store(History history, Repository repository, String tillRevision) throws HistoryException;
7785

7886
/**

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,13 @@ final void createCache(HistoryCache cache, String sinceRevision) throws HistoryE
413413
LOGGER.log(Level.FINE, "Done storing history cache for repository {0}", getDirectoryName());
414414
}
415415

416+
/**
417+
* Actually store the history in history cache
418+
* @param cache history cache object
419+
* @param history history to store
420+
* @param tillRevision end revision (matters only for renamed files), can be null
421+
* @throws HistoryException on error
422+
*/
416423
void finishCreateCache(HistoryCache cache, History history, String tillRevision) throws HistoryException {
417424
// We need to refresh list of tags for incremental reindex.
418425
RuntimeEnvironment env = RuntimeEnvironment.getInstance();

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

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

25+
import org.opengrok.indexer.configuration.RuntimeEnvironment;
2526
import org.opengrok.indexer.logger.LoggerFactory;
2627
import org.opengrok.indexer.util.Statistics;
2728

@@ -70,6 +71,13 @@ public int getPerPartesCount() {
7071

7172
@Override
7273
protected void doCreateCache(HistoryCache cache, String sinceRevision, File directory) throws HistoryException {
74+
if (!RuntimeEnvironment.getInstance().isHistoryCachePerPartesEnabled()) {
75+
LOGGER.log(Level.INFO, "repository {0} supports per partes history cache creation however " +
76+
"it is disabled in the configuration. Generating history cache as whole.", this);
77+
finishCreateCache(cache, getHistory(directory, sinceRevision), null);
78+
return;
79+
}
80+
7381
// For repositories that supports this, avoid storing complete History in memory
7482
// (which can be sizeable, at least for the initial indexing, esp. if merge changeset support is enabled),
7583
// by splitting the work into multiple chunks.

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import static org.mockito.ArgumentMatchers.anyString;
4545
import static org.mockito.ArgumentMatchers.isNull;
4646
import static org.mockito.Mockito.times;
47+
import static org.mockito.Mockito.verify;
4748

4849
public class RepositoryWithPerPartesHistoryTest {
4950
private TestRepository repositories;
@@ -127,4 +128,17 @@ void testPseudoIncomingChangeset() throws Exception {
127128
assertEquals(1, cachedHistory.getHistoryEntries().size());
128129
assertEquals(historyEntries.get(0).getRevision(), cachedHistory.getHistoryEntries().get(0).getRevision());
129130
}
131+
132+
@Test
133+
void testPerPartesOff() throws HistoryException {
134+
FileHistoryCache cache = new FileHistoryCache();
135+
FileHistoryCache spyCache = Mockito.spy(cache);
136+
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
137+
env.setHistoryCachePerPartesEnabled(false);
138+
assertFalse(env.isHistoryCachePerPartesEnabled());
139+
// Use non-null revision for better robustness (in case sinceRevision gets mixed up with tillRevision).
140+
gitRepository.createCache(spyCache, "b6413947a59f481ddc0a05e0d181731233557f6e");
141+
verify(spyCache, times(1)).store(any(), any(), isNull());
142+
env.setHistoryCachePerPartesEnabled(true);
143+
}
130144
}

0 commit comments

Comments
 (0)