Skip to content

Commit 09dc233

Browse files
author
Vladimir Kotal
committed
add API endpoint for deleting history cache
fixes #2655
1 parent 5c1fc40 commit 09dc233

File tree

16 files changed

+46
-71
lines changed

16 files changed

+46
-71
lines changed

apiary.apib

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,14 @@ This will also mark the project as not indexed.
156156

157157
+ Response 204
158158

159+
## Project history cache management [/projects/{project}/historycache]
160+
161+
### delete history cache for a project [DELETE]
162+
163+
This will delete history cache for a project.
164+
165+
+ Response 204
166+
159167
## Project metadata management [/projects/{project}/indexed]
160168

161169
This entry point is used by the Indexer once it finishes indexing given project.

opengrok-indexer/src/main/java/org/opengrok/indexer/index/Indexer.java

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
import org.opengrok.indexer.configuration.LuceneLockName;
5656
import org.opengrok.indexer.configuration.Project;
5757
import org.opengrok.indexer.configuration.RuntimeEnvironment;
58-
import org.opengrok.indexer.history.HistoryException;
5958
import org.opengrok.indexer.history.HistoryGuru;
6059
import org.opengrok.indexer.history.Repository;
6160
import org.opengrok.indexer.history.RepositoryFactory;
@@ -114,7 +113,6 @@ public final class Indexer {
114113
private static final Set<String> repositories = new HashSet<>();
115114
private static final HashSet<String> allowedSymlinks = new HashSet<>();
116115
private static final Set<String> defaultProjects = new TreeSet<>();
117-
private static final ArrayList<String> zapCache = new ArrayList<>();
118116
private static RuntimeEnvironment env = null;
119117
private static String webappURI = null;
120118

@@ -319,9 +317,9 @@ public static void main(String[] argv) {
319317
getInstance().prepareIndexer(env, searchRepositories, addProjects,
320318
defaultProjects,
321319
listFiles, createDict, runIndex, subFiles, new ArrayList<>(repositories),
322-
zapCache, listRepos);
320+
listRepos);
323321

324-
if (listRepos || !zapCache.isEmpty()) {
322+
if (listRepos) {
325323
return;
326324
}
327325

@@ -498,12 +496,6 @@ public static String[] parseOptions(String[] argv) throws ParseException {
498496
}
499497
);
500498

501-
parser.on("--deleteHistory", "=/path/to/repository",
502-
"Delete the history cache for the given repository and exit.",
503-
"Use '*' to delete the cache for all repositories.").Do(repo -> {
504-
zapCache.add((String)repo);
505-
});
506-
507499
parser.on("--depth", "=number", Integer.class,
508500
"Scanning depth for repositories in directory structure relative to",
509501
"source root. Default is " + Configuration.defaultScanningDepth + ".").Do(depth -> {
@@ -899,10 +891,9 @@ public void prepareIndexer(RuntimeEnvironment env,
899891
boolean createDict,
900892
List<String> subFiles,
901893
List<String> repositories,
902-
List<String> zapCache,
903894
boolean listRepoPaths) throws IndexerException, IOException {
904895
prepareIndexer(env, searchRepositories, addProjects, defaultProjects, listFiles, createDict, true,
905-
subFiles, repositories, zapCache, listRepoPaths);
896+
subFiles, repositories, listRepoPaths);
906897
}
907898

908899
/**
@@ -924,7 +915,6 @@ public void prepareIndexer(RuntimeEnvironment env,
924915
* @param createHistoryCache create history cache flag
925916
* @param subFiles list of directories
926917
* @param repositories list of repositories
927-
* @param zapCache list of projects to remove history cache for
928918
* @param listRepoPaths print repository paths to standard output
929919
* @throws IndexerException indexer exception
930920
* @throws IOException I/O exception
@@ -939,7 +929,6 @@ public void prepareIndexer(RuntimeEnvironment env,
939929
boolean createHistoryCache,
940930
List<String> subFiles,
941931
List<String> repositories,
942-
List<String> zapCache,
943932
boolean listRepoPaths) throws IndexerException, IOException {
944933

945934
if (env.getDataRootPath() == null) {
@@ -950,12 +939,9 @@ public void prepareIndexer(RuntimeEnvironment env,
950939
throw new IndexerException("ERROR: please specify a SRC_ROOT with option -s !");
951940
}
952941

953-
if (zapCache.isEmpty() && !env.validateUniversalCtags()) {
942+
if (!env.validateUniversalCtags()) {
954943
throw new IndexerException("Didn't find Universal Ctags");
955944
}
956-
if (zapCache == null) {
957-
throw new IndexerException("Internal error, zapCache shouldn't be null");
958-
}
959945

960946
// Projects need to be created first since when adding repositories below,
961947
// some of the project properties might be needed for that.
@@ -993,14 +979,14 @@ public void prepareIndexer(RuntimeEnvironment env,
993979
}
994980
}
995981

996-
if (searchRepositories || listRepoPaths || !zapCache.isEmpty()) {
982+
if (searchRepositories || listRepoPaths) {
997983
LOGGER.log(Level.INFO, "Scanning for repositories...");
998984
Statistics stats = new Statistics();
999985
env.setRepositories(env.getSourceRootPath());
1000986
stats.report(LOGGER, String.format("Done scanning for repositories, found %d repositories",
1001987
env.getRepositories().size()));
1002988

1003-
if (listRepoPaths || !zapCache.isEmpty()) {
989+
if (listRepoPaths) {
1004990
List<RepositoryInfo> repos = env.getRepositories();
1005991
String prefix = env.getSourceRootPath();
1006992
if (listRepoPaths) {
@@ -1014,33 +1000,7 @@ public void prepareIndexer(RuntimeEnvironment env,
10141000
System.out.println(String.format("%s (%s)", dir.substring(prefix.length()), info.getType()));
10151001
}
10161002
}
1017-
if (!zapCache.isEmpty()) {
1018-
HashSet<String> toZap = new HashSet<>(zapCache.size() << 1);
1019-
boolean all = false;
1020-
for (String repo : zapCache) {
1021-
if ("*".equals(repo)) {
1022-
all = true;
1023-
break;
1024-
}
1025-
if (repo.startsWith(prefix)) {
1026-
repo = repo.substring(prefix.length());
1027-
}
1028-
toZap.add(repo);
1029-
}
1030-
if (all) {
1031-
toZap.clear();
1032-
for (RepositoryInfo info : env.getRepositories()) {
1033-
toZap.add(info.getDirectoryName()
1034-
.substring(prefix.length()));
1035-
}
1036-
}
1037-
try {
1038-
HistoryGuru.getInstance().removeCache(toZap);
1039-
} catch (HistoryException e) {
1040-
LOGGER.log(Level.WARNING, "Clearing history cache failed: {0}",
1041-
e.getLocalizedMessage());
1042-
}
1043-
}
1003+
10441004
return;
10451005
}
10461006
}

opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/executables/JarAnalyzerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public static void setUpClass() throws Exception {
8585
IndexChangedListener progress = new DefaultIndexChangedListener();
8686
Indexer.getInstance().prepareIndexer(env, true, true,
8787
new TreeSet<>(Collections.singletonList("/c")),
88-
false, false, null, null, new ArrayList<>(), false);
88+
false, false, null, null, false);
8989

9090
Indexer.getInstance().doIndexerExecution(true, null, progress);
9191

opengrok-indexer/src/test/java/org/opengrok/indexer/index/IndexDatabaseTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public static void setUpClass() throws Exception {
8888
Indexer indexer = Indexer.getInstance();
8989
indexer.prepareIndexer(
9090
env, true, true, new TreeSet<>(Arrays.asList(new String[]{"/c"})),
91-
false, false, null, null, new ArrayList<String>(), false);
91+
false, false, null, null, false);
9292
indexer.doIndexerExecution(true, null, null);
9393
}
9494

opengrok-indexer/src/test/java/org/opengrok/indexer/index/IndexVersionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private void testIndexVersion(boolean projectsEnabled, List<String> subFiles) th
9191
env.setHistoryEnabled(false);
9292
env.setProjectsEnabled(projectsEnabled);
9393
Indexer.getInstance().prepareIndexer(env, true, true, null,
94-
false, false, null, null, new ArrayList<>(), false);
94+
false, false, null, null, false);
9595
Indexer.getInstance().doIndexerExecution(true, null, null);
9696

9797
IndexVersion.check(subFiles);

opengrok-indexer/src/test/java/org/opengrok/indexer/index/IndexerRepoTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ private void testPerProjectHistory(boolean globalOn) throws IndexerException, IO
143143
false, // don't create dictionary
144144
null, // subFiles - not needed since we don't list files
145145
null, // repositories - not needed when not refreshing history
146-
new ArrayList<>(), // don't zap cache
147146
false); // don't list repos
148147

149148
File repoRoot = new File(env.getSourceRootFile(), "git");
@@ -209,7 +208,6 @@ public void testSymlinks() throws IndexerException, IOException {
209208
false, // don't create dictionary
210209
null, // subFiles - not needed since we don't list files
211210
null, // repositories - not needed when not refreshing history
212-
new ArrayList<>(), // don't zap cache
213211
false); // don't list repos
214212

215213
// Check the respository paths.

opengrok-indexer/src/test/java/org/opengrok/indexer/index/IndexerTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public void testIndexGeneration() throws Exception {
121121
env.setDataRoot(repository.getDataRoot());
122122
env.setHistoryEnabled(false);
123123
Indexer.getInstance().prepareIndexer(env, true, true, new TreeSet<>(Collections.singletonList("/c")),
124-
false, false, null, null, new ArrayList<>(), false);
124+
false, false, null, null, false);
125125
Indexer.getInstance().doIndexerExecution(true, null, null);
126126
}
127127

@@ -159,7 +159,6 @@ public void testRescanProjects() throws Exception {
159159
false, // don't create dictionary
160160
null, // subFiles - not needed since we don't list files
161161
null, // repositories - not needed when not refreshing history
162-
new ArrayList<>(), // don't zap cache
163162
false); // don't list repos
164163

165164
List<Project> newProjects = env.getProjectList();
@@ -487,7 +486,7 @@ public void testDefaultProjectsSingleProject() throws Exception {
487486
Indexer.getInstance().prepareIndexer(env, true, true, new TreeSet<>(Arrays.asList(new String[]{
488487
Paths.get("/c").toString()
489488
})),
490-
false, false, null, null, new ArrayList<>(), false);
489+
false, false, null, null,false);
491490
assertEquals(1, env.getDefaultProjects().size());
492491
assertEquals(new TreeSet<>(Arrays.asList(new String[]{"c"})),
493492
env.getDefaultProjects().stream().map((Project p) -> p.getName()).collect(Collectors.toSet()));
@@ -513,7 +512,7 @@ public void testDefaultProjectsNonExistent() throws Exception {
513512
Paths.get("/data").toString(),
514513
Paths.get("/no-project-x32ds1").toString()
515514
})),
516-
false, false, null, null, new ArrayList<>(), false);
515+
false, false, null, null, false);
517516
assertEquals(4, env.getDefaultProjects().size());
518517
assertEquals(new TreeSet<>(Arrays.asList(new String[]{"lisp", "pascal", "perl", "data"})),
519518
env.getDefaultProjects().stream().map((Project p) -> p.getName()).collect(Collectors.toSet()));
@@ -537,7 +536,7 @@ public void testDefaultProjectsAll() throws Exception {
537536
Paths.get("__all__").toString(),
538537
Paths.get("/no-project-x32ds1").toString()
539538
})),
540-
false, false, null, null, new ArrayList<>(), false);
539+
false, false, null, null, false);
541540
Set<String> projects = new TreeSet<>(Arrays.asList(new File(repository.getSourceRoot()).list()));
542541
assertEquals(projects.size(), env.getDefaultProjects().size());
543542
assertEquals(projects, env.getDefaultProjects().stream().map((Project p) -> p.getName()).collect(Collectors.toSet()));

opengrok-indexer/src/test/java/org/opengrok/indexer/search/SearchEngineTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public static void setUpClass() throws Exception {
7575
env.setHistoryEnabled(false);
7676
Indexer.getInstance().prepareIndexer(env, true, true,
7777
new TreeSet<>(Collections.singletonList("/c")),
78-
false, false, null, null, new ArrayList<>(), false);
78+
false, false, null, null, false);
7979
Indexer.getInstance().doIndexerExecution(true, null, null);
8080

8181

opengrok-indexer/src/test/java/org/opengrok/indexer/search/context/SearchAndContextFormatterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public static void setUpClass() throws Exception {
8989
env.setHistoryEnabled(false);
9090
Indexer.getInstance().prepareIndexer(env, true, true,
9191
new TreeSet<>(Collections.singletonList("/c")),
92-
false, false, null, null, new ArrayList<>(), false);
92+
false, false, null, null, false);
9393
Indexer.getInstance().doIndexerExecution(true, null, null);
9494

9595
configFile = File.createTempFile("configuration", ".xml");

opengrok-indexer/src/test/java/org/opengrok/indexer/search/context/SearchAndContextFormatterTest2.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public static void setUpClass() throws Exception {
128128
env.setHistoryEnabled(false);
129129
Indexer.getInstance().prepareIndexer(env, true, true,
130130
new TreeSet<>(Collections.singletonList("/c")),
131-
false, false, null, null, new ArrayList<>(), false);
131+
false, false, null, null, false);
132132

133133
Project proj1 = env.getProjects().get(SYMLINK1);
134134
assertNotNull("symlink1 project", proj1);

0 commit comments

Comments
 (0)