Skip to content

Commit 64ffde9

Browse files
committed
change the tunable for fetching history when not found in file history cache
fixes #917
1 parent d625ae9 commit 64ffde9

File tree

5 files changed

+91
-21
lines changed

5 files changed

+91
-21
lines changed

src/org/opensolaris/opengrok/configuration/Configuration.java

+18-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package org.opensolaris.opengrok.configuration;
2424

@@ -86,7 +86,7 @@ public final class Configuration {
8686
*/
8787
private Project defaultProject;
8888
/**
89-
* Default size of memory to be used for flushing of lucene docs
89+
* Default size of memory to be used for flushing of Lucene docs
9090
* per thread.
9191
* Lucene 4.x uses 16MB and 8 threads, so below is a nice tunable.
9292
*/
@@ -126,6 +126,13 @@ public final class Configuration {
126126
private int tabSize;
127127
private int command_timeout;
128128
private static final Logger logger = Logger.getLogger(Configuration.class.getName());
129+
/*
130+
* Set if we want to disable fetching history of individual files
131+
* (by running appropriate SCM command) when the history is not found
132+
* in history cache for repositories capable of fetching history for
133+
* directories. This option affects file based history cache only.
134+
*/
135+
private boolean noFetchHistoryWhenNoCache;
129136

130137
public static final double defaultRamBufferSize=16;
131138
public static final int defaultScanningDepth=3;
@@ -168,10 +175,6 @@ public int getTabSize() {
168175
/**
169176
* Set the default tab size (number of space characters per tab character)
170177
* to use for each project. If {@code <= 0} tabs are read/write as is.
171-
*
172-
*
173-
*
174-
175178
*
176179
* @param tabSize tabsize to set.
177180
* @see Project#setTabSize(int)
@@ -239,6 +242,7 @@ public Configuration() {
239242
setSourceRoot(null);
240243
setDataRoot(null);
241244
setCommandTimeout(600); // 10 minutes
245+
setFetchHistoryWhenNotInCache(true);
242246
}
243247

244248
public String getRepoCmd(String clazzName) {
@@ -330,6 +334,14 @@ public void setHistoryCacheTime(int historyCacheTime) {
330334
this.historyCacheTime = historyCacheTime;
331335
}
332336

337+
public boolean isFetchHistoryWhenNotInCache() {
338+
return noFetchHistoryWhenNoCache;
339+
}
340+
341+
public void setFetchHistoryWhenNotInCache(boolean nofetch) {
342+
this.noFetchHistoryWhenNoCache = nofetch;
343+
}
344+
333345
/**
334346
* Should the history cache be stored in a database? If yes,
335347
* {@code JDBCHistoryCache} will be used to cache the history; otherwise,

src/org/opensolaris/opengrok/configuration/RuntimeEnvironment.java

+7-9
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

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

@@ -887,16 +887,14 @@ public void setChattyStatusPage(boolean chatty) {
887887
threadConfig.get().setChattyStatusPage(chatty);
888888
}
889889

890-
public boolean noFetchHistoryWhenNotInCache() {
891-
String enabled =
892-
System.getProperty("org.opensolaris.opengrok.history.noFetchWhenNotInCache");
893-
if (enabled != null) {
894-
return true;
895-
}
890+
public void setFetchHistoryWhenNotInCache(boolean nofetch) {
891+
threadConfig.get().setFetchHistoryWhenNotInCache(nofetch);
892+
}
896893

897-
return (false);
894+
public boolean isFetchHistoryWhenNotInCache() {
895+
return threadConfig.get().isFetchHistoryWhenNotInCache();
898896
}
899-
897+
900898
/**
901899
* Read an configuration file and set it as the current configuration.
902900
*

src/org/opensolaris/opengrok/history/FileHistoryCache.java

+11-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323

2424
package org.opensolaris.opengrok.history;
@@ -476,11 +476,17 @@ public History get(File file, Repository repository, boolean withFiles)
476476
}
477477
}
478478

479-
// Some repository checkouts may contain lots of files untracked by
480-
// given SCM. For these it would be waste of time to get their history.
479+
/*
480+
* Some mirrors of repositories which are capable of fetching history
481+
* for directories may contain lots of files untracked by given SCM.
482+
* For these it would be waste of time to get their history
483+
* since the history of all files in this repository should have been
484+
* fetched in the first phase of indexing.
485+
*/
481486
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
482-
if (isHistoryIndexDone() && env.noFetchHistoryWhenNotInCache()) {
483-
return null;
487+
if (isHistoryIndexDone() && repository.hasHistoryForDirectories() &&
488+
!env.isFetchHistoryWhenNotInCache()) {
489+
return null;
484490
}
485491

486492
final History history;

test/org/opensolaris/opengrok/configuration/RuntimeEnvironmentTest.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package org.opensolaris.opengrok.configuration;
2424

@@ -171,6 +171,14 @@ public void testHistoryReaderTimeLimit() {
171171
assertEquals(50, instance.getHistoryReaderTimeLimit());
172172
}
173173

174+
@Test
175+
public void testFetchHistoryWhenNotInCache() {
176+
RuntimeEnvironment instance = RuntimeEnvironment.getInstance();
177+
assertEquals(true, instance.isFetchHistoryWhenNotInCache());
178+
instance.setFetchHistoryWhenNotInCache(false);
179+
assertEquals(false, instance.isFetchHistoryWhenNotInCache());
180+
}
181+
174182
@Test
175183
public void testUseHistoryCache() {
176184
RuntimeEnvironment instance = RuntimeEnvironment.getInstance();

test/org/opensolaris/opengrok/history/FileHistoryCacheTest.java

+46
Original file line numberDiff line numberDiff line change
@@ -383,4 +383,50 @@ public void testRenamedFile() throws Exception {
383383
updatedHistory = cache.get(reposRoot, repo, true);
384384
assertEquals(14, updatedHistory.getHistoryEntries().size());
385385
}
386+
387+
private void checkNoHistoryFetchRepo(String reponame, String filename,
388+
boolean hasHistory, boolean historyFileExists) throws Exception {
389+
390+
File reposRoot = new File(repositories.getSourceRoot(), reponame);
391+
Repository repo = RepositoryFactory.getRepository(reposRoot);
392+
393+
// Make sure the file exists in the repository.
394+
File repoFile = new File(reposRoot, filename);
395+
assertTrue(repoFile.exists());
396+
397+
// Try to fetch the history for given file. With default setting of
398+
// FetchHistoryWhenNotInCache this should create corresponding file
399+
// in history cache.
400+
History retrievedHistory = cache.get(repoFile, repo, true);
401+
assertEquals(hasHistory, retrievedHistory == null ? false : true);
402+
403+
// The file in history cache should not exist since
404+
// FetchHistoryWhenNotInCache is set to false.
405+
File dataRoot = new File(repositories.getDataRoot(),
406+
"historycache" + File.separatorChar + reponame);
407+
File fileHistory = new File(dataRoot, filename + ".gz");
408+
assertEquals(historyFileExists, fileHistory.exists());
409+
}
410+
411+
/*
412+
* Functional test for the FetchHistoryWhenNotInCache configuration option.
413+
*/
414+
public void testNoHistoryFetch() throws Exception {
415+
// Do not create history cache for files which do not have it cached.
416+
RuntimeEnvironment.getInstance().setFetchHistoryWhenNotInCache(false);
417+
418+
// Make cache.get() predictable. Normally when the retrieval of
419+
// history of given file is faster than the limit, the history of this
420+
// file is not stored. For the sake of this test we want the history
421+
// to be always stored.
422+
RuntimeEnvironment.getInstance().setHistoryReaderTimeLimit(0);
423+
424+
// Pretend we are done with first phase of indexing.
425+
cache.setHistoryIndexDone();
426+
427+
// First try repo with ability to fetch history for directories.
428+
checkNoHistoryFetchRepo("mercurial", "main.c", false, false);
429+
// Second try repo which can fetch history of individual files only.
430+
checkNoHistoryFetchRepo("teamware", "header.h", true, true);
431+
}
386432
}

0 commit comments

Comments
 (0)